• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

I'm trying to write a VBS script to map multiple network drives

I cannot figure out how to write a script to map multiple network drives to a group.

Example:
John Doe and Gail Smith are in the Sales Group in AD so when they log in I want these drives mapped

 "\\servername\SALES\Reports "W:", -
 "\\servername\SALES\Orders "V:", -
 "\\servername\SALES\Clients "L:", -
 "\\servername\SALES\Contracts "Y:", -

Now here's the catch when;

Caleb Doe and Kim Smith  log in, I want another set of drives mapped for them becasue they are in the TECHS Group in AD

 "\\servername\TECHS\Schedules "W:", -
 "\\servername\TECHS\Inventory "V:", -
 "\\servername\TECHS\Databases "L:", -
 "\\servername\TECHS\Documentation "Y:", -

and so on, the plus is that all these file shares are located on the same server.
Is this even possible to do.

0
Marco1680
Asked:
Marco1680
2 Solutions
 
weareitCommented:
Script I wrote a while ago:

' Company Login script...
' Author: Richard Fouts [We Are IT]
' Date:   17-02-2006

Option Explicit ' Force Explicit Declarations

      '//////////// DO NOT MODIFY BELOW ////////////
      ' Declare variables
      ' Object variables
      Dim objFSO ' File System Object
      Dim objNetwork ' Network Object
      Dim objShell ' Shell Object
      Dim objSysInfo ' System Information Object
      Dim objComputer ' Computer Object
      Dim objGroupList ' Group List Object
      Dim objUser ' User Object
      Dim objIExplore ' Internet Explorer Object

      ' String variables
      Dim strGroup ' Group String
      Dim strComputerDN ' Computer String
      Dim strUserDN ' User String

      ' Array Variables
      Dim mRegInf(100) ' Array used for the AddReg function
      Dim mMailInf(100) ' Array used for the SendMail function
      Dim mDrive(100) ' Array of Drive parameters
      Dim mPrn(100) ' Array of Printer parameters

      ' IE variables
      Dim IEWdth ' Width of IE Window
      Dim IEHght ' Height of IE Window
      Dim IEVisible ' IE Window visible or not
      Dim IETime ' Time IE Windows stays visible after login script completes
      Dim IETitle ' Title of IE Window
      Dim IECoName ' Company Name

      ' Option variables
      Dim optionDrv ' Drive options variable
      Dim optionPrn ' Printer options variable
      Dim optionReg ' Registry options variable
      Dim optionMail ' Mail options variable

      ' Miscellaneous variables
      Dim rmoveDrvs ' Remove drive mappings switch
      Dim rmovePrns ' Remove printer connections switch
      Dim Drives ' Drives mapped currently
      Dim Prns ' Printer currently connected
      Dim StartTime ' Script Activation Time
      Dim varIdx ' Index Counting
      Dim AREnabled ' Switch variable for AddReg Function
      Dim SMEnabled ' Switch variable for SendMail Function
      Dim objNoRun ' Computers that will not run the login script

      On Error Resume Next
      
      ' Set objShell to Wscript.Shell
      Set objShell = CreateObject("Wscript.Shell")

      ' Set nUser variable to WScript.Network
      'Set nUser = WScript.CreateObject("Wscript.Network")

      ' Set objFSO variable to Scripting File System
      Set objFSO = CreateObject("Scripting.FileSystemObject")

      ' Set objNetwork variable to WScript.Network
      Set objNetwork = CreateObject("WScript.Network")

      ' Set objSysInfo variable to ADSystemInfo
      Set objSysInfo = CreateObject("ADSystemInfo")

      ' Set strUserDN to Domain Username
      strUserDN = objSysInfo.userName

      ' Set strComputerDN to Domain Computername
      strComputerDN = objSysInfo.computerName

      ' Bind to the user and computer objects with the LDAP provider.
      Set objUser = GetObject("LDAP://" & strUserDN)
      Set objComputer = GetObject("LDAP://" & strComputerDN)
          '//////////// DO NOT MODIFY ABOVE ////////////


      '\\\\\\\\\\\\ MODIFY THIS SECTION BELOW \\\\\\\\\\\\
      ' Should the script remove current drive mappings (TRUE/FALSE)
      rmoveDrvs = TRUE

      ' Should the script remove current printer connections (TRUE/FALSE)
      rmovePrns = FALSE

      ' Default drive mappings

      ' mDrive(x) is the array location
      ' value after must one of the following masks:
      '
      '      D,,X:,\\servername\sharename,persistency
      '      U,Username,X:,\\servername\sharename,persistency
      '      C,Computername,X:,\\servername\sharename,persistency
      '      G,Groupname,X:,\\servername\sharename,persistency
      '
      ' Where:
      '
      '      D, U, C, G denote the mapping type:
      '            D = Default drive mapping
      '            U = User specific drive mapping
      '            C = Computer specific drive mapping
      '            G = Group specific drive mapping
      '      Username, Computer and Groupname are the name of the user or group
      '      X is the drive letter with a colon preceeding
      '      servername is the name of the server
      '      sharename is the name of the share or path
      '      persistency is the whether you want a persistent connection or not (TRUE/FALSE)
      '
      ' Note: There should be no spaces between the drive and the colon
      '      There should be no spaces between the colon and the comma
      '      There should be no spaces between the comma and the first backslash
      '      All other dos rules apply
      mDrive(0) = "D,,H:,\\server1\home\" & objNetwork.UserName & ",TRUE"
      mDrive(1) = "U,JDoe,Z:,\\server1\home\jdoe,TRUE"
      mDrive(2) = "C,COMP1,Z:,\\server1\home\comp1,TRUE"
      mDrive(3) = "G,Administrators,S:,\\server1\home\private,True"

      ' Default printer connections

      ' mPrn(x) is the array location
      ' value after must one of the following masks:
      '
      '      D,\\servername\printersharename
      '      U,Username,\\servername\printersharename
      '      C,Computername,\\servername\printersharename
      '      G,Groupname,\\servername\printersharename
      '
      ' Where:
      '
      '      D, U, C, G denote the connection type:
      '            D = Default printer connection
      '            U = User specific printer connection
      '            C = Computer specific printer connection
      '            G = Group specific printer connection
      '      Username and Groupname are the name of the user or group
      '      servername is the name of the server
      '      printersharename is the name of the printer
      '
      ' Note: There should be no spaces between the comma and the first backslash
      '      All other dos rules apply
      mPrn(0) = "D,,\\server1\HP4000,FALSE"
      mPrn(1) = "U,JDoe,\\server1\HP4250,FALSE"
      mPrn(2) = "C,COMP1,\\server1\COPIER,FALSE"
      mPrn(3) = "G,Domain Users,\\server1\COPIER,FALSE"

      ' Width (in pixels) of IE Window
      IEWdth = "450"

      ' Height (in pixels) of IE Window
      IEHght = "650"

      ' IE Window visible or not
      ' Valid values are True or False
      IEVisible = "True"

      ' Time (in seconds) IE Windows stays visible after login script completes
      IETime = "4000"

      ' Title of IE Window
      IETitle = "Chiropractic Healing Center Login Script"

      ' Company Name
      IECoName = "Chiropractic Healing Center"
      '\\\\\\\\\\\\ MODIFY THIS SECTION ABOVE \\\\\\\\\\\\


      '////////////   ADVANCED MODIFICATIONS  ////////////
      ' Do not run script on the following devices
      'objNoRun = "CN=OCCUDATA1,OU=Domain Controllers,DC=ad,DC=occudata"

      ' AddReg Enabled (TRUE/FALSE)
      AREnabled = FALSE

      ' SendMail Enabled (TRUE/FALSE)
      SMEnabled = FALSE

      ' What is the registry key path
      'mRegInf(0) = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon,LegalNoticeCaption,Registry Test"
      'mRegInf(1) = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon,LegalNoticeText,This is a test."
      ' Send mail to
      'mMailInf(0) = "jdoe@somedomain.com,jane@otherdomain.com,Test Subject,This is a test."
      '\\\\\\\\\\\\   ADVANCED MODIFICATIONS  \\\\\\\\\\\\

      '//////////// DO NOT MODIFY BELOW ////////////
      If (strComputerDN <> objNoRun) Then

            ' Set objIExplore varable to Internet Explorer Application
            Set objIExplore = WScript.CreateObject("InternetExplorer.Application","event_")

            ' Set Drives variable to enumeration of network drives
            Set Drives = objNetwork.EnumNetworkDrives

            ' Set Prns variable to enumeration of printers
            Set Prns = objNetwork.EnumPrinterConnections

            ' Open blank Internet Explorer window
            objIExplore.Navigate "about:Blank"

            ' Set window width to defined width in px
            objIExplore.Width = IEWdth

            ' Set window height to defined height in px
            objIExplore.Height = IEHght

            ' Set window with no toolbar
            objIExplore.Toolbar = False

            ' Set window with no status bar
            objIExplore.StatusBar = False

            ' Set window to visible
            objIExplore.Visible = True

            ' Set window to non-resizable
            objIExplore.Resizable = False

            ' Set window at 10px from top of screen
            objIExplore.Top = 10

            ' Set window at 10px from left edge of screen
            objIExplore.Left = 10

            ' Set window to visible
            objIExplore.Visible = IEVisible

            ' Set StartTime variable to Now (current time)
            StartTime = Now

            ' Set Get access to UserObj Active Directory object
            'Set UserObj = GetObject("WinNT://" & objNetwork.UserDomain & _
            '      "/" & objNetwork.UserName)

            ' Set UserName variable to User
            'UserName = "User"

            ' While objIExplore window is not ready, sleep for 250 seconds and loop
            Do While Not objIExplore.ReadyState = 4
                  WScript.Sleep 250
            Loop

            ' Set window title to company name
            objIExplore.Document.Title = IETitle

            ' Set window font to Verdana
            objIExplore.Document.Body.Style.FontFamily = "Verdana"

            ' Set fontsize to 10pt
            objIExplore.Document.Body.Style.FontSize = "10"

            ' Inside window, write the company name
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "<U Style='Color:DarkRed'>" & IECoName & "</U><BR>"

            ' Inside window, write the domain name
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "<U Style='Color:DarkBlue'>" & objNetwork.UserDomain & "</U><BR><BR>"

            ' Inside window, write the user name
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "Running for " & objNetwork.UserName & "<BR>@" & Now & "<BR>@"& _
                  objNetwork.UserDomain & "<BR><BR>"

            ' Inside window, write the strGroup information
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  strGroup

            ' Inside window, welcome the user to the domain
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "Welcome " & objNetwork.UserName & " to the " & objNetwork.UserDomain & _
                  " domain." & "<BR><BR>"

            ' Inside windows, write mapping drives
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "<I>Mapping drives:</I><BR>"

            ' Set ObjGroupDict to return from CreateMemberOfObject function
            'Set ObjGroupDict = CreateMemberOfObject(nUser.UserDomain, nUser.UserName)

            ' If statement to remove current drive and printer connections
            If rmoveDrvs = TRUE Then

                  ' For loop to work with      enumerated network drives
                  For varIdx = 0 To Drives.Count -1 Step 2

                        ' Remove network drive mapping
                        objNetwork.RemoveNetworkDrive Drives.Item(varIdx), true

                        ' Inside window, print results of removing drive mapping
                        objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                              "Removed " & Drives.Item(varIdx) & "<BR>"

                        ' Call DeleteDriveMapping function to remove persistent connection
                        DeleteDriveMapping(Drives.Item(varIdx))

                  ' Next iteration in for-loop
                  Next
            End If

            If rmovePrns = TRUE Then

                  ' For loop to work with      enumerated printer connections
                  For varIdx = 0 To Prns.Count -1 Step 2

                        ' Remove network drive mapping
                        objNetwork.RemovePrinterConnection Prns.Item(varIdx), TRUE, TRUE

                        ' Inside window, print results of removing drive mapping
                        objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                              "Removed " & Prns.Item(varIdx) & "<BR>"

                  ' Next iteration in for-loop
                  Next
            End If

            ' Inside window, print applying      exact mapping
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "Applying Exact mapping...<BR>"


            ' Beggining of drive mappings
            ' Inside window, print general drive mappings

            ' Inside window, print advanced drive mappings
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "<BR>Drive mappings for " & objNetwork.UserName & "...<BR>"

            ' Username driven mappings
            For varIdx = LBound(mDrive) To UBound(mDrive)

                  optionDrv = Split(mDrive(varIdx),",")

                  ' Switch statement
                  Select Case UCase(optionDrv(0))

                        ' Default Case
                        Case "D"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.UserName & " is " & optionDrv(1) & _
                              '      " then attempting to connect " & optionDrv(2) & " to " & _
                              '      optionDrv(3) & " The mapping will be persitant: " & optionDrv(4)

                              ' Inside window, print results of removing drive mapping
                              objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                    "Connecting " & optionDrv(2) & " to " & optionDrv(3) & "... "
                              If Not MapDrive(optionDrv(2), optionDrv(3), optionDrv(4)) Then

                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "NOT CONNECTED!!!<BR>"
                              Else

                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "CONNECTED!!!<BR>"
                              End If

                        ' User Case
                        Case "U"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.UserName & " is " & optionDrv(1) & _
                              '      " then attempting to connect " & optionDrv(2) & " to " & _
                              '      optionDrv(3) & " The mapping will be persitant: " & optionDrv(4)

                              If UCase(objNetwork.UserName) = UCase(optionDrv(1)) Then

                                    ' Inside window, print results of removing drive mapping
                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "Connecting " & optionDrv(2) & " to " & optionDrv(3) & "... "
                                    If Not MapDrive(optionDrv(2), optionDrv(3), optionDrv(4)) Then

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "NOT CONNECTED!!!<BR>"
                                    Else

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "CONNECTED!!!<BR>"
                                    End If
                              End If

                        ' User Case
                        Case "C"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.ComputerName & " is " & optionDrv(1) & _
                              '      " then attempting to connect " & optionDrv(2) & " to " & _
                              '      optionDrv(3) & " The mapping will be persitant: " & optionDrv(4)

                              If UCase(objNetwork.ComputerName) = UCase(optionDrv(1)) Then

                                    ' Inside window, print results of removing drive mapping
                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "Connecting " & optionDrv(2) & " to " & optionDrv(3) & "... "
                                    If Not MapDrive(optionDrv(2), optionDrv(3), optionDrv(4)) Then

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "NOT CONNECTED!!!<BR>"
                                    Else

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "CONNECTED!!!<BR>"
                                    End If
                              End If

                        ' Group Case
                        Case "G"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.UserName & " is a member of " & optionDrv(1) & _
                              '      " then attempting to connect " & optionDrv(2) & " to " & _
                              '      optionDrv(3) & " The mapping will be persitant: " & optionDrv(4)

                              If (IsMember(objUser, optionDrv(1)) = True) Then

                                    ' Inside window, print results of removing drive mapping
                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "Connecting " & optionDrv(2) & " to " & optionDrv(3) & "... "
                                    If Not MapDrive(optionDrv(2), optionDrv(3), optionDrv(4)) Then

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "NOT CONNECTED!!!<BR>"
                                    Else

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "CONNECTED!!!<BR>"
                                    End If
                              End If

                        ' Error Case or case mismatch
                        Case Else
                              'Wscript.echo "Error in array: " & vbCrLf & "      optionDrv(0) - " & optionDrv(0) & _
                              '      vbCrLf & "      optionDrv(1) - " & optionDrv(1) & vbCrLf & _
                              '      "      optionDrv(2) - " & optionDrv(2) & vbCrLf & "      optionDrv(3) - " & optionDrv(3) & _
                              '      vbCrlf & "      optionDrv(4) - " & optionDrv(4)

                  End Select

            Next

            ' End of drive mappings

            ' Beggining of printer connections
            ' Inside window, print general printer mappings

            ' Inside window, print advanced printer connections
            objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                  "<BR>Printer connections for " & objNetwork.UserName & "...<BR>"

            ' Username driven printer connections
            For varIdx = LBound(mPrn) To UBound(mPrn)

                  optionPrn = Split(mPrn(varIdx),",")

                  ' Switch statement
                  Select Case UCase(optionPrn(0))

                        ' Default Case
                        Case "D"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.UserName & " is " & optionPrn(1) & _
                              '      " then attempting to connect to printer " & optionPrn(2) & "using a persistant" & _
                              '      " connection: " & optionPrn(3)

                              ' Inside window, print results of removing drive mapping
                              objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                    "Connecting to " & optionPrn(2) & "... "
                              If Not ConnPrn(optionPrn(2), optionPrn(3)) Then

                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "NOT CONNECTED!!!<BR>"
                              Else

                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "CONNECTED!!!<BR>"
                              End If

                        ' User Case
                        Case "U"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.UserName & " is " & optionPrn(1) & _
                              '      " then attempting to connect to printer " & optionPrn(2) & "using a persistant" & _
                              '      " connection: " & optionPrn(3)

                              If UCase(objNetwork.UserName) = UCase(optionPrn(1)) Then

                                    ' Inside window, print results of removing drive mapping
                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "Connecting to " & optionPrn(2) & "... "
                                    If Not ConnPrn(optionPrn(2), optionPrn(3)) Then

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "NOT CONNECTED!!!<BR>"
                                    Else

                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "CONNECTED!!!<BR>"
                              End If
                        End If

                        ' Computer Case
                        Case "C"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.ComputerName & " is " & optionPrn(1) & _
                              '      " then attempting to connect to " & optionPrn(2) & "using a persistant" & _
                              '      " connection: " & optionPrn(3)

                              If UCase(objNetwork.ComputerName) = UCase(optionPrn(1)) Then

                                    ' Inside window, print results of removing drive mapping
                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "Connecting to " & optionPrn(2) & "... "
                                    If Not ConnPrn(optionPrn(2), optionPrn(3)) Then

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "NOT CONNECTED!!!<BR>"
                                    Else

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "CONNECTED!!!<BR>"
                                    End If
                              End If

                        ' Group Case
                        Case "G"
                              '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
                              'Wscript.echo "If " & objNetwork.UserName & " is a member of " & optionPrn(1) & _
                              '      " then attempting to connect to " & optionPrn(2) & "using a persistant" & _
                              '      " connection: " & optionPrn(3)

                              If (IsMember(objUser, optionPrn(1)) = True) Then

                                    ' Inside window, print results of removing drive mapping
                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "Connecting to " & optionPrn(2) & "... "
                                    If Not ConnPrn(optionPrn(2), optionPrn(3)) Then

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "NOT CONNECTED!!!<BR>"
                                    Else

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "CONNECTED!!!<BR>"
                                    End If
                              End If

                              If (IsMember(objComputer, optionPrn(1)) = True) Then

                                    ' Inside window, print results of removing drive mapping
                                    objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                          "Connecting to " & optionPrn(2) & "... "
                                    If Not ConnPrn(optionPrn(2), optionPrn(3)) Then

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "NOT CONNECTED!!!<BR>"
                                    Else

                                          objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                                                "CONNECTED!!!<BR>"
                                    End If
                              End If

                        ' Error Case or case mismatch
                        Case Else
                              'Wscript.echo "Error in array: " & vbCrLf & "      optionPrn(0) - " & optionPrn(0) & _
                              '      vbCrLf & "      optionPrn(1) - " & optionPrn(1) & vbCrLf & _
                              '      "      optionPrn(2) - " & optionPrn(2)

                  End Select

            Next

            ' End of printer connections

            ' Beggining of registry modifications
            ' First check if registry modifications are requested
            If AREnabled = TRUE Then

                  ' Inside window, print advanced printer connections
                  objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                        "<BR>Registry modifications for " & objNetwork.ComputerName & "..."

                  ' Computername driven registry modifications
                  For varIdx = LBound(mRegInf) To UBound(mRegInf)

                        optionReg = Split(mRegInf(varIdx),",")

                        If AddReg(optionReg(0), optionReg(1), optionReg(2)) Then
                        End If

                  Next

                  If SMEnabled = TRUE Then

                        For varIdx = LBound(mMailInf) To UBound(mMailInf)

                              optionMail = Split(mMailInf(varIdx),",")

                              If SendMail(optionMail(0), optionMail(1), optionMail(2), optionMail(3)) Then
                              End If
                        Next

                  End If

                  objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
                        "COMPLETED!!!<BR>"

            End If


            ' End of registry modifications

      End If


      ' Inside window, print end
      objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
            "End<BR><BR>"

      ' Inside window, print time difference from start to finish
      objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
            "Loginscript took: " & DateDiff("s",StartTime,Now) & " second(s)..."

      ' Inside window, close out of writing
      objIExplore.Document.Body.InnerHTML = objIExplore.Document.Body.InnerHTML & _
      "</BODY></HTML>"

      ' Sleep for 4000 seconds
      WScript.Sleep(IETime)

      ' Quite Internet Explorer
      objIExplore.Quit


