Announcement

Collapse
No announcement yet.

VBS logon cscript issue

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS logon cscript issue

    Having trouble getting this script to map network drives. It is run from User\Profile\Logon Script in active Directory. Script location is Sysvol\domain.local\scripts. The script maps all printers, but not one drive ( I have omited most of the printers and drives for clarity). If the user runs this script after they have logged, everything works great. This is running on win 2003 DC and xp clients PC's. Any ideas would be greatly appreciated as I am out of ideas.

    Below is a sample of the script



    Dim objFSO,objFILE,objShell,objNetwork
    set objFSO=CreateObject("Scripting.FileSystemObject")
    set objShell=CreateObject("Wscript.Shell")
    set objNetwork=CreateObject("Wscript.Network")

    'Map network drives
    If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserN ame,"DOMAIN - All Corporate Users") Then MapIt "H:","\\FS1\corp"

    'Map printers
    If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserN ame,"Domain Users") Then AddPrinterConnection "\\FS1\Xerox"

    'End of main script
    '//////////////////////////////////////////////////

    Function IsAMemberOf(strDomain,strUser,strGroup)
    On Error Resume Next
    Set objUser=GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
    Set objGrp=GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
    If objGrp.IsMember(objUser.ADsPath) Then
    IsAMemberOf=True
    Else
    IsAMemberOf=False
    End If
    End Function
    Sub MapIt(strDrive,strMap)
    On Error Resume Next
    If objFSO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive)
    objNetwork.MapNetworkDrive strDrive,strMap
    If Err.Number<>0 And blnShowError Then
    strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_
    strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
    VbCrLf & Err.Description
    objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamatio n
    Err.Clear
    End If
    End Sub
    Sub AddPrinterConnection(strPrinterUNC)
    On Error Resume Next
    objNetwork.AddWindowsPrinterConnection strPrinterUNC
    If Err.Number<>0 And blnShowError Then
    strMsg="There was a problem mapping " & UCase(strPrinterUNC) & ". " &_
    vbcrlf & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
    VbCrLf & Err.Description

    objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamatio n
    Err.Clear
    End If
    end sub

  • #2
    Re: VBS logon cscript issue

    Here's another script you could use to map network drives based on group membership.

    Just stuff the vbs and csv in the netlogon folder, apply the script via Group Policy, and modify the csv file with the
    GroupName, Drive:, \\server\share
    you require and the script reads the csv and maps the drives accordingly.
    Daniel Frei
    -Windows Operations Server Administrator
    -Exchange Guru
    -Cisco Fanatic
    -SharePoint Hippie
    -Volkswagen Enthusiast

    www.lazynetworkadmin.com

    Comment

    Working...
    X