i need a Logon Script that maps drives, per Group.
Results 1 to 2 of 2

Thread: i need a Logon Script that maps drives, per Group.

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    11

    Question i need a Logon Script that maps drives, per Group.

    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

  2. #2
    Registered User hudsonsmith's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    2,276
    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\co pybat.bat"
    End If
    End If

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

    'If InGroup("Group Fast New York") Then
    'wshshell.run "\\xxxxxxxxxxx\newyork$\vol1\apps\fast\local\updat es\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
    Probability factor of one to one...we have normality, I repeat we have normality. Anything you still can't cope with is therefore your own problem.

Similar Threads

  1. How to make a logon script, that maps network drives ???
    By jtice in forum Windows Server 2003 & Windows Home Server
    Replies: 17
    Last Post: June 24th, 2004, 10:44 AM
  2. Can you assign a logon file to a group or OU, instead of just each user?
    By jtice in forum Windows Server 2003 & Windows Home Server
    Replies: 1
    Last Post: April 30th, 2004, 03:11 PM
  3. pdc and logon script weirdness
    By BrunDMC in forum Windows NT/2000
    Replies: 5
    Last Post: September 7th, 2001, 01:43 AM
  4. create logon script to set IP address in IE
    By death in forum Networking
    Replies: 3
    Last Post: April 23rd, 2001, 09:40 PM
  5. [RESOLVED] NT logon script
    By Note in forum Windows NT/2000
    Replies: 3
    Last Post: August 1st, 2000, 07:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •