rundll32 + printui.dll: Printername as variable?

FragenFragerFragenFrager Member Posts: 56
Hello,
at the moment, I'm trying to change the system printer from NAV by the rundll32 + printui.dll.
Basically, it works. Hovewer, I can't pass the printer name as a variable :-k
Here is the code:
IF ISCLEAR(WShShell) THEN
CREATE(WShShell);

RegKey := 'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device';

gtxDefaultPrinter := WShShell.RegRead(RegKey);
ginPos:=STRPOS(gtxDefaultPrinter,',');
gtxDefaultPrinter:=DELSTR(gtxDefaultPrinter,ginPos);
gtxReportPrinter:=gcuAppM.FindPrinter(50001);
gtxReportPrinter:='"'+gtxReportPrinter+'"';

WShShell.Run('rundll32 printui.dll,PrintUIEntry /y /n%gtxReportPrinter%');
//WShShell.Run('rundll32 printui.dll,PrintUIEntry /y /n"\\minastirith\IBM Infoprint 1532 PS3"');
CLEAR(WShShell);

The command, where I pass the printername \\minastirith\IBM Infoprint 1532PS2 directly works. When I try to run the command with the Printername as Variable %gtxReportPrinter%, I get an errormessage which says that the printername ist incorrect or connection to server is down.
I tried different ways to put the printername together, with quotation marks and without, with one blank after the /n parameter and, finally, with the percent-sign as below.
Anyone an Idea? It won't be a good Idea to hard-code the printername in the programm, I think.

With kind regards

Comments

  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • vaprogvaprog Member Posts: 1,139
    There is no automatic variable substitution in NAV. Please use STRSUBSTNO instead
    WShShell.Run(STRSUBSTNO('rundll32 printui.dll,PrintUIEntry /y /n%1',gtxReportPrinter);
    
    or use + to concatenate the string
    WShShell.Run('rundll32 printui.dll,PrintUIEntry /y /n'+gtxReportPrinter);
    
Sign In or Register to comment.