Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Server enumeration

Status
Not open for further replies.

MillsRJ

Technical User
Sep 14, 2002
28
CA
I have the following code that I run to enumerate printers on a given server, can I incorperate this into a webpage. I wish to select the server in one drop list and have the printers presented in the second droplist for the client to choose.

Then I have a second script that will enable the client to add/delete printers on remote XP boxes. All of our servers are NT4/Win2K, clients are XP Pro running IE6

----- script code 1-----
strComputer = ""
serv = ""
strmsg = "Queue Name / Share Name" + vbcrlf + vbcrlf

do
strcomputer=inputbox("Enter the server where the printer resides", "Server")
loop until strcomputer<>&quot;&quot;

Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colInstalledPrinters = objWMIService.ExecQuery (&quot;Select * from Win32_Printer&quot;)


For Each objPrinter in colInstalledPrinters

strmsg = strmsg + objprinter.name + &quot; / &quot; + objprinter.sharename + vbcrlf
Next

wscript.echo strmsg

---- script code 2------
---- this one adds/deletes/lists printers -----
set g_oshell = createobject(&quot;wscript.shell&quot;)
adminname = g_oshell.environment(&quot;Process&quot;).item(&quot;USERNAME&quot;)

box=&quot;&quot;
serv=&quot;&quot;
printshare=&quot;&quot;
act=&quot;&quot;


function Runcmd(sCmd)
dim sShell, sOS
sOS = g_oShell.environment(&quot;Process&quot;).Item(&quot;OS&quot;)
sShell = g_oShell.environment(&quot;Process&quot;).Item(&quot;Comspec&quot;)
if sshell = &quot;&quot; Then
wscript.echo &quot;No COMSPEC environment variable defined. Quitting.&quot;
wscript.quit (0)
end if
if sOS = &quot;Windows_NT&quot; Then
sshell = &quot;cmd&quot;
runcmd = g_oshell.run(sshell & &quot; /c&quot; & scmd, &H20000000, True)
end if
end function

do
act = inputbox(&quot;Enter the Action (add, adddef, del, list) desired&quot;, &quot;Action&quot;)
loop until act <> &quot;&quot;

do
box=inputbox(&quot;Please enter the client name.&quot;, &quot;Client&quot;)
loop until box<>&quot;&quot;

if act <> &quot;list&quot; then
do
serv=inputbox(&quot;Enter the server where the printer resides&quot;, &quot;Server&quot;)
loop until serv<>&quot;&quot;

do
printshare = inputbox(&quot;Enter the SHARENAME (not NT name) of the printer&quot;, &quot;Printer&quot;)
loop until printshare <> &quot;&quot;
end if


select case act

case &quot;show&quot;
'show
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /n \\&quot; & serv & &quot;\&quot; & printshare & &quot; /p&quot;)

case &quot;list&quot;
'list
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /ge&quot;)

case &quot;add&quot;
'add
'nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /in /n \\&quot; & serv & &quot;\&quot; & printshare & &quot; /b '&quot; & printshare & &quot;'&quot;)
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /ga /n \\&quot; & serv & &quot;\&quot; & printshare & &quot; /b '&quot; & printshare & &quot;'&quot;)
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /ge&quot;)

case &quot;adddef&quot;
'adddef
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /ga /n \\&quot; & serv & &quot;\&quot; & printshare & &quot; /b '&quot; & printshare & &quot;'&quot;)
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /y /n '&quot; & printshare & &quot;'&quot;)

case &quot;del&quot;
'delete
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /gd /n \\&quot; & serv & &quot;\&quot; & printshare & &quot; /b '&quot; & printshare & &quot;'&quot;)
'nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /dn /n \\&quot; & serv & &quot;\&quot; & printshare & &quot; /b '&quot; & printshare & &quot;'&quot;)
nextit=runcmd(&quot;rundll32 printui.dll,PrintUIEntry /c \\&quot; & box & &quot; /ge&quot;)

end select

Rob Mills
System Analyst
Correctional Services Canada
(all statements are my own ...., ah hell, its the government, sue'em anyway)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top