Showing posts with label printer. Show all posts
Showing posts with label printer. Show all posts

20 September 2007

vbscript to change printer server

Hello,

many people asked on newsgroup how to migrate from a printer server to another, without manual intervention off course.

1/Migrate drivers and declared printer with print migrator from Microsoft:

http://www.microsoft.com/downloads/details.aspx?FamilyID=9b9f2925-cbc9-44da-b2c9-ffdbc46b0b17&displaylang=en

2/

Use the following simple vbscript. Jut replace MYNEWPRINTERSERVER with the new print server name.

You may call it with cscript to not send popup, or remove wscript.echo to not warn user.

The best way is during logon script

The new print server must be already online and ready, as it removes the current printer and map again on the new print server

You can download here:

http://gollum123.free.fr/printermigrator.vbs

here is the code source:

----------------------------------------------

On Error Resume Next
Function GetDefaultPrinter()
sRegVal = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
sDefault = ""
On Error Resume Next
sDefault = objShell.RegRead(sRegVal)
sDefault = Left(sDefault ,InStr(sDefault, ",") - 1)
On Error Goto 0
GetDefaultPrinter = sDefault
End Function

Set objNetwork = CreateObject ("Wscript.Network")
Set objShell = CreateObject ("WScript.Shell")
Set objFSO = CreateObject ("Scripting.FileSystemObject")

LogonServer = objShell.ExpandEnvironmentStrings("%logonserver%")
UserName = objShell.ExpandEnvironmentStrings("%username%")

strComputer = "."
PrintServer = "MYNEWPRINTERSERVER"
PrintServer = LCase (PrintServer)

Err.Clear
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")

If Err.Number Then
wscript.echo ("Error : " & Err.Number & ": " & Err.Description & VbCrLf)
Err.Clear

Else
ImpDefault = GetDefaultPrinter
Set colInstalledPrinters = objWMIService.ExecQuery _
("SELECT * FROM Win32_Printer")
For Each objPrinter in colInstalledPrinters
PrinterArray = Split (objPrinter.Name , "\")

If (LCase(objPrinter.ServerName) <> "") and (LCase(objPrinter.ServerName) <> "\\" & PrintServer) then

objNetwork.AddWindowsPrinterConnection "\\" & PrintServer & "\" & PrinterArray(3)
If Err.Number Then
wscript.echo ("Error : " & Err.Number & ": " & Err.Description & VbCrLf)
Err.Clear
End If

If ImpDefault = objPrinter.Name then
objNetwork.SetDefaultPrinter ("\\" & PrintServer & "\" & PrinterArray(3))
End If

objNetwork.RemovePrinterConnection objPrinter.Name
End If
Next
End If

-------------------

20 June 2007

Free Citrix tool: stress Printer Driver

With a free citrix account, you can download it here:
http://support.citrix.com/kb/entry.jspa?externalID=CTX109374&searchID=45234516

Many driver problems in the Terminal Services environment revolve around poor multi-threaded performance, which in turn can cause Print Spooler instability. Problematic multi-threaded performance is usually exposed when multiple users connect to a Terminal Server simultaneously using the same print driver. Symptoms include the failure to autocreate client printers, increased thread count of the Printer Spooler and/or Citrix Print Manager services, and possibly the unresponsiveness and/or unexpected termination of these services (crashes).
This tool can be used to simulate multiple sessions autocreating printers using the same print driver.
It can also be used to compare the following among various drivers:
• CPU load incurred while creating a printer using a particular driver
• Time required to successfully create a printer using a particular driver