Function MemberOf(ObjDict, strKey)
      ' Given a Dictionary object containing groups to which the user
      ' is a member of and a group name, then returns True if the group
      ' is in the Dictionary else return False.      
      '
      ' Inputs:
      ' strDict - Input, Name of a Dictionary object
      ' strKey - Input, Value being searched for in
      ' the Dictionary object
      ' Sample Usage:
      '
      ' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
      ' wscript.echo "Is a member of Domain Admins."
      ' End If
      '
      '
      MemberOf = CBool(ObjGroupDict.Exists(strKey))
End Function


Function CreateMemberOfObject(strDomain, strUserName)
      ' Given a domain name and username, returns a Dictionary
      ' object of groups to which the user is a member of.
      '
      ' Inputs:
      '
      ' strDomain - Input, NT Domain name
      ' strUserName - Input, NT username
      '
      Dim objUser, objGroup

      Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
      CreateMemberOfObject.CompareMode = vbTextCompare
      Set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName & ",user")
      For Each objGroup In objUser.Groups
            CreateMemberOfObject.Add objGroup.Name,      "-"
      Next
      Set objUser = Nothing
End Function

Function IsMember(objADObject, strGroup)
      ' Function to test for group membership.
      ' objGroupList is a dictionary object with global scope.

      ' Set IsMember to False
      IsMember = False

      ' Declare variables
      Dim Group

      ' If objGroupList is Empty
      If (IsEmpty(objGroupList) = True) Then

            ' Create a dictionary object and set it to objGroupList
            Set objGroupList = CreateObject("Scripting.Dictionary")

      End If

      ' If objGroupList does not have an object called SAMAccountName\
      If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then

            ' Call LoadGroups function with objADObject as both variables
            Call LoadGroups(objADObject, objADObject)

            ' Add SAMAccountName\ to the objGroupList dictionary
            objGroupList.Add objADObject.sAMAccountName & "\", True

      End If

      ' Set IsMember to True or False depending upon if the intended group
      ' exists in the dictionary
      IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\" _
            & strGroup)

