C
Coso
Guest
I am trying to write a VBS script that will map drives and printers depending on what location the employee is at. I have a mixed win 7 and xp environment with 08 servers. I need to use IP address instead of site name because there are users that will take their laptops between locations. So far i have the following but i can not get it to run via GPO:
The logon script was added here in GPO "User Configuration", "Windows Settings", "Scripts (Logon/Logoff)", "Logon"
Any help would be great, this is getting stressful because this is one of the first scripts i need to run via vbs rather than just batch and i never really learned vbs :crosseyed: Thanks!!!!!
Code:
Dim strComputer,strIPAddress,strIPRange
Dim objNetwork
Dim IPConfigSet, IPConfig
Dim arrIPAddress
strComputer = "."
Set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" _
& strComputer & "/root/cimv2").ExecQuery("select IPAddress from " _
& "Win32_NetworkAdapterConfiguration where IPEnabled=True")
Set objNetwork = WScript.CreateObject("WScript.Network")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
arrIPAddress = split(IPConfig.IPAddress(0) ,".")
strIPRange = arrIPAddress(0) & "." & arrIPAddress(1) & "." & arrIPAddress(2) & ".0"
select case strIPRange
case "172.31.2.*"
WshNetwork.RemoveNetworkDrive "G:"
WshNetwork.MapNetworkDrive "G:", "[URL="file://\\Server\Folder"]\\Server\Folder[/URL]"
objNetwork.AddWindowsPrinterConnection "[URL="file://\\Server\Printer"(UPSTAIRS"]\\Server\Printer"(UPSTAIRS[/URL])"
case "172.31.1.*"
WshNetwork.RemoveNetworkDrive "G:"
WshNetwork.MapNetworkDrive "G:", "[URL="file://\\Server\Folder"]\\Server\Folder[/URL]"
objNetwork.AddWindowsPrinterConnection "[URL="file://\\Server\Printer"]\\Server\Printer[/URL]"
end select
end if
next
set objNetwork = nothing
set IPConfigSet = nothing
The logon script was added here in GPO "User Configuration", "Windows Settings", "Scripts (Logon/Logoff)", "Logon"
Any help would be great, this is getting stressful because this is one of the first scripts i need to run via vbs rather than just batch and i never really learned vbs :crosseyed: Thanks!!!!!
Last edited by a moderator: