A
active
Any idea why this fails with an
OpenPrinter exited with code : 5
Message is: Access is denied.
I have Adminstrative rights
Public Structure PRINTER_DEFAULTS
Dim pDatatype As Integer 'String I"VE TRIED BOTH
Dim pDevMode As Integer
Dim DesiredAccess As Integer
End Structure
....snip
PrinterDefaults.pDatatype = 0
PrinterDefaults.pDevMode = 0
PrinterDefaults.DesiredAccess = PRINTER_ALL_ACCESS
ALSO TRIED PRINTER_ACCESS_ADMINISTER
Flag = OpenPrinter(PrinterName, PrinterHandle, PrinterDefaults)
If Flag = 0 Then
ret = Marshal.GetLastWin32Error()
Console.WriteLine("OpenPrinter exited with code : {0}", ret)
Console.WriteLine("Message is: {0}", UtilityCs.GetErrorMessage(ret))
If ret = ERROR_ACCESS_DENIED Then
MsgBox("Requires Adminstrative rights to change default
printer", _
MsgBoxStyle.Exclamation Or MsgBoxStyle.OKOnly)
End If
Exit Sub
End If
OpenPrinter exited with code : 5
Message is: Access is denied.
I have Adminstrative rights
Public Structure PRINTER_DEFAULTS
Dim pDatatype As Integer 'String I"VE TRIED BOTH
Dim pDevMode As Integer
Dim DesiredAccess As Integer
End Structure
....snip
PrinterDefaults.pDatatype = 0
PrinterDefaults.pDevMode = 0
PrinterDefaults.DesiredAccess = PRINTER_ALL_ACCESS
ALSO TRIED PRINTER_ACCESS_ADMINISTER
Flag = OpenPrinter(PrinterName, PrinterHandle, PrinterDefaults)
If Flag = 0 Then
ret = Marshal.GetLastWin32Error()
Console.WriteLine("OpenPrinter exited with code : {0}", ret)
Console.WriteLine("Message is: {0}", UtilityCs.GetErrorMessage(ret))
If ret = ERROR_ACCESS_DENIED Then
MsgBox("Requires Adminstrative rights to change default
printer", _
MsgBoxStyle.Exclamation Or MsgBoxStyle.OKOnly)
End If
Exit Sub
End If