Jump to content

Semi-Automatic Drive-Mapping in Active Directory- Please help!


Recommended Posts

Hi,

first of all I have to excuse me: I am completly new in the world of scripting (OK, a few powershell and diskpart scripts which I designed work), some questions may sound stupid.

What I need is not really a simple hint for a special problem in my script, a template covers the description better.

I understand if someone tells me to learn first or use the search function, but I have a time-critical problem while doing this.

So here is what I want to do:

My company has a complete Active Directory with different shares, drives and so on. Mapping network drives in our forest works fine with login scripts.

The problem is: There is another big company which has no Active Directory Trust with us because they use 13 year old Microsoft infrastructure, but we have a site-to-site-vpn-tunnel up an running for sharing certain fileservers. :  

In the past, each user who has to work with the foreign drives had to map the drive manually. That means: I am running from one workstation to the next if something changes.

What I want to do is to generate a semi-automatic, interactive logon script.

This is what I try to reach:

The user logs in and the script maps the drives of our forest with actual user data silently.

Then the user is getting a first command prompt: "Do you want to map external shares"

If "No" is selected, the script exits.

If "Yes" is selected, the user should get a prompt to enter the credentials of the external company drives (all use the same).

These credentials should be saved to do the following steps:

After entering the credentials, a second prompt should ask for the first file server (multiple locations of the external company) to connect.

If yes is selected, a net use command should use the credentials entered before to map the drive of this first server. After doing that, the user gets a prompt for the second external server.

If "no" is selected at any point, the script should not exit, but skip the server which  was questioned for. So, for instance, the first and second remote server could be skipped, but the third one is the one which the user wants to connect to if he selected "Yes".

 

I know that this may sound strange.

But I hope there is anybody out there to help me with this strange goal.

I would be happy to get a solution for this.

Thanks in advance,

Sven

Link to comment
Share on other sites

hello field2network, welcome to AutoIt and to the forum!

you have too much prompts in your flow. do you insist your users hate you?  ;)

this is how it's done in a single GUI:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <Array.au3>

; init application data
Dim $aServers[4][2] ; columns: server name | LVitem ControlID
$aServers[0][0]=3
$aServers[1][0]='server1\share'
$aServers[2][0]='server2\share'
$aServers[3][0]='server3\share'
Global Const $sUserName='username'
Global Const $sPassword='password'

; init GUI-related data
Global Const $GUI_W=400
Global Const $GUI_H=200
Global $msg=0

; buid GUI
GUICreate("Connect to External Servers",$GUI_W,$GUI_H)
GUISetBkColor(0x444444)
$gServers=GUICtrlCreateListView('Servers                        ',10,10,$GUI_W-20,$GUI_H-60,Default,$LVS_EX_CHECKBOXES)
For $i=1 To $aServers[0][0]
    $aServers[$i][1]=GUICtrlCreateListViewItem($aServers[$i][0],$gServers)
Next
$gButtonOK=GUICtrlCreateButton('Connect',110,$GUI_H-40,$GUI_W-220,30)
GUISetState()

; main function
Do
    $msg=GUIGetMsg()
    If $msg=$gButtonOK Then
        For $i=1 To $aServers[0][0]
            If BitAND(GUICtrlRead($aServers[$i][1],1),$GUI_CHECKED) Then DriveMapAdd('',$aServers[$i][0],Default,$sUserName,$sPassword)
        Next
        Exit
    EndIf
Until $msg=$GUI_EVENT_CLOSE

note that the credentials are hard-coded, because as you say

 get a prompt to enter the credentials of the external company drives (all use the same).

 

so obviously everyone knows the credentials, and they doen't change, so it's a bit dumb to ask the user for the credentials.

of course you can add input fields to the credentials if you want.

also, there is no error checking or notification of success of the mapping. i leave it to you, but feel free to ask if you bump into a wall.

also, you do not map to a server, you map to a share. that's why the list includes the share.

