gooly
gooly

Reputation: 1341

How to keep the window open: ShellExecuteW(0,0,"powershell.exe", "..","..",SW_SHOW)?


from another program (metatrader) I start a ps-script to download some emails:

 shl = ShellExecuteW(0,0,"powershell.exe", "-file x.ps1","..\\path\\to\\scripts",SW_SHOW);

After a couple of weeks without any problem(!) I saw all of a sudden some red error code in the console - but it was closed too fast the return code (shl) signals no error: shl <=32.

Now I tried to start ShellExecuteW(..) with

  shl = ShellExecuteW(0,0,"powershell.exe","..","..",SW_SHOWNOACTIVATE);
  # SW_SHOWNOACTIVATE = 4 
  # 4: Displays a window in its most recent size and position. The active window remains active.

But again the console disappears :(

1) What do I have to enter so that the console stays open - for me to close 1t manually?
2) How do I force ShellExecuteW(..) to add the error-messages to an error file?

Thanks and a nice weekend,
Gooly

PS: After I re-started the program with ShellExecuteW(..) it runs again without any error?

Upvotes: 1

Views: 4995

Answers (2)

Paul
Paul

Reputation: 5861

Just for the record, You could have kept it open by adding read-host at the end of your Script.

You can Log error messages by using transcripts (start-transcript / stop-transcript) or just add error handling to your Script (try catch then log manually).

Regards

Upvotes: 1

Micky Balladelli
Micky Balladelli

Reputation: 9991

I think the problem is not ShellExecute, but how Powershell is invoked.

Try this:

shl = ShellExecuteW(0,0,"powershell.exe", "-noexit -file x.ps1","..\\path\\to\\scripts",SW_SHOW);

Upvotes: 2

Related Questions