Login | |
|
 |
Re: Checking which printer is default printer IN WSH - 6/27/2004 7:02:11 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Is it possible to use WMI? if so this might help: quote: strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters MSG = msg & "Name: " & objPrinter.Name & vbcr MSG = msg & "Location: " & objPrinter.Location & vbcr MSG = msg & "Default: " & objPrinter.Default & vbcr Next msgbox msg
Here is a link to a couple MS resources that have WMI samples. http://www.microsoft.com/technet/community/scriptcenter/default.mspx Mike
|
|
| |
|
|
|
 |
Re: Checking which printer is default printer IN WSH - 7/9/2004 4:46:05 AM
|
|
 |
|
| |
EDLiN
Posts: 4
Score: 0
Joined: 7/9/2004
From: USA
Status: offline
|
This is my first post. This thread helped me with a project so I figured I would post my cut final. Code is a combination of previous posts with a little tweekin and overcomes the XP/2K3 objPrinter.default limitation. It outputs a list to c:\printer.lst with DEFAULT next to the default printer on 2K,XP, and 2K3 systems. Drive letters were hard coded for my purposes.. but im sure you guys can figure it out. The idea is to have this run on every logon to a terminal server to dump printers to a client home drive. Then another script is run across the home drives which collects all of the data into a spreadsheet so that profiles can be rebuilt and printers re-assigned. Printer lists are first output to the home drives because clients do not all have permissions to write to a common area. Anyway, works great on my end.. Thanks for the other posts which got me to this point. Here ya go: ---------------------------------------------------------------- Option Explicit dim objWMIService dim ColInstalledPrinters dim PrinterTextFile dim objPrinter dim DefaultPrinterString dim objReg dim FSO dim outstr Const HKEY_CURRENT_USER = &H80000001 Const ForReading = 1, ForWriting = 2, ForAppending = 8 Set objReg=GetObject ("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") objReg.GetStringValue HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", DefaultPrinterString Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer") Set FSO = CreateObject("Scripting.FileSystemObject") if fso.driveexists("C:") then Set PrinterTextFile = FSO.CreateTextFile("C:\Printer.lst", ForAppending) if fso.fileexists("C:\Printer.Lst") then For Each objPrinter in colInstalledPrinters outstr="" outstr=objPrinter.Name & "," & objPrinter.Location outstr=outstr & "," if instr(DefaultPrinterString,",")>0 then if lcase(mid(DefaultPrinterString,1,instr(DefaultPrinterString,",")-1))=lcase(objPrinter.Name) then outstr=outstr & "DEFAULT" end if end if PrinterTextFile.writeline outstr Next PrinterTextFile.close end if end if Set FSO = Nothing Set objWMIService = Nothing Set objReg = Nothing Set colInstalledPrinters = Nothing
|
|
| |
|
|
|
|
|