also, the drive letters are assigned automatically. you can change that too of course.

you probably want to modify that in many ways, feel free. best of luck!

 

when done, compile to exe, deploy to workstations, and set to execute at logon in any method convenient. in this case i'd use a shortcut to the StartUp folder, because then the user is free to launch it any time.

P.S. and most of all - usually you will not find ready-made scripts for specific purposes, and you will need to write your own. take this opportunity to learn from this example!

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Hello Universalist,

many many thanks for your help. I think this will save my whole week.  :thumbsup:

I promise you that I will learn each single Auto-IT-Script starting from this day on. ;-)

In the meantime, I have a annotation:

The part of my question which you quoted is a little bit confusing (sorry, I should have wrote this better):

The credentials are NOT the same for every user.

Every user has his own credentials for the external systems, I meant that these credentials are the same for all external servers (EXTERNALDOMAIN%User%), but depending on the employee.

So I need a prompt.

Finally, it would be great if you could get me a tip how to assign fixed drive letters to these shares within the script.

 

Many thanks in advance!!!

Link to comment
Share on other sites

for drive letters, extend the array to add another column to hold the required drive letter, and also display it in the GUI.

for user name and password, add two input boxes.

like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <EditConstants.au3>

; init application data
Dim $aServers[4][3] ; columns: server name | LVitem ControlID | drive letter
$aServers[0][0]=3
$aServers[1][0]='server1\share'
$aServers[2][0]='server2\share'
$aServers[3][0]='server3\share'
$aServers[1][2]='X:'
$aServers[2][2]='Y:'
$aServers[3][2]='Z:'

Global $sUserName=''
Global $sPassword=''

; init GUI-related data
Global Const $GUI_W=400
Global Const $GUI_H=300
Global $msg=0

; buid GUI
GUICreate("Connect to External Servers",$GUI_W,$GUI_H)
GUISetBkColor(0x444444)
$gServers=GUICtrlCreateListView('Drive|Server',10,10,$GUI_W-20,$GUI_H-120,Default,$LVS_EX_CHECKBOXES)
GUICtrlCreateLabel('User Name:',50,$GUI_H-100+2)
GUICtrlSetColor(-1,0xFFFFFF)
GUICtrlCreateLabel('Password:',50,$GUI_H-70-2)
GUICtrlSetColor(-1,0xFFFFFF)
$gUserName=GUICtrlCreateInput('',110,$GUI_H-103+2,$GUI_W-220,20)
$gPassword=GUICtrlCreateInput('',110,$GUI_H-73-2,$GUI_W-220,20,BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
For $i=1 To $aServers[0][0]
    $aServers[$i][1]=GUICtrlCreateListViewItem($aServers[$i][2]&'|'&$aServers[$i][0],$gServers)
Next
$gButtonOK=GUICtrlCreateButton('Connect',110,$GUI_H-40,$GUI_W-220,30)
GUICtrlSetState($gButtonOK,$GUI_DEFBUTTON)
GUISetState()

; main function
Do
    $msg=GUIGetMsg()
    If $msg=$gButtonOK Then
        $sUserName='EXTERNALDOMAIN\'&GUICtrlRead($gUserName)
        $sPassword=GUICtrlRead($gPassword)
        For $i=1 To $aServers[0][0]
            If BitAND(GUICtrlRead($aServers[$i][1],1),$GUI_CHECKED) Then DriveMapAdd($aServers[$i][2],$aServers[$i][0],Default,$sUserName,$sPassword)
        Next
        Exit
    EndIf
Until $msg=$GUI_EVENT_CLOSE

note: i also set the "Connect" button to be the "default button", so if you hit "Enter" it is interpreted as a click on the button.

so the user needs to check the shares from the list, then click (or Tab to) the user name field, Tab to password, and Enter. very convenient, not too much mouse moves. and no prompt!  ;)

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...