Link to home
Start Free TrialLog in
Avatar of Ozwazza
OzwazzaFlag for Australia

asked on

WIndows Scripts for network resources

Hi, I have a single active directory network encompassing 9 sites all with different IP ranges from 192.168.100.x to 192.168.180.x.  At each location there are printers and shared folders, several staff roam to the different offices frequently.  I would like to get a script that will detect where it is based on the IP range and then map the appropriate printers and shared folders accordingly to standardized drive letters.
Look forward to hearing from you gurus soon.
Cheers
Warren
Avatar of Brendan M
Brendan M
Flag of Australia image

http://www.eggheadcafe.com/forumarchives/scriptingVisualBasicscript/Nov2005/post24366005.asp
(website offline as of posting)
suggests to check the default gateway and then base the mapping from that
code is provided
Function DefaultGateway  
  DefaultGateway = Empty  
  Dim oDG, oDGs, WMI  
  Set WMI = GetObject("winmgmts:\\.\root\cimv2")  
  Set oDGs = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")  
  For Each oDG in oDGs  
    If Not IsNull(oDG.DefaultIPGateway) Then  
      If Not oDG.defaultIPGateway(0) = "0.0.0.0" Then  
        DefaultGateway = oDG.DefaultIPGateway(0)  
        Exit For  
      End If    
    End If  
  Next  
End Function  

Select Case DefaultGateway  
  Case "10.1.1.254"  
    'Do something  
  Case "10.2.1.254"  
    'Do something  
End Select

Open in new window

Avatar of Ozwazza

ASKER

Can you add a bit more to the 'Do something, I would like to map printers and drives

Regards
Warren
ASKER CERTIFIED SOLUTION
Avatar of Brendan M
Brendan M
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ozwazza

ASKER

Had to rework the script to include full domain name in the printer setup, also included the RemoveNetworkDrive setting otherwise would get errors if trying to remap a drive at another location