KevinBugg
Technical User
- Feb 8, 2008
- 65
Hi,
We currently have 4 sites, all sepearted with different subnets. I am trying to create a single login script which defines which site the user is in by IP address then apply the relevant drive and printer mappings. At the moment it works well with pc's that have 1 network card. If a machine has 2 networks cards the script fails to run, even if the second card has no ip address. Can anyone see how I can tackle this problem? Here is my script.
On Error Resume Next
Dim objFSO,objFILE,objShell,objNetwork
strComputer = "."
set objFSO=CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("Wscript.Shell")
set objNetwork=CreateObject("Wscript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")
For Each objAdapter in colAdapters
For Each strAddress in objAdapter.IPAddress
arrOctets = Split(strAddress, ".")
If arrOctets(0) <> "" Then
strSubnet = arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
x = 1
Exit For
End If
If x = 1 Then
Exit For
End If
Next
Next
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DeviceID = 'Y:'")
If colItems.Count = 0 Then
Select Case strSubnet
'site 1
Case "192.168.0"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
'site 2
Case "192.168.1"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
'site 3
Case "192.168.2"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
'site 4
Case "192.168.3"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
End Select
End If
'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+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
Thanks
Kev
We currently have 4 sites, all sepearted with different subnets. I am trying to create a single login script which defines which site the user is in by IP address then apply the relevant drive and printer mappings. At the moment it works well with pc's that have 1 network card. If a machine has 2 networks cards the script fails to run, even if the second card has no ip address. Can anyone see how I can tackle this problem? Here is my script.
On Error Resume Next
Dim objFSO,objFILE,objShell,objNetwork
strComputer = "."
set objFSO=CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("Wscript.Shell")
set objNetwork=CreateObject("Wscript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")
For Each objAdapter in colAdapters
For Each strAddress in objAdapter.IPAddress
arrOctets = Split(strAddress, ".")
If arrOctets(0) <> "" Then
strSubnet = arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
x = 1
Exit For
End If
If x = 1 Then
Exit For
End If
Next
Next
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DeviceID = 'Y:'")
If colItems.Count = 0 Then
Select Case strSubnet
'site 1
Case "192.168.0"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
'site 2
Case "192.168.1"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
'site 3
Case "192.168.2"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
'site 4
Case "192.168.3"
MapIt "I:","\\server-01\Upload"
AddPrinterConnection "\\server-01\Photocopier - Ricoh"
End Select
End If
'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+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
Thanks
Kev