I am not much of a scripter and have gotten by with editing scripts found online with other info found in books, guides and online. This basically means that some things that will be obvious to you may be a little abstract for me hence the need for a little assistance.
I have a logon script that maps drives and printers.
I need to add a section from an old script that I made which maps personal drives based on the users user name to this logon script.
The problem is that I am not incorporating the code properly.
Below are two ways to map drives according to username, I could use some help in getting either (or something else) to work properly within the logon script:
1.
Dim objNetwork, strDriveLetter
strDriveLetter = "X:"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemoveNetworkDrive strDriveLetter
strDriveLetter = "X:"
strRemotePath = "\\Server\Share"
Set objNetwork = CreateObject("WScript.Network")
2.
strUsername = objNetwork.UserName
MapIt "X:","\\Server\Share\" & strUsername
Logon Script:
I have a logon script that maps drives and printers.
I need to add a section from an old script that I made which maps personal drives based on the users user name to this logon script.
The problem is that I am not incorporating the code properly.
Below are two ways to map drives according to username, I could use some help in getting either (or something else) to work properly within the logon script:
1.
Dim objNetwork, strDriveLetter
strDriveLetter = "X:"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemoveNetworkDrive strDriveLetter
strDriveLetter = "X:"
strRemotePath = "\\Server\Share"
Set objNetwork = CreateObject("WScript.Network")
2.
strUsername = objNetwork.UserName
MapIt "X:","\\Server\Share\" & strUsername
Logon Script:
Code:
On Error Resume Next
Dim objFSO,objFILE,objShell,objNetwork
set objFSO=CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("Wscript.Shell")
set objNetwork=CreateObject("Wscript.Network")
'-------------------------------
'Map Network drives for everyone
'-------------------------------
MapIt "Z:","\\Server\Share"
'-----------------------------------------------------------------
'Map Network drives based on Group Membership (currently disabled)
'-----------------------------------------------------------------
'If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Security Group Name") Then MapIt "X:","\\Server\Share"
'----------------
'Network Printers
'----------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
' Wscript.Echo objOperatingSystem.Caption & " " & objOperatingSystem.Version
oscaption = objOperatingSystem.Caption
Next
Set RegularExpressionObject = New RegExp
RegularExpressionObject.Global = True
RegularExpressionObject.IgnoreCase = True
RegularExpressionobject.Pattern = "Server"
Set Matches = RegularExpressionObject.Execute(oscaption)
For each Match in Matches
k=k+1
next
if k>0 then
'wscript.echo "This IS a server"
else
'wscript.echo "This IS NOT a server"
'--------------------------------------
'Map Printers based on Group Membership
'--------------------------------------
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Security Group Name") Then addPrinterConnection "\\Server\Printer"
end if
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+vbExclamation
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+vbExclamation
Err.Clear
End If
end sub
Sub AddPrinterPortConnection(strPort,strPrinterUNC)
On Error Resume Next
objNetwork.AddPrinterConnection strPort,strPrinterUNC
If Err.Number<>0 And blnShowError Then
strMsg="There was a problem mapping " & UCase(strPrinterUNC) & " to " &_
strPort & vbcrlf & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
VbCrLf & Err.Description
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
Err.Clear
End If
end sub