I'm working on a windows 2003 server. I am using an administrator account. I
am trying to create a printer queue using the win32_printer object. I get
the following error message:
C:\usr\akbp\bin\prnt_wmi.vbs(200, 10) SWbemObjectEx: Access denied
That line is the line "this_printer.Put_"
This is extremely annoying. I would appreciate any suggestions
The code is shown below.
greetings,
'*
'* some definitions
'*
prnServer = "." '* This print server
Set prnWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & prnServer & "\root\cimv2")
'
'* this function
'
function create_printer(pr_name, pr_driver, port_name, pr_description,
pr_location, pr_sharename)
dim this_printer, prn_item
dim this_exists
this_exists = false
create_printer = false
if driver_present(pr_driver) then
Set this_printer = prnWMI.ExecQuery _
("Select * From Win32_Printer Where DeviceID = '" & pr_name & "'
")
for each prn_item in this_printer
this_exists = true
next
this_printer = null
if this_exists then
wscript.echo " " & pr_name & " exists"
else
set this_printer = prnWMI.Get("Win32_Printer").SpawnInstance_
this_printer.DeviceID = pr_name
this_printer.DriverName = pr_driver
this_printer.PortName = port_name
this_printer.Comment = pr_description
this_printer.Location = pr_location
this_printer.Network = true
this_printer.Hidden = false
this_printer.Shared = true
this_printer.ShareName = pr_sharename
this_printer.Put_ '**** this is line 200
if 0 <> Err.number then
wscript.echo "Add printer failed for " & pr_name
else
wscript.echo pr_name & "OK"
create_printer = true
end if
end if
else
unknown_driver pr_driver, pr_name
'wscript.echo "Driver not present: " & pr_driver
end if
end function