End Function

Sub LoadGroups(objPriObject, objADSubObject)
      ' Recursive subroutine to populate dictionary object objGroupList.

      Dim colstrGroups, objGroup, j

      objGroupList.CompareMode = vbTextCompare

      colstrGroups = objADSubObject.memberOf

      If (IsEmpty(colstrGroups) = True) Then

            Exit Sub

      End If

      If (TypeName(colstrGroups) = "String") Then

            Set objGroup = GetObject("LDAP://" & colstrGroups)

            If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _
                  & objGroup.sAMAccountName) = False) Then

                  objGroupList.Add objPriObject.sAMAccountName & "\" _
                        & objGroup.sAMAccountName, True

                  Call LoadGroups(objPriObject, objGroup)

            End If

            Set objGroup = Nothing

            Exit Sub

      End If

      For j = 0 To UBound(colstrGroups)

            Set objGroup = GetObject("LDAP://" & colstrGroups(j))

            If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _
                  & objGroup.sAMAccountName) = False) Then

                  objGroupList.Add objPriObject.sAMAccountName & "\" _
                        & objGroup.sAMAccountName, True

                  Call LoadGroups(objPriObject, objGroup)

            End If

      Next

      Set objGroup = Nothing

End Sub

Function DeleteDriveMapping(sDriveLetter)
      ' This will remove the mapped drive sDriveLetter

      '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
      'Wscript.echo "Removing drive mapping " & sDriveLetter

      CreateObject("WScript.Shell").Run "net.exe use " _
            & sDriveLetter & " /delete", 0,      True
      WScript.Sleep 250
