jazzyjeff Posted December 3, 2009 Share Posted December 3, 2009 Hey Everyone, I'm having some issues getting this script to work. The goal is to scan for any mapped drives, and if they exist then the script will delete them. Once the network drives are removed, the script continues and is supposed to map drives based on the Active Directory group membership. Here is what I have: expandcollapse popup#include <constants.au3> #include <adfunctions.au3> Global $strHostServer = $objRootDSE.Get ("willowhilldc") ; Retrieve the name of the connected DC DriveMapDel ("H:") DriveMapDel ("M:") DriveMapDel ("N:") DriveMapDel ("O:") DriveMapDel ("S:") DriveMapDel ("T:") DriveMapDel ("W:") DriveMapDel ("X:") DriveMapDel ("Y:") Func _ADIsMemberOf($group, $user) $ObjGroup = ObjGet("LDAP://" & $strHostServer & "/" & $group) $ismember = $objGroup.IsMember ("LDAP://" & $strHostServer & "/" & $user) $ObjGroup = 0 Return -$ismember If $group = "Domain Admins" Then DriveMapAdd ("M:", "\\app2\apps") DriveMapAdd ("Y:", "\\operserver2\techdownloads") ElseIf $group = "Office" Then DriveMapAdd ("M:", "\\whserver\apps") DriveMapAdd ("O:", "\\whserver\OfficeShare$") DriveMapAdd ("T:", "\\whserver\TeacherShare$") ElseIf $group = "Students" Then DriveMapAdd ("H:", "\\whserver\NetBaskets$") DriveMapAdd ("M:", "\\whserver\apps") DriveMapAdd ("N:", "\\app2\K5-Common") ElseIf $group = "Teachers" Then DriveMapAdd ("H:", "\\whserver\NetBaskets$") DriveMapAdd ("M:", "\\whserver\apps") DriveMapAdd ("N:", "\\app2\K5-Common") DriveMapAdd ("T:", "\\whserver\TeacherShare$") EndIf EndFunc I've used part of the code from a VB script that I had working, but for some users has now stopped... Not sure why, but I figure I'd try and get a script working through AutoIT. Any help is much appreciated. Jeff Registered 1 Link to comment Share on other sites More sharing options...
water Posted December 4, 2009 Share Posted December 4, 2009 And which part of your script doesn't work? The DriveDel, DriveAdd, Active Directory ...? Do you get errors or does the script just not what you want it to do? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
99ojo Posted December 4, 2009 Share Posted December 4, 2009 (edited) Hi, 1) You never call Function _ADIsMemberOf, so maybe some code is missing. 2) Also you have a return before the if conditions could be check. This could be a paste and copy error!?! Maybe you mean this? expandcollapse popup#include <constants.au3> #include <adfunctions.au3> Global $strHostServer = $objRootDSE.Get ("willowhilldc") ; Retrieve the name of the connected DC _deldrive () _addrive () Func _deldrive () DriveMapDel ("H:") DriveMapDel ("M:") DriveMapDel ("N:") DriveMapDel ("O:") DriveMapDel ("S:") DriveMapDel ("T:") DriveMapDel ("W:") DriveMapDel ("X:") DriveMapDel ("Y:") EndFunc Func _ADIsMemberOf($group, $user) $ObjGroup = ObjGet("LDAP://" & $strHostServer & "/" & $group) $ismember = $objGroup.IsMember ("LDAP://" & $strHostServer & "/" & $user) $ObjGroup = 0 Return $ismember EndFunc Func _addrive () If _ADIsMemberOf ("Domain Admins", @UserName) Then DriveMapAdd ("M:", "\\app2\apps") DriveMapAdd ("Y:", "\\operserver2\techdownloads") ElseIf _ADIsMemberOf ("Office", @UserName) Then DriveMapAdd ("M:", "\\whserver\apps") DriveMapAdd ("O:", "\\whserver\OfficeShare$") DriveMapAdd ("T:", "\\whserver\TeacherShare$") ElseIf _ADIsMemberOf ("Students", @UserName) Then DriveMapAdd ("H:", "\\whserver\NetBaskets$") DriveMapAdd ("M:", "\\whserver\apps") DriveMapAdd ("N:", "\\app2\K5-Common") ElseIf _ADIsMemberOf ("Teachers", @UserName) Then DriveMapAdd ("H:", "\\whserver\NetBaskets$") DriveMapAdd ("M:", "\\whserver\apps") DriveMapAdd ("N:", "\\app2\K5-Common") DriveMapAdd ("T:", "\\whserver\TeacherShare$") Else MsgBox (0, "Group Error", "No mebership found!") EndIf EndFunc ;-)) Stefan Edited December 4, 2009 by 99ojo Link to comment Share on other sites More sharing options...
brian873 Posted December 4, 2009 Share Posted December 4, 2009 Hey As good as autoit is, i would use a vb script run from a GPO to do this. here is code that will help you. its only a snippet so it will not work as is you will need to declare vairable s and so on. this will remove a single or all mapped drives add mapped drives add mapped drives based on group membership add mapp drive with alternative loin credentials. brian 'Disconnect any drive mappings as needed. 'WSHNetwork.RemoveNetworkDrive "F:", True, True 'Disconnect ALL mapped drives Set clDrives = WshNetwork.EnumNetworkDrives For i = 0 to clDrives.Count -1 Step 2 WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True Next 'Give the PC time to do the disconnect, wait 400 milliseconds wscript.sleep 600 'Map standard drives needed 'Note the first command uses the user name as a variable to map to a user share. WSHNetwork.MapNetworkDrive "H:", "\\server1a01\home\" & UserString,True WSHNetwork.MapNetworkDrive "x:", "\\server1\Shared Data\",True 'Check for group memberships and map appropriate drives For Each GroupObj In UserObj.Groups Select Case GroupObj.Name Case "data-osxserver" WSHNetwork.MapNetworkDrive "Y:", "\\192.168.0.210\SHARE",True Case "data-osxserver-Adfast1" Set objNetMap1 = WScript.CreateObject("WScript.Network") strLocalDrive = "X:" strRemoteShare = "\\192.168.10.252\SHARE2" strPer = "FALSE" strUsr = "USERNAME" strPas = "PASSWORD" objNetMap1.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas End Select Next Link to comment Share on other sites More sharing options...
jazzyjeff Posted December 10, 2009 Author Share Posted December 10, 2009 Sorry for the delay on this. I have been off sick. Here is the error that I get: >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\carrollje\My Documents\LoginScript TEST.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>11:45:28 Starting AutoIt3Wrapper v.2.0.0.3 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3 CPU:X64 OS:X86) >Running AU3Check (1.54.14.0) from:C:\Program Files\AutoIt3 C:\Documents and Settings\carrollje\My Documents\LoginScript TEST.au3(21,34) : ERROR: _ADIsMemberOf() already defined. Func _ADIsMemberOf($group, $user) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Documents and Settings\carrollje\My Documents\LoginScript TEST.au3 - 1 error(s), 0 warning(s) !>11:45:29 AU3Check ended.rc:2 +>11:45:40 AutoIt3Wrapper Finished >Exit code: 0 Time: 13.162 Link to comment Share on other sites More sharing options...
99ojo Posted December 11, 2009 Share Posted December 11, 2009 Hi, remove #include <adfunctions.au3> or remove Function _ADIsMemberOf from your script. ;-)) Stefan Link to comment Share on other sites More sharing options...
PeterAtkin Posted February 15, 2010 Share Posted February 15, 2010 (edited) I had the exact same issue so with a little help searching through the forum I managed to make this! it works a treat.. expandcollapse popupGlobal $network_drives[24] Global $number_of_network_drives _EnumerateDrives() ; needed to find drives in use and free drive avaiable for use. If $number_of_network_drives > 0 Then _delmappeddrive("*") EndIf Func _delmappeddrive($drived) Local $i = $number_of_network_drives If $drived = "*" Then Do DriveMapDel($network_drives[$i] & ":") Sleep(500) $i = $i - 1 Until $i = 0 Else DriveMapDel($drived) Switch @error Case 0 ;MsgBox(16, "Error", "An unknown error occured trying to delete local drive :" & $network_drives[$i] & ":") Case Else ;MsgBox(64, "Completed!", "Deleted " & $network_drives[$i]) EndSwitch EndIf EndFunc ;==>_delmappeddrive Func _EnumerateDrives() Local $x = 1 Local $y = 1 For $dl = 72 To 89 ; (H-Y) $network_drives[$x] = Chr($dl) $drive = Chr($dl) & ":\" $drive_letter = Chr($dl) DriveGetFileSystem($drive) If @error = 0 Then ;MsgBox(16, "Network Drive", "Drive in Use " & $drive & @CRLF & @CRLF & " Array Varible :" & $network_drives[$x]) $x = $x + 1 Else ;MsgBox(16,"New Drive " & $network_drives[$y], "Free Drive " & $drive_letter) $y = $y + 1 EndIf Next $number_of_network_drives = $x - 1 Return $number_of_network_drives ;MsgBox(16, "Drives", "Number of network drives in use are " & $number_of_network_drives) EndFunc ;==>_EnumerateDrives Its not pretty but it works if anyone can think of a way to tidy this up I would be greatful. Edited February 15, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now