joe_Burge Posted August 22, 2011 Posted August 22, 2011 I made this recently for a customer, maybe someone will find it useful. As with most scripts used in the world, this is not entirely new source and was not created by me 100%. If I remember where I got the bulk of it, I will credit the author(s). 'execute an ipconfig to the local machine and store the ouput in the stdout text stream Set objShell = CreateObject("Wscript.Shell") set objNetwork = WScript.CreateObject("WScript.Network") set objExec = objShell.Exec("%comspec% /c ipconfig.exe") 'loop through the stream looking for key phrase "IPv4 Address" do while NOT (objExec.Stdout.AtEndOfStream) strLine = objExec.Stdout.ReadLine if(inStr(strLine, "IPv4 Address")) then 'Parse strLine to obtain IP. strIP = trim(right(strLine, len(strLine) - inStrRev(strLine, ":"))) exit do end if loop arrTokens = split(strIP, ".") select case arrTokens(2) '3rd token/octet'If the client IP address is X.X.100.X map Printer_1, wait for 2 seconds then make Printer_1 the default case "100" objNetwork.AddWindowsPrinterConnection "\\server\Printer_1" WScript.Sleep 2000 objNetwork.SetDefaultPrinter "\\server\Printer_1" 'If the client IP address is X.X.200.X map Printer_2 and Printer_3, wait for 2 seconds then make Printer_3 the default case "200" objNetwork.AddWindowsPrinterConnection "\\server\Printer_2" objNetwork.AddWindowsPrinterConnection "\\server\Printer_3" WScript.Sleep 2000 objNetwork.SetDefaultPrinter "\\server\Printer_3" 'If the client IP address is X.X.300.X map Printer_4, wait for 2 seconds then make Printer_4 the default case "300" objNetwork.AddWindowsPrinterConnection "\\server\Printer_4" WScript.Sleep 2000 objNetwork.SetDefaultPrinter "\\server\Printer_4" end select If you are running Windows XP, you will need to replace "IPv4 Address" with just "IP Address" to make it work.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now