End Function

Function MapDrive(strDrive, strShare, strPersistent)
      ' Function to map network share to a drive letter.
      ' If the drive letter specified is already in use, the function
      ' attempts to remove the network connection.
      ' objFSO is the File System Object, with global scope.
      ' objNetwork is the Network object, with global scope.
      ' Returns True if drive mapped, False otherwise.

      Dim objDrive

      'On Error Resume Next

      '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
      'Wscript.echo "Mapping " & strDrive & " to " & strShare

            If objFSO.DriveExists(strDrive) Then
                  Set objDrive = objFSO.GetDrive(strDrive)
                  If Err.Number <> 0 Then
                        On Error GoTo 0
                        MapDrive = False
                        Exit Function
                  End If
                  If CBool(objDrive.DriveType = 3) Then
                        objNetwork.RemoveNetworkDrive strDrive, True, True
                  Else
                        MapDrive = False
                        Exit Function
                  End If
                  Set objDrive = Nothing
            End If
            objNetwork.MapNetworkDrive strDrive, strShare, strPersistent
            If Err.Number = 0 Then
                  MapDrive = True
            Else
                  Err.Clear
                  MapDrive = False
            End If
      On Error GoTo 0
End Function

Function ConnPrn(strPrnUNC, strDefPrn)
      ' Function to connect to a network printer share.
      ' If the printer specified is already connected, the function
      ' attempts to remove the network connection.
      ' objFSO is the File System Object, with global scope.
      ' objNetwork is the Network object, with global scope.
      ' objShell is the Shell Object, with global scope.
      ' Returns True if printer connected, False otherwise.

      Dim objWMISvc ' WMI Service Object
      Dim objPrn ' Printer Object
      Dim intIdx ' Index counter
      Dim colItems ' Collected Items
      Dim strComputer ' Local computer variable
      Dim strDefaultState ' Default share state
      Dim strCmd ' Default command string
      Dim cmdRetVal ' Return Value of the command

      strComputer ="."

      'On Error Resume Next

      ' Set the WMI Service object to get objects from the local computer
      Set objWMISvc = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

      ' Set the Collected Items to be installed printers
      Set colItems = objWMISvc.ExecQuery ("SELECT * FROM Win32_Printer")


      '////////// TEST VARIABLE PASS THROUGH \\\\\\\\\\
      'Wscript.echo "Connecting to " & strPrnUNC

            If Prns.Count = 0 Then
                  strCmd = "rundll32 printui.dll,PrintUIEntry /in /q /n " & strPrnUNC
                  'Wscript.echo "Prns.Count - Executing command: " & strCmd
                  cmdRetVal = objShell.Run(strCmd, 1, TRUE)
                  'Wscript.echo "Prns.Count - Return value is: " & cmdRetVal
            Else
                  For Each objPrn In colItems
                        'Wscript.Echo objPrn.DeviceID
                        If UCase(objPrn.DeviceID) = UCase(strPrnUNC) Then
                              ' Add new printer. Need the ,1,true to wait for shell to complete before continue
                              strCmd = "rundll32 printui.dll,PrintUIEntry /dn /q /n " & strPrnUNC
                              'Wscript.echo "objPrn - Executing command: " & strCmd
                              cmdRetVal = objShell.Run(strCmd, 1, TRUE)
                              'Wscript.echo "objPrn - Return value is: " & cmdRetVal
                              'Wscript.Echo "objPrn - First error Number is: " & Err.Number                  
                        End If

                  Next
                        
                  Set objPrn = Nothing
            End If

            strCmd = "rundll32 printui.dll,PrintUIEntry /in /q /n " & strPrnUNC
            'Wscript.echo "Out of loop - Executing command: " & strCmd
            cmdRetVal = objShell.Run(strCmd, 1, TRUE)
            'Wscript.echo "Out of loop - Return value is: " & cmdRetVal
            'Wscript.Echo "Out of loop - Second error Number is: " & Err.Number

            'Wscript.echo "This is a default printer?" & strDefPrn            

            If strDefPrn = "TRUE" Then
                  strCmd = "rundll32 printui.dll,PrintUIEntry /y /n " & strPrnUNC
                  'Wscript.echo "strDefPrn - Executing command: " & strCmd
                  cmdRetVal = objShell.Run(strCmd, 1, TRUE)
                  'Wscript.echo "strDefPrn - Return value is: " & cmdRetVal
            End If
            If cmdRetVal = 0 Then
                  ConnPrn = True
            Else
                  Err.Clear
                  ConnPrn = False
            End If
      On Error GoTo 0
