I have a printer named "Teacher's Lounge Printer
" (note the apostrophe).
When executing the following command at a standard Windows 7 Command Prompt, "Error 0x8004103A Invalid object path
" occurs.
cscript "%WINDIR%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -d -p "Teacher's Lounge Printer"
If I rename the printer to "Teachers Lounge Printer
" (without the apostrophe), the command without the apostrophe will execute successfully.
cscript "%WINDIR%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -d -p "Teachers Lounge Printer"
I feel like I've tried every combination of double-quotes, single-quotes, and I've even attempted escape characters.
Eventually, this will make it into a batch script I'm writing, but I need to get the individual command working properly, first.
I know I'm doing something wrong, and any help is appreciated.
Microsoft's prnmngr.vbs script uses WMI to provide the underlying functionality.
WMI accepts quoted strings using either single '
quotes, or double "
quotes. Unfortunately the developer of prnmngr.vbs chose to use single quotes in two places, which causes problems when the printer name contains single quotes (apostrophe).
I haven't figured out a way to escape the '
in a prnmnger.vbs parameter in a way that WMI will accept. But I have figured out how to hack (debug) the Microsoft prnmngr.vbs code to eliminate the problem.
On my machine, there are two identical offending lines at line numbers 462 and 818.
set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")
The bug can be fixed by switching to using double quotes in the WMI query string. Since the double quote literals are within a VBS quoted string, the quotes must be escaped as ""
.
set oPrinter = oService.Get("Win32_Printer.DeviceID=""" & strPrinter & """")
Rather than modifying the original Microsoft file, you may want to copy the file into a different folder, and make the changes there, and run that hacked version instead of the Microsoft original.
User contributions licensed under CC BY-SA 3.0