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

Re: win32_printer gives access denied on Put_ by Michael

Michael
Tue May 03 19:06:01 CDT 2005

Tarjei T. Jensen wrote:
> 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



Request the SeLoadDriverPrivilege in your GrtObject call...

Win32_Printer class [WMI]
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_printer.asp?frame=true

<quote>

Remarks

The Win32_Printer class is derived from CIM_Printer. Before calling
SWbemObject.Put_ or IWbemServices::PutInstance for a Win32_Printer instance,
the SeLoadDriverPrivilege privilege (wbemPrivilegeLoadDriver for Visual
Basic and LoadDriver for scripting monikers) must be enabled. For more
information, see Windows NT/Windows 2000 Privilege Strings and Executing
Privileged Operations. The following VBScript example shows how to enable
the SeLoadDriverPrivilege privilege in script.

Set objPrinter = GetObject( _
"winmgmts:{impersonationLevel=Impersonate ," _
& "(LoadDriver)}!//./root/cimv2:Win32_Printer")

</quote>


--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.




Re: win32_printer gives access denied on Put_ by Tarjei

Tarjei
Wed May 04 01:43:25 CDT 2005

Michael Harris (MVP) wrote:
> Request the SeLoadDriverPrivilege in your GrtObject call...
>
> Win32_Printer class [WMI]
>
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_printer.asp?frame=true
>
> <quote>

Spot on!

BTW I found an alternate way of doing this on the web. I didn't realize at
the time that this privilege was needed to create printers. The code is
slightly modified below.

prnWMI.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

Thankful greetings,





Re: win32_printer gives access denied on Put_ by Gawain

Gawain
Fri May 20 00:46:22 CDT 2005

Hi Tarjei,
I am trying to do the same thing but am getting stuck on a few areas..any
chance I could have a look at your script?
Cheers,
Gawain :)

"Tarjei T. Jensen" <tarjei@online.no> wrote in message
news:427860fd$1@news.wineasy.se...
> Michael Harris (MVP) wrote:
>> Request the SeLoadDriverPrivilege in your GrtObject call...
>>
>> Win32_Printer class [WMI]
>>
> http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_printer.asp?frame=true
>>
>> <quote>
>
> Spot on!
>
> BTW I found an alternate way of doing this on the web. I didn't realize at
> the time that this privilege was needed to create printers. The code is
> slightly modified below.
>
> prnWMI.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
>
> Thankful greetings,
>
>
>
>