End Function

Function AddReg(strKeyPath, strValueName, strValue)
      Const constHKEY_LOCAL_MACHINE = &H80000002
      Const constComputer = "."

      Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
            constComputer & "\root\default:StdRegProv")
      objReg.SetStringValue constHKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
End Function

Function SendMail(strTo, strFrom, strSubj, strMsg)
      Set objEmail = CreateObject("CDO.Message")
      objEmail.From = strFrom
      objEmail.To = strTo
      objEmail.Subject = strSubj
      objEmail.Textbody = strMsg
      objEmail.Send
End Function
      '//////////// DO NOT MODIFY ABOVE ////////////
0
 
netsmithcentralCommented:
'drvbygrp.vbs
Option Explicit

Dim objNetwork, objUser
Set objNetwork = CreateObject("Wscript.Network")
Set objUser = GetObject("WinNT://idlers.local/" & objNetwork.UserName & ", user")

Dim grp
For Each grp In objUser.Groups
      If grp.Name = "Sales" Then
            objNetwork.MapNetworkDrive "W:", "\\servername\SALES\Reports"
            objNetwork.MapNetworkDrive "V:", "\\servername\SALES\Orders"
            objNetwork.MapNetworkDrive "L:", "\\servername\SALES\Clients"
            objNetwork.MapNetworkDrive "Y:", "\\servername\SALES\Contracts"
      End If

      If grp.Name = "Techs" Then
            objNetwork.MapNetworkDrive "W:", "\\servername\TECHS\Schedules"
            objNetwork.MapNetworkDrive "V:", "\\servername\TECHS\Inventory"
            objNetwork.MapNetworkDrive "L:", "\\servername\TECHS\Databases"
            objNetwork.MapNetworkDrive "Y:", "\\servername\TECHS\Documentation"
      End If

      'If block for another group

      'If block for another group
Next

Set objNetwork = Nothing
Set objUser = Nothing
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now