Click to See Complete Forum and Search --> : i need a Logon Script that maps drives, per Group.


jtice
May 6th, 2004, 02:08 PM
I have been working on a logon script for the last week, and it is getting very frustrating.
I have tried a few different bat, and vbs files. None are working at all.

I need a script, that will map certain drives, depending on the users group.

Here is a vbs script I found, but it is not working, its not calling up the other scripts.
BTW, how can I display the UserObj variable?
I cant even error check it, to see if that variable is getting set to the group, cuz I cant figure out a way to display its value.

Also, I see it has WinNT as part of the directory, but I am running Windows Server 2003. Should I change it to something else? If so, what?

The below script is supposed to call up other scripts, that are named the same as the group.

' Let's declare some variables that we'll need....
Dim Domain, UserObj, Group, GroupObj, UserName, nUser,wsh, sArray
Dim test

'Now give them their initial values.....
Set wsh = WScript.CreateObject("Wscript.Shell")
Set nUser = WScript.CreateObject("Wscript.Network")
Domain = nUser.UserDomain
UserName = nUser.UserName

'Now get the current user name and domain from ADS....
Set UserObj = GetObject("WinNT://" & Domain & "/" & UserName)


'Go through each group, executing the .vbs file for each one......
On Error Resume Next
For Each GroupObj in UserObj.Groups
'The next two lines strip the spaces from the Group in question
' because the script name cannot have spaces in it
sArray= Split(GroupObj.name)
sJoin = Join(sArray,"")
'This calls the script named from the group membership....
wsh.Run ("\\KITE\munnr$\Login\" & sJoin &".vbs"), bWaitOnReturn
Next

Wscript.quit

hudsonsmith
May 6th, 2004, 04:07 PM
Here's what ours looks like (we have similar ones for each location):

Dim WSHNetwork
Dim WshShell
Dim UserObj
Dim objTimer
Dim strUserID
Dim strDomain


Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FileSysObj = CreateObject("Scripting.FileSystemObject")


strDomain = "XXXXXXX"

Do
strUserID = WSHNetwork.UserName

Loop Until strUserID <> ""

Set UserObj = GetObject("WinNT://" & strDomain & "/" & strUserID)

'***Initialise Groups
Dim UserGroups
Dim GroupObj
UserGroups=""
For Each GroupObj In UserObj.Groups
UserGroups=UserGroups & "[" & GroupObj.Name & "]"
Next


'***Workstation Copies***

wshshell.run "iexplore.exe home.xxxxxxxxxxxxxx.com"

If InGroup("Group Fast New York") Then
If not FileSysObj.FileExists("C:\printer.bat") Then
wshshell.run "\\xxxxxxxxxxx\newyork$\vol1\apps\fast\printers\cop ybat.bat"
End If
End If

If InGroup("Group Fast New York") Then
wshshell.run "\\xxxxxxxxxxx\newyork$\vol1\apps\fast\local\update s\updates.bat"
wshshell.run "c:\printer.bat"
End If

'If InGroup("Group Fast New York") Then
'wshshell.run "\\xxxxxxxxxxx\newyork$\vol1\apps\fast\local\update s\updates.bat"
'End If

wshshell.run "net time /domain /set /y"

wshshell.run "\\xxxxxxx\netlogon\test\uatcs.bat"


'-------------------------------------------------------------------------
' General Logon Processes - (Specifics Executed By Procedures & Functions)
'-------------------------------------------------------------------------

KillDrive("F:")
MapDrive "F:","\\xxxxxxx\newyork$\vol1\users\" & strUserID

If InGroup("Group New York") Then
KillDrive("G:")
MapDrive "G:","\\xxxxxxx\newyork$\vol1\groups\New York"
End If

...many more drives like this deleted

KillDrive("X:")
MapDrive "X:","\\xxxxxxx\newyork$\vol1\apps"

KillDrive("Z:")
MapDrive "Z:","\\xxxxxxxxxxx\PUBLIC$"

on error resume next

Set objTimer = CreateObject("TimeObject.Time")
objTimer.Timer (5) 'Wait 5 seconds


'-------------------------------------------------------------------------
'-------------------------------Sub-Procedures---------------------------

'-------------------------------------------------------------------------
' Sub: Disconnects Network Drives
'-------------------------------------------------------------------------
Sub KillDrive(strdrive)

On Error Resume Next
If FileSysObj.DriveExists(strDrive) = true then
WshNetwork.RemoveNetworkDrive strDrive
End If

End Sub
'-------------------------------------------------------------------------
' Sub: Drive Mapping Routine
'-------------------------------------------------------------------------
Sub MapDrive( strDrive, strShare )

Dim Path
If InStr(strShare,"\") then
Path=strShare
Else
Path="\\" & Authsvr & "\" & strShare
End If

' Map drive
On Error Resume Next
WSHNetwork.MapNetworkDrive strDrive, Path

' End Sub result
If Err.Number <> 0 Then WriteErr( strUserID & ": Mapping " & strDrive & " to " & Path & " " & Err.Description & " " & Now() )
End Sub
'-------------------------------------------------------------------------
' Function: InGroup
'-------------------------------------------------------------------------
Function InGroup(strGroup)
InGroup=False
If InStr(UserGroups,"[" & strGroup & "]") Then
InGroup=True
End If
End Function