check for installed printer

  • Thread starter Thread starter Keith G Hicks
  • Start date Start date
K

Keith G Hicks

Guest
Is there some sort of command line tool that will let me check for the

existence of an installed printer? I knwo I can use Prnmngr.vbs and related

tools but they give me too much information. I'm hoping there's something

simpler that will just confirm if a printer is installed or not.
 
I'm doing this in a clunky sort of way because I don't have any idea how

else to do it just yet.



I can run the following in a command window and it works fine. The results

go to the specified text file.



C:\>c:\windows\system32\cscript c:\windows\system32\prncnfg.vbs -g -p

"Ghostscript PS" > "c:\GSPrinterInfo.txt"



But I'm trying to run this from inside an Inno setup. The ShellExec command

in Inno requires me to split up the thing into the command and the command's

parameters. So I tried this:



FileString := 'c:\windows\system32\cscript';

ParamString := ' c:\windows\system32\prncnfg.vbs -g -p "Ghostscript PS" >

"c:\GSPrinterInfo.txt"';

ShellResult := ShellExec('', FileString, ParamString, '', SW_SHOW,

ewWaitUntilTerminated, ErrorCode);



The problem is that the part that sends the results to the text file:



> "c:\GSPrinterInfo.txt"';




is not actually a parameter, it's a DOS command apart from cscript. So I get

an error.



I was looking for some switch for cscript that sends the results to a file

but I don't see one. I'm not getting faste enough help in the Inno newsgroup

so I'm asking here if there's a way to do cscript to file other than >

"c:\GSPrinterInfo.txt"';
 
In news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl,

Keith G Hicks typed:



> Is there some sort of command line tool that will let me check for the

> existence of an installed printer? I knwo I can use Prnmngr.vbs and

> related tools but they give me too much information. I'm hoping

> there's something simpler that will just confirm if a printer is

> installed or not.




Part of the power of Unix/Linux is its ability to redirect input/output

using pipes, which allows one to take the output of one command and use it

as input for another, etc. M$ has at least learned to do that to a very

limited extent, certainly nowhere near the functionality of such simple

tools as grep, awk and sed.



The M$ "find" command will let you search the Prnmngr.vbs output for the

item of interest, which can be assigned to a variable, compared and used for

further processing. A simple illustration will suggest a solution for your

needs, since by implication you seem competent at scripting:



D:\> dir /s

.... (lengthy file listing expunged)

Total Files Listed:

100930 File(s) 15,387,877,309 bytes

24543 Dir(s) 18,508,480,512 bytes free



D:\> dir /s | find "well"

09/04/2001 20:31 153,540 wellington_gateway_1.jpg

09/04/2001 20:35 186,802 wellington_gateway_2.jpg

09/04/2001 20:38 152,034 wellington_gateway_3.jpg

09/04/2001 20:45 181,920 wellington_gateway_4.jpg

09/04/2001 20:48 185,854 wellington_gateway_5.jpg

09/04/2001 20:51 208,789 wellington_gateway_6.jpg
 
Paste the following code into a new text file (Notepad) document. Save it,

then rename it Installed_Printers.vbs. Copy *between* the dotted lines, do

not include the lines. You can probably run the script by double-clicking.

If so, I'd recommend changing the file association for VBS to "Edit" instead

of "Open". This is because of potential security risks. No biggy, just one

of those "rules". If the file doesn't run using double-click, right-click it

and "Open". If you have a lot of printers and don't want to go through the

whole list, I can either have it produce a single list, or I can include an

Input box where you can enter the name of the printer to list, if installed,

or I can make individual scripts for each printer (and include instructions

for adding more.) Another option is to list the port along with the printer

name. Anything else?



'-------------------------------------------------------------------



strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")



Set colInstalledPrinters = objWMIService.ExecQuery _

("Select * from Win32_Printer")



For Each objPrinter in colInstalledPrinters

wscript.echo objPrinter.name

Next



'-----------------------------------------------------------------------



--

Ronin



"Keith G Hicks" wrote in message

news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl...

> Is there some sort of command line tool that will let me check for the

> existence of an installed printer? I knwo I can use Prnmngr.vbs and

> related tools but they give me too much information. I'm hoping there's

> something simpler that will just confirm if a printer is installed or not.

>
 
Ronin,



Thanks. That helps a lot. And while I was reading your post it occurred to

me taht I could have even created a very simple bat file to run my previous

code and then run the batch file inside of Inno so as not to worry about

params.



THanks again.



"Ronin" wrote in message

news:uZ9y0whwKHA.5940@TK2MSFTNGP02.phx.gbl...

