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<>""
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer"
For Each objPrinter in colInstalledPrinters
strmsg = strmsg + objprinter.name + " / " + objprinter.sharename + vbcrlf
Next
wscript.echo strmsg
---- script code 2------
---- this one adds/deletes/lists printers -----
set g_oshell = createobject("wscript.shell"
adminname = g_oshell.environment("Process"
.item("USERNAME"
box=""
serv=""
printshare=""
act=""
function Runcmd(sCmd)
dim sShell, sOS
sOS = g_oShell.environment("Process"
.Item("OS"
sShell = g_oShell.environment("Process"
.Item("Comspec"
if sshell = "" Then
wscript.echo "No COMSPEC environment variable defined. Quitting."
wscript.quit (0)
end if
if sOS = "Windows_NT" Then
sshell = "cmd"
runcmd = g_oshell.run(sshell & " /c" & scmd, &H20000000, True)
end if
end function
do
act = inputbox("Enter the Action (add, adddef, del, list) desired", "Action"
loop until act <> ""
do
box=inputbox("Please enter the client name.", "Client"
loop until box<>""
if act <> "list" then
do
serv=inputbox("Enter the server where the printer resides", "Server"
loop until serv<>""
do
printshare = inputbox("Enter the SHARENAME (not NT name) of the printer", "Printer"
loop until printshare <> ""
end if
select case act
case "show"
'show
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /n \\" & serv & "\" & printshare & " /p"
case "list"
'list
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ge"
case "add"
'add
'nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /in /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ga /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ge"
case "adddef"
'adddef
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ga /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /y /n '" & printshare & "'"
case "del"
'delete
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /gd /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
'nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /dn /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ge"
end select
Rob Mills
System Analyst
Correctional Services Canada
(all statements are my own ...., ah hell, its the government, sue'em anyway)
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<>""
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer"
For Each objPrinter in colInstalledPrinters
strmsg = strmsg + objprinter.name + " / " + objprinter.sharename + vbcrlf
Next
wscript.echo strmsg
---- script code 2------
---- this one adds/deletes/lists printers -----
set g_oshell = createobject("wscript.shell"
adminname = g_oshell.environment("Process"
box=""
serv=""
printshare=""
act=""
function Runcmd(sCmd)
dim sShell, sOS
sOS = g_oShell.environment("Process"
sShell = g_oShell.environment("Process"
if sshell = "" Then
wscript.echo "No COMSPEC environment variable defined. Quitting."
wscript.quit (0)
end if
if sOS = "Windows_NT" Then
sshell = "cmd"
runcmd = g_oshell.run(sshell & " /c" & scmd, &H20000000, True)
end if
end function
do
act = inputbox("Enter the Action (add, adddef, del, list) desired", "Action"
loop until act <> ""
do
box=inputbox("Please enter the client name.", "Client"
loop until box<>""
if act <> "list" then
do
serv=inputbox("Enter the server where the printer resides", "Server"
loop until serv<>""
do
printshare = inputbox("Enter the SHARENAME (not NT name) of the printer", "Printer"
loop until printshare <> ""
end if
select case act
case "show"
'show
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /n \\" & serv & "\" & printshare & " /p"
case "list"
'list
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ge"
case "add"
'add
'nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /in /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ga /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ge"
case "adddef"
'adddef
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ga /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /y /n '" & printshare & "'"
case "del"
'delete
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /gd /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
'nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /dn /n \\" & serv & "\" & printshare & " /b '" & printshare & "'"
nextit=runcmd("rundll32 printui.dll,PrintUIEntry /c \\" & box & " /ge"
end select
Rob Mills
System Analyst
Correctional Services Canada
(all statements are my own ...., ah hell, its the government, sue'em anyway)