Reply
Old November 17th, 2011 Top | #1
 
Coso's Avatar
OSNN Junior Addict
Joined: November 2011
Posts: 2
Reputation: 0
Power: 0

Default VBS Script

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:

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:", "\\Server\Folder"
                    objNetwork.AddWindowsPrinterConnection "\\Server\Printer"(UPSTAIRS)"
               case "172.31.1.*"
   WshNetwork.RemoveNetworkDrive "G:"
   WshNetwork.MapNetworkDrive "G:", "\\Server\Folder"
                    objNetwork.AddWindowsPrinterConnection "\\Server\Printer"
          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 Thanks!!!!!
Coso is offline   Reply With Quote
Old November 23rd, 2011 Top | #2

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,028
Reputation: 2947
Power: 168

Default Re: VBS Script

Assuming it's an Active Directory environment and you've setup your sites correctly, it shouldn't matter if they have laptops as wherever the computer is, it will pick up the correct AD site and you should be able to map drives based on site.

That all being said, does the script work if you run it manually?
The code you wrote has you setting the strIPRange variable to xxx.xxx.xxx.0 but your case statement has you searching on xxx.xxx.xxx.* - it will never find a match that way.

Code:
strIPRange = arrIPAddress(0) & "." & arrIPAddress(1) & "." & arrIPAddress(2) & ".0" 

select case strIPRange
  case "172.31.2.*"
  case "172.31.1.*"
end select
fitz is offline   Reply With Quote
Old November 28th, 2011 Top | #3
 
Coso's Avatar
OSNN Junior Addict
Joined: November 2011
Posts: 2
Reputation: 0
Power: 0

Default Re: VBS Script

thanks, i got it working now
Coso is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible Script? omg its nlm Web Design & Coding 10 February 9th, 2004 8:26am
log in script gerrieb Windows Desktop Systems 1 October 3rd, 2003 7:54am
Very new to PHP Script Alex_is_Axel Web Design & Coding 17 May 22nd, 2003 10:29pm
tv script slmatix Green Room 13 May 18th, 2003 5:42am
XP and script ericha Windows Desktop Systems 6 April 16th, 2002 5:41pm