> Paste the following code into a new text file (Notepad) document. Save it,

> then rename it Installed_Printers.vbs. Copy *between* the dotted lines, do

> not include the lines. You can probably run the script by double-clicking.

> If so, I'd recommend changing the file association for VBS to "Edit"

> instead of "Open". This is because of potential security risks. No biggy,

> just one of those "rules". If the file doesn't run using double-click,

> right-click it and "Open". If you have a lot of printers and don't want to

> go through the whole list, I can either have it produce a single list, or

> I can include an Input box where you can enter the name of the printer to

> list, if installed, or I can make individual scripts for each printer (and

> include instructions for adding more.) Another option is to list the port

> along with the printer name. Anything else?

>

> '-------------------------------------------------------------------

>

> strComputer = "."

> Set objWMIService = GetObject("winmgmts:" _

> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

>

> Set colInstalledPrinters = objWMIService.ExecQuery _

> ("Select * from Win32_Printer")

>

> For Each objPrinter in colInstalledPrinters

> wscript.echo objPrinter.name

> Next

>

> '-----------------------------------------------------------------------

>

> --

> Ronin

>

> "Keith G Hicks" wrote in message

> news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl...

>> Is there some sort of command line tool that will let me check for the

>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>> related tools but they give me too much information. I'm hoping there's

>> something simpler that will just confirm if a printer is installed or

>> not.

>>


>
 
You're welcome. It's simple to change the file to get the output you want.

Writing it all to a file, for instance. Just ask.



--

Ronin



"Keith G Hicks" wrote in message

news:ucjaNAiwKHA.1692@TK2MSFTNGP04.phx.gbl...

> Ronin,

>

> Thanks. That helps a lot. And while I was reading your post it occurred to

> me taht I could have even created a very simple bat file to run my

> previous code and then run the batch file inside of Inno so as not to

> worry about params.

>

> THanks again.

>

> "Ronin" wrote in message

> news:uZ9y0whwKHA.5940@TK2MSFTNGP02.phx.gbl...

>> Paste the following code into a new text file (Notepad) document. Save

>> it, then rename it Installed_Printers.vbs. Copy *between* the dotted

>> lines, do not include the lines. You can probably run the script by

>> double-clicking. If so, I'd recommend changing the file association for

>> VBS to "Edit" instead of "Open". This is because of potential security

>> risks. No biggy, just one of those "rules". If the file doesn't run using

>> double-click, right-click it and "Open". If you have a lot of printers

>> and don't want to go through the whole list, I can either have it produce

>> a single list, or I can include an Input box where you can enter the name

>> of the printer to list, if installed, or I can make individual scripts

>> for each printer (and include instructions for adding more.) Another

>> option is to list the port along with the printer name. Anything else?

>>

>> '-------------------------------------------------------------------

>>

>> strComputer = "."

>> Set objWMIService = GetObject("winmgmts:" _

>> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

>>

>> Set colInstalledPrinters = objWMIService.ExecQuery _

>> ("Select * from Win32_Printer")

>>

>> For Each objPrinter in colInstalledPrinters

>> wscript.echo objPrinter.name

>> Next

>>

>> '-----------------------------------------------------------------------

>>

>> --

>> Ronin

>>

>> "Keith G Hicks" wrote in message

>> news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl...

>>> Is there some sort of command line tool that will let me check for the

>>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>>> related tools but they give me too much information. I'm hoping there's

>>> something simpler that will just confirm if a printer is installed or

>>> not.

>>>


>>


>

>
 
I feel pretty silly. I was sitting there staring at this Inno script trying

to figure out how to get the ShellExec to spit out a text file. It didn't

occur to me to go back to the old days and write a batch file that I could

call from ShellExec. And I didn't know I could execute vb script like that

either. I never bothered opening up the built in vbs files in an editor to

see what was going on. Calling a vbs file from the command line in Windows

is not something I was aware of being able to do. I got all buried in the

code i was working on and couldn't see the forest!





"Ronin" wrote in message

news:%23o%23cRDiwKHA.732@TK2MSFTNGP06.phx.gbl...

> You're welcome. It's simple to change the file to get the output you want.

> Writing it all to a file, for instance. Just ask.

>

> --

> Ronin

>

> "Keith G Hicks" wrote in message

> news:ucjaNAiwKHA.1692@TK2MSFTNGP04.phx.gbl...

>> Ronin,

>>

>> Thanks. That helps a lot. And while I was reading your post it occurred

>> to me taht I could have even created a very simple bat file to run my

>> previous code and then run the batch file inside of Inno so as not to

>> worry about params.

>>

>> THanks again.

>>

>> "Ronin" wrote in message

>> news:uZ9y0whwKHA.5940@TK2MSFTNGP02.phx.gbl...

>>> Paste the following code into a new text file (Notepad) document. Save

>>> it, then rename it Installed_Printers.vbs. Copy *between* the dotted

>>> lines, do not include the lines. You can probably run the script by

>>> double-clicking. If so, I'd recommend changing the file association for

>>> VBS to "Edit" instead of "Open". This is because of potential security

>>> risks. No biggy, just one of those "rules". If the file doesn't run

>>> using double-click, right-click it and "Open". If you have a lot of

>>> printers and don't want to go through the whole list, I can either have

>>> it produce a single list, or I can include an Input box where you can

>>> enter the name of the printer to list, if installed, or I can make

>>> individual scripts for each printer (and include instructions for adding

>>> more.) Another option is to list the port along with the printer name.

>>> Anything else?

>>>

>>> '-------------------------------------------------------------------

>>>

>>> strComputer = "."

>>> Set objWMIService = GetObject("winmgmts:" _

>>> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

>>>

>>> Set colInstalledPrinters = objWMIService.ExecQuery _

>>> ("Select * from Win32_Printer")

>>>

>>> For Each objPrinter in colInstalledPrinters

>>> wscript.echo objPrinter.name

>>> Next

>>>

>>> '-----------------------------------------------------------------------

>>>

>>> --

>>> Ronin

>>>

>>> "Keith G Hicks" wrote in message

>>> news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl...

>>>> Is there some sort of command line tool that will let me check for the

>>>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>>>> related tools but they give me too much information. I'm hoping there's

>>>> something simpler that will just confirm if a printer is installed or

>>>> not.

>>>>

>>>


>>

>>


>
 
"Greg Russell" wrote in message

news:7vvjkuF4h0U1@mid.individual.net...

> In news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl,

> Keith G Hicks typed:

>

>> Is there some sort of command line tool that will let me check for the

>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>> related tools but they give me too much information. I'm hoping

>> there's something simpler that will just confirm if a printer is

>> installed or not.


>

> Part of the power of Unix/Linux is its ability to redirect input/output

> using pipes, which allows one to take the output of one command and use it

> as input for another, etc. M$ has at least learned to do that to a very

> limited extent, certainly nowhere near the functionality of such simple

> tools as grep, awk and sed.

>

> The M$ "find" command will let you search the Prnmngr.vbs output for the

> item of interest, which can be assigned to a variable, compared and used

> for

> further processing. A simple illustration will suggest a solution for your

> needs, since by implication you seem competent at scripting:

>

> D:\> dir /

> ... (lengthy file listing expunged)

> Total Files Listed:

> 100930 File(s) 15,387,877,309 bytes

> 24543 Dir(s) 18,508,480,512 bytes free

>

> D:\> dir /s | find "well"

> 09/04/2001 20:31 153,540 wellington_gateway_1.jpg

> 09/04/2001 20:35 186,802 wellington_gateway_2.jpg

> 09/04/2001 20:38 152,034 wellington_gateway_3.jpg

> 09/04/2001 20:45 181,920 wellington_gateway_4.jpg

> 09/04/2001 20:48 185,854 wellington_gateway_5.jpg

> 09/04/2001 20:51 208,789 wellington_gateway_6.jpg




Who gives a flying whoop about linux? And what does the dir command have to

do with finding installed printers? What is it with you ignorant linux

trolls that makes you believe that others want to listen to your

proselytizing linux cr@p? Guys like you give linux a bad name. Get a life

or get lost, we don't need another ignorant linux nutcase in these groups!
 
"Peter" wrote in message

news:piymn.9557$NH1.1048@newsfe14.iad...



> what does the dir command have to do with finding installed printers?




Unfortunately, your feeble mind is unable to use the example to "connect the

dots" of the prnmngr.vbs output being piped into the find command to extract

the required printer information the OP was looking for from the command

line.



Cheer up though, there's still hope for you.
 
Happens to all of us.... All the time!



--

Ronin



"Keith G Hicks" wrote in message

news:Om2MyIiwKHA.812@TK2MSFTNGP06.phx.gbl...

>I feel pretty silly. I was sitting there staring at this Inno script trying

>to figure out how to get the ShellExec to spit out a text file. It didn't

>occur to me to go back to the old days and write a batch file that I could

>call from ShellExec. And I didn't know I could execute vb script like that

>either. I never bothered opening up the built in vbs files in an editor to

>see what was going on. Calling a vbs file from the command line in Windows

>is not something I was aware of being able to do. I got all buried in the

>code i was working on and couldn't see the forest!

>

>

> "Ronin" wrote in message

> news:%23o%23cRDiwKHA.732@TK2MSFTNGP06.phx.gbl...

>> You're welcome. It's simple to change the file to get the output you

>> want. Writing it all to a file, for instance. Just ask.

>>

>> --

>> Ronin

>>

>> "Keith G Hicks" wrote in message

>> news:ucjaNAiwKHA.1692@TK2MSFTNGP04.phx.gbl...

>>> Ronin,

>>>

>>> Thanks. That helps a lot. And while I was reading your post it occurred

>>> to me taht I could have even created a very simple bat file to run my

>>> previous code and then run the batch file inside of Inno so as not to

>>> worry about params.

>>>

>>> THanks again.

>>>

>>> "Ronin" wrote in message

>>> news:uZ9y0whwKHA.5940@TK2MSFTNGP02.phx.gbl...

>>>> Paste the following code into a new text file (Notepad) document. Save

>>>> it, then rename it Installed_Printers.vbs. Copy *between* the dotted

>>>> lines, do not include the lines. You can probably run the script by

>>>> double-clicking. If so, I'd recommend changing the file association for

>>>> VBS to "Edit" instead of "Open". This is because of potential security

>>>> risks. No biggy, just one of those "rules". If the file doesn't run

>>>> using double-click, right-click it and "Open". If you have a lot of

>>>> printers and don't want to go through the whole list, I can either have

>>>> it produce a single list, or I can include an Input box where you can

>>>> enter the name of the printer to list, if installed, or I can make

>>>> individual scripts for each printer (and include instructions for

>>>> adding more.) Another option is to list the port along with the printer

>>>> name. Anything else?

>>>>

>>>> '-------------------------------------------------------------------

>>>>

>>>> strComputer = "."

>>>> Set objWMIService = GetObject("winmgmts:" _

>>>> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

>>>>

>>>> Set colInstalledPrinters = objWMIService.ExecQuery _

>>>> ("Select * from Win32_Printer")

>>>>

>>>> For Each objPrinter in colInstalledPrinters

>>>> wscript.echo objPrinter.name

>>>> Next

>>>>

>>>> '-----------------------------------------------------------------------

>>>>

>>>> --

>>>> Ronin

>>>>

>>>> "Keith G Hicks" wrote in message

>>>> news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl...

>>>>> Is there some sort of command line tool that will let me check for the

>>>>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>>>>> related tools but they give me too much information. I'm hoping

>>>>> there's something simpler that will just confirm if a printer is

>>>>> installed or not.

>>>>>

>>>>

>>>

>>>


>>


>

>
 
wmic printer list status



John



Keith G Hicks wrote:

> Is there some sort of command line tool that will let me check for the

> existence of an installed printer? I knwo I can use Prnmngr.vbs and related

> tools but they give me too much information. I'm hoping there's something

> simpler that will just confirm if a printer is installed or not.

>

>
 
I have seven printers that are all installed and functioning, all listed as

"Ready" in the printers folder. (Only three are actually printers, if you

know what I mean.) Your command shows the status for all of them as

"Unknown". Any ideas?



--

Ronin



"John John - MVP" wrote in message

news:e6tVk9rwKHA.5940@TK2MSFTNGP02.phx.gbl...

> wmic printer list status

>

> John

>

> Keith G Hicks wrote:

>> Is there some sort of command line tool that will let me check for the

>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>> related tools but they give me too much information. I'm hoping there's

>> something simpler that will just confirm if a printer is installed or

>> not.
 
Yes, I've noticed that also. It's the command that I found to produce

the least verbiage. I couldn't find a verb or switch to list the

printers only. Your WMI script has greater flexibility and allows you

to select the InstalledPrinters column only. If you work your script to

include the status column I think it would probably reports the same

thing. Can you add the column to the script so that we can try it?



We might have to go down into the WMI bowels to figure this one out...



John



Ronin wrote:

> I have seven printers that are all installed and functioning, all listed

> as "Ready" in the printers folder. (Only three are actually printers, if

> you know what I mean.) Your command shows the status for all of them as

> "Unknown". Any ideas?

>
 
John John - MVP wrote:

> Yes, I've noticed that also. It's the command that I found to produce

> the least verbiage. I couldn't find a verb or switch to list the

> printers only.




wmic printer list instance



John
 
ooh. I like that. Thank you.





"John John - MVP" wrote in message

news:e6tVk9rwKHA.5940@TK2MSFTNGP02.phx.gbl...

> wmic printer list status

>

> John

>

> Keith G Hicks wrote:

>> Is there some sort of command line tool that will let me check for the

>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>> related tools but they give me too much information. I'm hoping there's

>> something simpler that will just confirm if a printer is installed or

>> not.
 
You're welcome. Are all your "Ready" printers showing an "Unknown" status?



John



Keith G Hicks wrote:

> ooh. I like that. Thank you.

>

>

> "John John - MVP" wrote in message

> news:e6tVk9rwKHA.5940@TK2MSFTNGP02.phx.gbl...

>> wmic printer list status

>>

>> John

>>

>> Keith G Hicks wrote:

>>> Is there some sort of command line tool that will let me check for the

>>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>>> related tools but they give me too much information. I'm hoping there's

>>> something simpler that will just confirm if a printer is installed or

>>> not.


>

>
 
Yes. They all show as unkown. But for my purposes right now I don't think

that matters.





"John John - MVP" wrote in message

news:eMwaOUtwKHA.3564@TK2MSFTNGP05.phx.gbl...

> You're welcome. Are all your "Ready" printers showing an "Unknown"

> status?

>

> John

>

> Keith G Hicks wrote:

>> ooh. I like that. Thank you.

>>

>>

>> "John John - MVP" wrote in message

>> news:e6tVk9rwKHA.5940@TK2MSFTNGP02.phx.gbl...

>>> wmic printer list status

>>>

>>> John

>>>

>>> Keith G Hicks wrote:

>>>> Is there some sort of command line tool that will let me check for the

>>>> existence of an installed printer? I knwo I can use Prnmngr.vbs and

>>>> related tools but they give me too much information. I'm hoping there's

>>>> something simpler that will just confirm if a printer is installed or

>>>> not.


>>
 
I could add it, but it comes up the same: "Unknown". I don't know where the

disconnect is, but it is.



If you don't need or can't get the printer status, your wmic command is

ideal, though if you want that limited output you have to add the "instance"

parameter. Otherwise, the output is voluminous.



--

Ronin



"John John - MVP" wrote in message

news:ewucuuswKHA.3408@TK2MSFTNGP06.phx.gbl...

> Yes, I've noticed that also. It's the command that I found to produce the

> least verbiage. I couldn't find a verb or switch to list the printers

> only. Your WMI script has greater flexibility and allows you to select

> the InstalledPrinters column only. If you work your script to include the

> status column I think it would probably reports the same thing. Can you

> add the column to the script so that we can try it?

>

> We might have to go down into the WMI bowels to figure this one out...

>

> John

>

> Ronin wrote:

>> I have seven printers that are all installed and functioning, all listed

>> as "Ready" in the printers folder. (Only three are actually printers, if

>> you know what I mean.) Your command shows the status for all of them as

>> "Unknown". Any ideas?

>>
 
Any reason it's not okay just do read the subkeys?



HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows

NT\CurrentVersion\Print\Printers subkeys



I recoded my Inno project to do that and it's MUCH easier than the other way

I was working on.





"Keith G Hicks" wrote in message

news:up8X%23%23gwKHA.732@TK2MSFTNGP06.phx.gbl...

> Is there some sort of command line tool that will let me check for the

> existence of an installed printer? I knwo I can use Prnmngr.vbs and

> related tools but they give me too much information. I'm hoping there's

> something simpler that will just confirm if a printer is installed or not.

>
 
WMI script reports it correctly:



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

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _

("SELECT * FROM Win32_Printer")

For Each objPrinter in colInstalledPrinters

Wscript.Echo "Name: " & objPrinter.Name

Select Case objPrinter.PrinterStatus

Case 1

strPrinterStatus = "Other"

Case 2

strPrinterStatus = "Unknown"

Case 3

strPrinterStatus = "Idle"

Case 4

strPrinterStatus = "Printing"

Case 5

strPrinterStatus = "Warmup"

End Select

Wscript.Echo "Printer Status: " & strPrinterStatus

Wscript.Echo

Next



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







Note:

Possible Win32_Printer Class for PrinterStatus are:

(inherited from CIM_Printer)



1 (0x1) Other



2 (0x2) Unknown



3 (0x3) Idle



4 (0x4) Printing



5 (0x5) Warming Up



6 (0x6) Stopped printing



7 (0x7) Offline



(6 & 7 not used in above script)



http://msdn.microsoft.com/en-us/library/aa394363(VS.85).aspx

Win32_Printer Class



John



Ronin wrote:

> I could add it, but it comes up the same: "Unknown". I don't know where

> the disconnect is, but it is.

>

> If you don't need or can't get the printer status, your wmic command is

> ideal, though if you want that limited output you have to add the

> "instance" parameter. Otherwise, the output is voluminous.

>
 
Back
Top