Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace printer TCP/IP Prots 1

Status
Not open for further replies.

MoleDirect

Technical User
Sep 4, 2007
45
US
We are undergoing a complete IP change, and we have many users mapped to many different printers..

I am trying to make a script that looks for TCP/IP ports printers are attached to, and replace them with another IP based on an external file... Here is the logic I am working with:

Use with CSV containing 2 fields, OLDIP and NEWIP
___

Script Logical Actions:

enumerate printers

for each printer..
Get ports
if port = any IP in field OLDIP
replace port with ip in field NEWIP
Next


The problem is, all I have is the script to place a new port... Here is the example for that :

Code:
Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_169.254.110.14"
objNewPort.Protocol = 1
objNewPort.HostAddress = "169.254.110.14"
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_

If anyone has done this before, ir has any good resources, your help would be greatly appreciated!
 
My login script FAQ has code to remap printers such as you need.
I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thank you very much!! Excellent resource...

I have a script to add if you like.. It is for VPN users, It runs the login script once a user has connected to the company network..

Make sure you change the IP at: strHost = "10.11.1.110"

to your company intranet. I made this because we have many users who complain about not having their mapped drives when working over VPN. ForumUniversal is my websote, so dont worry, I didnt gank it. :)

If you want go to the site and look for the headding: VPN Logonscript for domains and it gives more info.

Code:
Dim strHost,tries
wscript.sleep 10000
call main 'Script used from ForumUniversal.com  
function main ' Enjoy
strHost = "10.11.1.110"
if Ping(strHost) = True then
  call runlogonscript
Else
  tries = tries + 1
  call waitasec
end if
end function
Function Ping(strHost)
  dim objPing, objRetStatus
  set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
  ("select * from Win32_PingStatus where address = '" & strHost & "'")
  for each objRetStatus in objPing
  if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
  Ping = False
  else
  Ping = True
  end if
  next
End Function
function runlogonscript
strComputer = "."
  Dim objNet,runme,x
  Set objNet = CreateObject("WScript.NetWork")
  strUserName = objNet.UserDomain & "\" & objNet.UserName
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Set objShell = CreateObject("Wscript.Shell")
  Set objEnv = objShell.Environment("process")
  strServer = objEnv("LOGONSERVER")
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
  Set objTranslator = CreateObject("NameTranslate")
  objTranslator.Init ADS_NAME_INITTYPE_GC, ""
  objTranslator.Set ADS_NAME_TYPE_NT4, strUserName
  strUserDN = objTranslator.Get(ADS_NAME_TYPE_1779)
Set objItem = GetObject("LDAP://" & strUserDN)
strscriptPath = objItem.Get("scriptPath")
Dim LogonScript
LogonScript = strServer & "\netlogon\" & strscriptPath
x = ("rundll32 url.dll,FileProtocolHandler " & LogonScript)
WshShell.run x
call goodquits
end function
function waitasec
if tries = 5 then
call quits
else
wscript.sleep 20
wscript.sleep 10000
call main
end if
end function
function quits
end function
Function goodquits
end function
 
The script may need some cleanup.. Im fairly new with VBScript, so I use functions alot as you can see.
 
Hi Mark.. I found the resource, and I found samples to do the following things:


1. Disconnect network drives
2. Map network drives
3. Map network drives based on a group membership
4. Disconnect network printers
5. Connect network printers
6. Set the default printer
7. Modify the registry
8. Have the PC say good morning



I was not able to find one to take a printer, and replace the TCP/IP port from one ting to another based on an external file..

It has plenty of good resources, some which I may be able to marry together, but I am hoping to find somthing a little closer. Thanks!!
 
Take a look at the section for Adding Missing Printers from a predefined list. Also Moving Shares to a New Server. Between those two you should be able to get the job done.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top