Shell without confirmation-request of Navision 4.00

krikikriki Member, Moderator Posts: 9,112
edited 2014-03-12 in NAV Tips & Tricks
This function can be used instead of the SHELL-command that triggers the confirmation-request of Navision 4.00.
One remark:if you put "IblnWaitForEndOfCommand" to TRUE, the Navision-code waits for a return-value, but very strange is that it does NOT block the userinterface!

Local Variables:
Name	DataType	Subtype	Length
Laut	Automation	'Windows Script Host Object Model'.WshShell	
Lint	Integer

The function:
DosShell(ItxtCommand : Text[1024];IintWindowStyle : Integer;IblnWaitForEndOfCommand : Boolean) OintReturnValue : Integer
// DosShell //*** 109
// Works like SHELL and HYPERLINK of Navision but without the annoying confirmation-request of Navision 4.00
//   (this function uses automation 'Windows Script Host Object Model'.WshShell)
// PARAMETERS:
//   ItxtCommand : command + parameters for the SHELL
//   IintWindowStyle : Type of window for command
//     0:Hides the window and activates another window. (=Doesn't even show a window, to kill the doscommand,
//             you have to do it with taskmanager=>Processes)
//     1:Activates and displays a window. If the window is minimized or maximized, the system restores
//       it to its original size and position. An application should specify this flag when displaying
//       the window for the first time. (=shows the window as normal window)
//     2:Activates the window and displays it as a minimized window. (=shows as minimized)
//     3:Activates the window and displays it as a maximized window. (=shows as maximized)
//     4:Displays a window in its most recent size and position. The active window remains active.
//     5:Activates the window and displays it in its current size and position.
//     6:Minimizes the specified window and activates the next top-level window in the Z order.
//     7:Displays the window as a minimized window. The active window remains active.
//     8:Displays the window in its current state. The active window remains active.
//     9:Activates and displays the window. If the window is minimized or maximized, the system
//       restores it to its original size and position. An application should specify this flag
//       when restoring a minimized window.
//     10:Sets the show-state based on the state of the program that started the application.
//   IblnWaitForEndOfCommand : TRUE : wait for the command to finish (and use the RETURN-VALUE)
//                             FALSE: Launch the command and return (RETURN-VALUE will be 0)
//   RETURN-VALUE : SHELL-command RETURN-VALUE

CREATE(Laut);
OintReturnValue := Laut.Run(ItxtCommand,IintWindowStyle,IblnWaitForEndOfCommand);
CLEAR(Laut);
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Comments

  • garakgarak Member Posts: 3,263
    Nice, but When you need the result you can use execute
    ...
    WSHExec := WSHShell.Exec(Command);
    WSHTextStream := WSHExec.StdOut;
    
    WHILE NOT WSHTextStream.AtEndOfStream DO BEGIN
      message(WSHTextStream.ReadLine());
    END;
    

    Regards
    Do you make it right, it works too!
  • MiniMini Member Posts: 17
    Hi Kriki,

    Can you please let me know from where I will call this function?

    Regards
    Mini
  • garakgarak Member Posts: 3,263
    Hi Mini,

    you can call this from every where in Navision. But this function is not a Navision function, it's customized.

    So, you must create this "example function" self. Also you need the "Windows Scription Host" as Variable (if you need more infos about these theme, search the forum for Windows Scripting Host or WSH)
    To understand this example, create, only for this example, a blank form with a button.
    In the form you create the Kriki's function with the needed WSH variable. From your button you call the function like
    RetournValueAsInteger := DosShell('notepad.exe',1,true);
    


    Now, Notepad is opend (as example)

    Regards
    Do you make it right, it works too!
  • dsatriadsatria Member Posts: 80
    It doesn't seem to work if the executable is located on folder with spaces on its name, such "C:\Documents and Settings\me\program.exe"
    Any ideas, please?
  • mdPartnerNLmdPartnerNL Member Posts: 802
    In the dos-prompt you can find the short names with "dir /x", maybe that will work?
  • krikikriki Member, Moderator Posts: 9,112
    try this : dosshell('"C:\Documents and Settings\me\program.exe"');
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DoomhammerDoomhammer Member Posts: 211
    hello, I have problem with windows scripting host

    I am trying to send some text file with label to printer connected via USB port (USB is mapped to LPT 1 in windows)

    I am using this code:
    IF ISCLEAR(autWinScriptHost) THEN
    CREATE(autWinScriptHost);

    txtCommand := 'copy /B ' + txtFilename+ ' LPT1';
    autWinScriptHost.Run(txtCommand);

    where txtfilename is d:\Navision\ProTeam\geis\PDL1208283.txt

    attached error appears

    there are no spaces in file path.
    Please, can you tell me, what can be wrong? Thanks in advance.
    Martin Bokůvka, AxiomProvis
  • krikikriki Member, Moderator Posts: 9,112
    Does it work when you run it directly from DOS?

    Which version of NAV are you using?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DoomhammerDoomhammer Member Posts: 211
    NAV 2009 R2, classic

    from commandline it works (I copied value of txtcommand from debugger and inserted it to commandline)
    Martin Bokůvka, AxiomProvis
  • krikikriki Member, Moderator Posts: 9,112
    Found it:

    Copy is not an executable but is part of the cmd.exe. So you need to run that for copying the file:
    "cmd.exe /C copy ...."
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DoomhammerDoomhammer Member Posts: 211
    Awesome, that worked like a charm.

    Thank you very much.
    Martin Bokůvka, AxiomProvis
  • rkaufmannrkaufmann Member Posts: 71
    Hi, I know the topic is quite old, but I have an answer.
    I use this to do ftp transfers with an ftp commandline tool. works pretty good.
    I use the "IblnWaitForEndOfCommand = true" Option. And mostly the returnvalue is 0, which is OK.
    But sometimes I get "3" as returnvalue, and I don't know what that means, and I can not find information about the different returnvalues
Sign In or Register to comment.