Jump to content

Default Printer location


Recommended Posts

Anyone know where the setting is located in the registry for the default printer?

I am working on a routine that I will post that will change the network printers installed on a Windows NT + machine from one server to another. I am doing this as part a migration. I just want to be able to set the user's default printer to what it should be since the server change actually requires me to create a new key. With that change the computer loses it's default printer. I would like to set it to the replaced printer. Any ideas??

I was thinking of just changing the registry setting but I can't find where it is. So far I will have to send a popup to the user that they need to change it. Press button one to open printers to change it or button 2 to do it later.

Link to comment
Share on other sites

Not sure about NT, on Win XP printer prefs are per-user, so the default printer name can be found at:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows:Device

...the data is a comma-separated entry of the name, driver and port name.

If you really want a power tool for doing this chore you can get PRNADMIN.DLL from the Windows 2003 Resource Kit. The included PRNADMIN.DOC file gives examples in VBScript, you could either make and FileInstall VB scripts and Run them with cscript.exe from AutoIt, or if you were feeling really empowered you could use the AutoIt3 beta and create and handle the PrintMaster COM objects from AutoIt itself...

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Anyone know where the setting is located in the registry for the default printer?

Try this...

RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "printer"

More info here ...

http://www.robvanderwoude.com/2kprintcontrol.html

I'm not 100% sure, but monitoring the command above with regmon,

where "printer" was replaced with one of my printers, gives me:

HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device="Brother MFC-9880 USB,winspool,Ne07:"

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

I'm feeling generous. I've used the following on 98/2000/XP machines at work:

; Default printer is denoted with astrisk; shared printers are denoted with $ then share name
MsgBox(4096, "Printer Info", _Identify_Printers() )

