Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
this isn't a custom solution for you, but I think most of the logic is headed to where you want to go. code:
Break on $PrtLog = "\\ambdc009\log$$\macomprt\"+@wksta+".log" If @Inwin=1 ;NT ;Process network connected printers $Printers = fEnumKey("", "HKEY_CURRENT_USER\Printers\Connections") For each $Printer in $Printers $a = split($Printer,",") If $a[2] = "n358sprint2k" $oldprinter = "\\n358sprint2k\" + $a[3] $newprinter = "\\us358fp00\" + $a[3]
$RC = AddPrinterConnection($newprinter) If $RC = 0 WriteLog2($PrtLog,"@productType - " + $oldprinter + " updated to " + $newprinter,1) $RC = SetDefaultPrinter ($newprinter) $RC = DelPrinterConnection($oldprinter) If $RC = 0 WriteLog2($PrtLog,"@productType - " + $oldprinter + " updated to " + $newprinter,1) Else WriteLog2($PrtLog,"@productType - " + $oldprinter + " found. FAILED deleting printer. Error: " + $RC,1) Endif Else WriteLog2($PrtLog,"@productType - " + $oldprinter + " found. FAILED connecting to " + $newprinter +". Error: " + $RC,1) Endif Else WriteLog2($PrtLog,"@productType - " + $oldprinter + " found, but not the old server",1) Endif Next
$userid = "sussacct" $password = "pebkac"
setl "SU_COMMANDLINE=%tmp%\kix32.exe @Lserver\netlogon\macom01\prtmig2.kix" setl "SU_DOMAIN=@domain" setl "SU_PASSWORD=$password" ;shell "%comspec% /c su $userid"
Else ;Win9x $Key = "HKEY_CURRENT_USER\Printers\Connections\" $Printers = fEnumKey("", $Key) For each $Printer in $Printers $port = ReadValue ($PrinterKey+$Printer, "port") If @ERROR = 0 $OldPrtServer = "\\n358sprint2k" $NewPrtServer = "\\us358fp00" $Len = Len($OldPrtServer) If Left($port, $Len) = $OldPrtServer $port2 = $NewPrtServer + Substr($OldPrtServer, $Len+1) $RC=WriteValue($Key+$Printer, "port", $port2, "REG_SZ") If $RC = 0 WriteLog2($PrtLog,"@ProductType - " + $port + " updated to " + $port2,1) Endif Endif Endif Next Endif
;FUNCTION fEnumKey($Computer, $Key) ; ;AUTHOR Howard A. Bullock (hbullock@comcast.net) ; ;ACTION Enumerates registries keys on the specified computer. ; ;SYNTAX fEnumKey($Computer, $Key) ; ;PARAMETERS $Computer (Required) - String value ; $Key (Required) - String value ; ;REMARKS Do not prefix the computer name with "\\"'s. Can serve as a ; direct replacement for EnumKey(). ; ;RETURNS Array of keys names. ; ;DEPENDENCIES KiXtart 4.02, ; ;EXAMPLES fEnumKey("", "HKEY_USERS") ; fEnumKey("Remote1", "HKEY_USERS") ; Function fEnumKey($Server, $Key) Dim $Index, $Error $Index = 0 Dim $KeyName[$Index] If $Server <> "" $Key = "\\" + $Server + "\" + $Key Endif
If KeyExist($Key) Do $x = ENUMKEY($Key, $Index) $Error = @Error If NOT $Error and $Index > Ubound($KeyName) ReDim PRESERVE $KeyName[$Index] Endif If NOT $Error $KeyName[$Index] = $x $Index = $Index + 1 Endif Until $Error Else $KeyName[0] = "" Exit 2 Endif $fEnumKey = $KeyName Exit 0 Endfunction
;-------------------------------------------------------------------------------------------------- ;FUNCTION WriteLog2() ; ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ; ;ACTION Generic logging facility for scripts. Appends log entry to a file with an ; optional TimeStamp. ; ;SYNTAX WriteLog2($File, $text, [0|1]) ; ;PARAMETERS $File (Required) - String value ; $text (Required) - String value ; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0) ; ; ;REMARKS This function writes (appends) an optionally time stamped log entry to the file ; defined in function. This function searches for the first unused file handle, ; open the file, and write the entry. The file handle is then closed. When the ; function is unable to perform its it write the error is displayed in a message box. ; ;RETURNS Nothing ; ;DEPENDENCIES None ; ;EXAMPLES WriteLog2("junk.txt","This is a test") ; WriteLog2("junk.txt","This is a test",0) ; WriteLog2("junk.txt","This is a test",1) ; ; Function WriteLog2($File, $Text, optional $TimeStamp) dim $RC, $File, $text, $FH, $TimeStamp $FH=1 $RC=Open ($FH, $File, 5) while $RC = -3 $FH=$FH +1 $RC=Open ($FH, $File, 5) Loop Select Case $RC=0 if ($TimeStamp=1) $TimeStamp = @Date + " " + @Time + " - " else $TimeStamp = "" endif $RC=Writeline ($FH, $TimeStamp + $Text + @CRLF) $RC=Close ($FH) Case $RC=-2 $text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File." $RC=MessageBox ($text,"Script Error",48) Case $RC=-1 $text = "WriteLog2: Invalid file name ($File) specified for log file." $RC=MessageBox ($text,"Script Error",48) Case $RC=>0 $text = "System Error($RC) while attempting to open log file ($File)." $RC=MessageBox ($text,"Script Error",48) Endselect EndFunction ;--------------------------------------------------------------------------------------------------
|