tazdev Posted May 16, 2005 Share Posted May 16, 2005 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 More sharing options...
tazdev Posted May 16, 2005 Author Share Posted May 16, 2005 Yeah I couldn't find it either. Sucks. Link to comment Share on other sites More sharing options...
DaveF Posted May 16, 2005 Share Posted May 16, 2005 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 More sharing options...
/dev/null Posted May 17, 2005 Share Posted May 17, 2005 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.htmlI'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:"CheersKurt __________________________________________________________(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 More sharing options...
CyberSlug Posted May 17, 2005 Share Posted May 17, 2005 I'm feeling generous. I've used the following on 98/2000/XP machines at work: expandcollapse popup; 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 More sharing options...
tazdev Posted May 17, 2005 Author Share Posted May 17, 2005 HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device="Brother MFC-9880 USB,winspool,Ne07:"CheersKurtYep 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 More sharing options...
hum3 Posted September 14, 2007 Share Posted September 14, 2007 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 More sharing options...
hum3 Posted September 14, 2007 Share Posted September 14, 2007 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 More sharing options...
ptrex Posted September 14, 2007 Share Posted September 14, 2007 @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 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
ptrex Posted September 14, 2007 Share Posted September 14, 2007 @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 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
weaponx Posted September 14, 2007 Share Posted September 14, 2007 This thread was dead and buried, now it is walking among us in a lifeless state feasting on the flesh of the living. GREAT Link to comment Share on other sites More sharing options...
blckpythn Posted August 8, 2012 Share Posted August 8, 2012 Arise from the dead once more my minion. Skitty 1 Link to comment Share on other sites More sharing options...
Valik Posted August 8, 2012 Share Posted August 8, 2012 Arise from the dead once more my minion.Your minion turned on you. 48 hour ban. Do it again and you are gone permanently. Link to comment Share on other sites More sharing options...
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