$theTitle=wp_title(" - ", false); if($theTitle != "") { ?>
About Virtualization, VDI, SBC, Application Compatibility and anything else I feel like
A few days ago I wrote about a PowerShell Script to Install Printer Drivers.
I noticed there was a problem with this script: some drivers fail to load with error 1797 which means ERROR_UNKNOWN_PRINTER_DRIVER.
I reread the AddPrinterConnection documentation on MSDN but it didn’t mention anything about additional required permissions or anything.
But then I read the remarks sections of the Win32_Printer Class and it mentions that for some operations the SeLoadDriverPrivilege is required.
In VBScript we can indicate it like this:
1 2 3 | Set objPrinter = GetObject( _ "winmgmts:{impersonationLevel=Impersonate ," _ & "(LoadDriver)}!//./root/cimv2:Win32_Printer") |
But how to do this in PowerShell?
I didn’t find a way to enable a specific privilege but we can enable all by setting Scope.Options.EnablePrivileges to $true.
So I modified the script like this:
1 | powershell.exe "& { $Wmi = ([wmiclass]'Win32_Printer') ; $Wmi.Scope.Options.EnablePrivileges = $true; gwmi win32_printer -ComputerName 'ADNRD02' -Filter 'shared=true' | foreach {$Wmi.AddPrinterConnection( [string]::Concat('\\', $_.__SERVER, '\', $_.ShareName) )} }" |
3 Responses for "Enabling Privileges for WMI in PowerShell"
[…] load new driver we need to enable the SeLoadDriverPrivilege. I have corrected the code above, see Enabling Privileges for WMI in PowerShell for an explanation. VN:F [1.9.7_1111]please wait…Rating: 0.0/10 (0 votes cast)VN:F […]
[…] Dit blogartikel was vermeld op Twitter door Remko Weijnen, Remko Weijnen. Remko Weijnen heeft gezegd: Blogged: Enabling Privileges for #WMI in #PowerShell http://bit.ly/fwTyG1 […]
Hi,
Tnx for this script. It;s working fine for most of my printers, but some don’t install but end with
ReturnValue 3019.
I’ve tried to find it, but can’t figure out what goes wrong. Maybe you can help me out? Tnx!
Leave a reply