Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Longon Script per MarkDMak Groups not connecting

Status
Not open for further replies.

jtutnc

Technical User
Jan 26, 2005
8
US
MarkDMak, I used your logon script and everything seems to be working fine with the exception of the group drives not wanting to connect. I setup a few new security groups and added the users but no luck. I'm not sure if the issue is with the code or the issue is with something I didn't get right in groups themselves. Please Help...
Code:
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor
' URL   : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'          Maps and disconnects drives and printers
'
'==========================================================================


ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName


'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\server /set /y"

'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:", True, True
WSHNetwork.RemoveNetworkDrive "G:", True, True
WSHNetwork.RemoveNetworkDrive "H:", True, True
WSHNetwork.RemoveNetworkDrive "P:", True, True
WSHNetwork.RemoveNetworkDrive "Q:", True, True
WSHNetwork.RemoveNetworkDrive "V:", True, True
WSHNetwork.RemoveNetworkDrive "U:", True, True
WSHNetwork.RemoveNetworkDrive "X:", True, True
WSHNetwork.RemoveNetworkDrive "Z:", 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 300 milliseconds
wscript.sleep 300

'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True
WSHNetwork.MapNetworkDrive "G:", "\\server\CENTEX",True
WSHNetwork.MapNetworkDrive "P:", "\\server\BPS",True
WSHNetwork.MapNetworkDrive "S:", "\\server\BPS-STANDARD",True
WSHNetwork.MapNetworkDrive "U:", "\\server\SCAN",True

'Now check for group memberships and map appropriate drives
'For Each GroupObj In UserObj.Groups
    Select Case GroupObj.Name
    'Check for group memberships and take needed action
    'In this example below, Administrators and Presidents are groups.
        Case "Administrators"
            WSHNetwork.MapNetworkDrive "F:", "\\server\REV 35 (F)",True
            WSHNetwork.MapNetworkDrive "X:", "\\server\ARCHIVED",True
        Case "Presidents"
            WSHNetwork.MapNetworkDrive "X:", "\\server\ARCHIVED",True
            WSHNetwork.MapNetworkDrive "Z:", "\\server\BPS - CONFIDENTIAL",True
        Case "QBusers"
            WSHNetwork.MapNetworkDrive "Q:", "\\server\QUICKBOOKS",True
        Case "Power Users"
            WSHNetwork.MapNetworkDrive "X:", "\\server\ARCHIVED",True
    End Select


'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
    If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
      WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next

'Remove a specific printer
'WSHNetwork.RemovePrinterConnection "\\ServerOld\HP5si",True,True
                                
'Install Printers
WSHNetwork.AddWindowsPrinterConnection "\\server\Canon iR2270/iR2870 PS3"
WSHNetwork.AddWindowsPrinterConnection "\\server\BPS_102"

'Add On Code goes below this line
'=====================================

'Adding the Notepad Application to the SendTo Menu
strSendToFolder = WSHShell.SpecialFolders("SendTo")
strPathToNotepad = WinDir & "windows\system32\Notepad.exe"
Set objShortcut = WSHShell.CreateShortcut(strSendToFolder & _
 "\Notepad.lnk")
objShortcut.TargetPath = strPathToNotepad
objShortcut.Save



'=====================================
'Add On Code goes above this line

'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
  

'Quit the Script
wscript.quit
 
You have a few things wrong there. comments in blue, problems in red

Code:
'Now check for group memberships and map appropriate drives
[blue]You have remarked the code to actually check the groups[/blue]
[red]'[/red]For Each GroupObj In UserObj.Groups
    Select Case GroupObj.Name
    'Check for group memberships and take needed action
    'In this example below, Administrators and Presidents are groups.
[blue] You need to be careful with mixed case as it IS case sensitive.  I suggest using all lower case and change the above [b]Select Case GroupObj.Name[/b] to [b]Select Case Lcase(GroupObj.Name)[/b]

        Case [red]"Administrators"[/red]
            WSHNetwork.MapNetworkDrive "F:", "\\server\REV 35 (F)",True
            WSHNetwork.MapNetworkDrive "X:", "\\server\ARCHIVED",True
        Case "Presidents"
            WSHNetwork.MapNetworkDrive "X:", "\\server\ARCHIVED",True
            WSHNetwork.MapNetworkDrive "Z:", "\\server\BPS - CONFIDENTIAL",True
        Case "QBusers"
            WSHNetwork.MapNetworkDrive "Q:", "\\server\QUICKBOOKS",True
        Case "Power Users"
            WSHNetwork.MapNetworkDrive "X:", "\\server\ARCHIVED",True
    End Select
[blue]You are missing the Next statement for the Group object For/Next[/blue]
[red]Next[/red]

I hope you find this post helpful.

Regards,

Mark
 
Thanks, easy fix. Not sure why I commented that line.
 
Looks like I missed my ending Blue tag on this line and want to be sure you saw the comment

[blue] You need to be careful with mixed case as it IS case sensitive. I suggest using all lower case and change the above Select Case GroupObj.Name to Select Case Lcase(GroupObj.Name)[/blue]


I hope you find this post helpful.

Regards,

Mark
 
Why is "Administrators" in red? Are you just making it "administrators"?
 
yes, see my previous post about case sensitivity.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top