Author Posts

October 27, 2013 at 1:11 pm

Hey Guys!
I have a problem that I'm been working on for about 3 weeks now.

I created a "Launchpad" with some GUI and stuff. It basically give the user a couple of choices and after that it launched a .bat file wich lanches an application.

My problem is that the user cannot quit the launchpad because then the newly started application quits too.
That is because the application becomes an child process(?).

How do I start a new "master" process instead?

This is my code so far (not all of it of course, just the relevant stuff):

$SelectedItemFromList = "Carl"
start-job -scriptblock {cmd /C "set USERNAME=$args" '&&' "C:\MADEUPNAME\run.bat"} -ArgumentList @($SelectedItemFromList )

I have to change the USERNAME verible in CMD before launching the .bat file.
This is the only way so far I managed to launch the program and the user can continue working in the GUI.

Any ideas?

October 27, 2013 at 1:17 pm

btw using powershell 2.0 (if possible I don't want to upgrade... because that means upgrading 150 clients...)

October 27, 2013 at 1:31 pm

Try using Start-Process instead of Start-Job.

October 27, 2013 at 1:43 pm

Allready tried it. Does not work. Can not even get it to launch the .bat file and let the user continue using the gui. Maybe im doing it wrong.
Can you give me an example? Maybe based on my code

Best regards

October 27, 2013 at 3:55 pm

Try this:

Start-Process $env:ComSpec "/C (set USERNAME=$($SelectedItemFromList)) && ""C:\MADEUPNAME\run.bat"""

Edit: Changed /K to /C (was that way from testing), and put parentheses around the SET command to avoid trailing whitespace in the environment variable.

October 28, 2013 at 1:08 am

Worked like a charm! Thank you!