wSHShell Minimized

twdavistwdavis Member Posts: 79
i have a 2 part problem.
I have read thru all of the associated automation posts concerning the Shell and the wSHShell.
I tried all of them in my code.
the wSHShell.exec(text001) works fine and starts the executable. The problem (part 1) is i would like to have it started in the minimized state. Part 2: how can i determine if the exe is already running so that i do not start it again. I tried the clear(wSHshell) but that does not 'kill' the running exe.

Text001 is defined as C:\Program Files\NOVA\viaWARP\Utilities\AutoProcess.exe

create(wSHShell);
wSHExec := wSHShell.Exec(Text001);
clear(wSHShell);

I tried the wSHShell.RUN(Text001,7,FALSE) but i get an error:
"An exception has occurred. Automation server returned error (HRESULT) -2147352567. The component did not provide the exception description.".



i also tried the :

Execute := STRSUBSTNO('start "" /MIN "%1"',Text001);
SHELL(ENVIRON('comspec'),'/c',Execute);

this DID start the exe minimized BUT it naturally opened the window with the message 'You are starting...' that the create(wSHShell) eliminates.

I could use some expert advice.

Comments

  • byllebylle Member Posts: 47
    Hi!

    You should be able to do something like this:
    IF ISCLEAR(WshShell) THEN
      CREATE(WshShell);
    
    WshMode := 7;
    WaitForEndOfCommand := TRUE;
    
    ReturnCode := WshShell.Run(’cmd.exe /c C:\Program Files\NOVA\viaWARP\Utilities\AutoProcess.exe’,WshMode,WaitForEndOfCommand);
    

    WshShell is defined as ‘Windows Script Host Object Model’.WshShell
    WshMode is an integer and is used to handle the Window Style (minimized, maximize etc.). Valid values can be found here.
    The ReturnCode tells you have the execution went.
  • krikikriki Member, Moderator Posts: 9,118
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • twdavistwdavis Member Posts: 79
    Thank you for your replies.

    Here is what i used:
    wSHShell2 is a global var in the codeunit.
    _commandline is a local var in the Function RunApp value: c:\program files\nova\viaWarp\utilities\AutoProcess.exe
    Function RunApp (_commandline,_runModally)
    IF ISCLEAR(wSHShell2) THEN
      CREATE(wSHShell2);
    
    WshMode := 0;
    WaitForEndOfCommand := FALSE;
    Execute := 'cmd.exe /c '+'start "" /MIN "' + _commandline + '"';
    
    ReturnCode := wSHShell2.Run(Execute,WshMode,WaitForEndOfCommand);
    
    IF NOT _runModally THEN
      EXIT(0);
    

    This function is called from within a codeunit that is 'run' from a form.
    I still have the problem with the second time that this codeunit is run from the form, the wSHShell2 variable is 'uninitialized' and a second instance of the executable is started.

    it just dawned on me that the variables in the codeunit automatically get cleared before and after the code unit is run.

    Is there a way to read the "Task Manager" from Navision to determine if a process is already running?
    OR
    Is there a way to 'kill' a process started via the above function?

    Thanks for your help.
  • krikikriki Member, Moderator Posts: 9,118
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • byllebylle Member Posts: 47
  • twdavistwdavis Member Posts: 79
    That worked perfectly.

    Thanks for the replies.
Sign In or Register to comment.