; CyberSlug - 18 Nov 2004
; List installed printers (port name drive and shareNameIfApplicable)  also indentify default printer
Func _Identify_Printers()
   Local $key, $default, $i = 1, $list, $name
   If @OSType = "WIN32_WINDOWS" Then
      $key = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers"
      $default = RegRead("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers","Default")
   Else;WIN_NT type
      $key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers"
      $default = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device")
      $default = StringLeft($default, StringInStr($default,",")-1);remove info after comma...
   EndIf

  ;;;$list = StringReplace($list, $default, '** ' & $default)

  ; ENUMERATE LOCAL PRINTERS (AND ALSO 9x PRINTERS SHARED ON OTHER COMPUTERS)
   While 1
     ;#cs - enum bug workaround
         RegRead($key, "")
         If @error = 1 Then ExitLoop
     ;#ce
      Local $name = RegEnumKey($key, $i)
      If @error Then ExitLoop
      Local $port = "<" & RegRead($key & "\" & $name, "Port") & ">"
      If $name = $default Then $port = '* ' & $port
      Local $driver = RegRead($key & "\" & $name, "Printer Driver")
      Local $shared = RegRead($key & "\" & $name, "Share Name")
      If $shared <> "" Then $shared = "$ " & $shared
      $list = $list & $port & "  " & $name & "  [" & $driver & "]  " & $shared & @CRLF
      $i = $i + 1
   WEnd

  ; ENUMERATE 2000/XP PRINTERS SHARED ON OTHER COMPUTERS
   If @OSType = "WIN_NT" Then
      Local $i = 1, $j = 1
      While 1
        ;#cs - enum bug workaround
            RegRead($key, "")
            If @error = 1 Then ExitLoop
        ;#ce
         Local $serverAddress = RegEnumKey($key, $i)
         If @error Then ExitLoop
         $j = 1
         While 1
           ;#cs - enum bug workaround
               RegRead($key & "\" & $serverAddress & "\Printers", "")
               If @error = 1 Then ExitLoop(2)
           ;#ce
            Local $networkedPrinter = RegEnumKey($key & "\" & $serverAddress & "\Printers", $j)
            If @error Then ExitLoop(2)
            $name = RegRead($key & "\" & $serverAddress & "\Printers\" & $networkedPrinter, "Name")
            Local $share = "<\\" & $serverAddress & "\" & RegRead($key & "\" & $serverAddress & "\Printers\" & $networkedPrinter, "Share Name") & ">"
            If $name = $default Then $share = '* ' & $share
            $list = $list & $share & "  " & $name & "  [" & $driver & "]" & @CRLF
            $j = $j + 1
         WEnd
         $i = $i + 1
      WEnd
   EndIf

   If $list = "" Then $list = "No printers detected" & @CRLF
   Return $list
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device="Brother MFC-9880 USB,winspool,Ne07:"

Cheers

Kurt

Yep that is the key. I wil lcheck out the site. I need to see what nexx will be for the new printer and then I can just change it myself in the script. As it stands now I can give them what their default is and do it that way with winwaitactive and send.

Link to comment
Share on other sites

  • 2 years later...

I just updated this as I wanted to use it and didn't quite work on my XP machine

CODE
; Default printer is denoted with astrisk; shared printers are denoted with $ then share name

MsgBox(4096, "Printer Info |" & @OSTYPE & "|", _Identify_Printers())

; CyberSlug - 18 Nov 2004

; Hum3 - 2007-09-14

; List installed printers (port name drive and shareNameIfApplicable) also indentify default printer

Func _Identify_Printers()

Local $key, $default, $i = 1, $list, $name

If @OSTYPE = "WIN32_WINDOWS" Then

$key = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers"

$default = RegRead("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers", "Default")

ElseIf @OSTYPE = "WIN_NT" Then;WIN_NT type

$key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers"

$netKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers"

$default = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")

$default = StringLeft($default, StringInStr($default, ",") - 1);remove info after comma...

Else ;assume "WIN32_NT"

$key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers"

$netKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\LanMan Print Services\Servers"

$default = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")

$default = StringLeft($default, StringInStr($default, ",") - 1);remove info after comma...

EndIf

;;;$list = StringReplace($list, $default, '** ' & $default)

; ENUMERATE LOCAL PRINTERS (AND ALSO 9x PRINTERS SHARED ON OTHER COMPUTERS)

While 1

;#cs - enum bug workaround

RegRead($key, "")

If @error = 1 Then ExitLoop

;#ce

Local $name = RegEnumKey($key, $i)

If @error Then ExitLoop

Local $port = "<" & RegRead($key & "\" & $name, "Port") & ">"

If $name = $default Then $port = '* ' & $port

Local $driver = RegRead($key & "\" & $name, "Printer Driver")

Local $shared = RegRead($key & "\" & $name, "Share Name")

If $shared <> "" Then $shared = "$ " & $shared

$list = $list & $port & " " & $name & " [" & $driver & "] " & $shared & @CRLF

$i = $i + 1

WEnd

; ENUMERATE 2000/XP PRINTERS SHARED ON OTHER COMPUTERS

If @OSTYPE <> "WIN32_WINDOWS" Then

Local $i = 1, $j = 1

While 1

;#cs - enum bug workaround

RegRead($netKey, "")

If @error = 1 Then ExitLoop

;#ce

Local $serverAddress = RegEnumKey($netKey, $i)

If @error Then ExitLoop

$j = 1

While 1

;#cs - enum bug workaround

RegRead($netKey & "\" & $serverAddress & "\Printers", "")

If @error = 1 Then ExitLoop (2)

;#ce

Local $networkedPrinter = RegEnumKey($netKey & "\" & $serverAddress & "\Printers", $j)

If @error Then ExitLoop (2)

$name = RegRead($netKey & "\" & $serverAddress & "\Printers\" & $networkedPrinter, "Name")

Local $share = "<\\" & $serverAddress & "\" & RegRead($netKey & "\" & $serverAddress & "\Printers\" & $networkedPrinter, "Share Name") & ">"

If $name = $default Then $share = '* ' & $share

$list = $list & $share & " " & $name & " [" & $driver & "]" & @CRLF

$j = $j + 1

WEnd

$i = $i + 1

WEnd

EndIf

If $list = "" Then $list = "No printers detected" & @CRLF

Return $list

EndFunc ;==>_Identify_Printers

Link to comment
Share on other sites

An Update.

What I really wanted was a list of printer names that matched the list in ActivePrinter in Excel. This is actually slightly different from the code above and this is what I have got to incase anyone else wants it. i have only tested in Excel 2003

CODE
;Returns a list which should match ActivePrinter and ing the same order

Func _PrinterList()

Local $key, $list, $port, $printer, $printerList[99], $numPrinters ;Set to only work for max of 99 printers

$numPrinters = 0

$key = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"

$j = 1

While 1

$printer = RegEnumVal($key, $j)

If @error < 0 Then ExitLoop

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $printer=RegEnumKey($key,$j) = ' & "Prob 1? " & $j & " " & $printer & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

$port = RegRead($key ,$printer)

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : RegRead($key,$printer) = ' & "Prob? " & $port & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

$port = StringRight($port,StringLen($port)-StringInStr($port,","))

$printerList[$numPrinters] = $printer & " on " & $port

$numPrinters += 1

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $numPrinters = ' & $numPrinters & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

$j = $j + 1

WEnd

if $numPrinters > 0 Then

ReDim $printerList[$numPrinters]

Else ;no printers set up

ReDim $printerList[1]

$printerList[0] = "No printers setup"

EndIf

Return $printerList

EndFunc ;==>_PrinterList

Link to comment
Share on other sites

@all

Less lines of code needed with the WMI approach.

Const $DEFAULT = 4

$strComputer = "."

$objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\cimv2")
$colPrinters = $objWMIService.ExecQuery ("Select * From Win32_Printer")
     

For $objPrinter in $colPrinters
    If $objPrinter.Attributes And $DEFAULT Then 
        If $objPrinter.ShareName <> "" Then
        ConsoleWrite( $objPrinter.ShareName & @CRLF )
        EndIf
    EndIf
Next

Regards,

ptrex

Link to comment
Share on other sites

@all

Wrong code, sorry guys.

This is the correct one and even less lines of code :)

$strComputer = "."

$objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\cimv2")
$colPrinters = $objWMIService.ExecQuery ("Select * From Win32_Printer Where Default = True")
     

For $objPrinter in $colPrinters
        ConsoleWrite($objPrinter.Name & @CRLF)
Next

regards,

ptrex

Link to comment
Share on other sites

  • 4 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...