Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start-Process from array value with arguments

Status
Not open for further replies.

AcumenP

Technical User
Sep 25, 2009
5
NL
Hi All,

As a newbie on Powershell I thought lets create a handy script, haha. So I created a small script that checks if a crypt container is already mounted and if so, it will start some apps I stored in an array.

So far so good, however... Now I have SugarSync and I want to start it into the tray instead of full screen. This can be done by adding the argument "-startinTray". How hard can it be ?

Well... Too hard for me right now. I could use some help of the Tek Guru's :)

So this is the script:
--------------------------------------------

$RunCheck = "c:\debug.txt"
$PostRun = "C:\path1\application.exe", "C:\'Program Files'\SugarSync\SugarSyncManager.exe -startinTray"

function RunApp([array]$Apps2Start)
{
foreach ($App in $Apps2Start)
{
$AppProc = $App.substring($App.lastindexOf("\")+1,$App.lastindexOf(".")-$App.lastindexOf("\")-1)
if((get-process $AppProc -ea SilentlyContinue) -eq $Null)
{
echo "Starting: $App" >> $RunCheck
if ($App.substring($App.lastindexOf(".")) -eq ".ps1")
{
& $App
}
else
{
Start-Process $App
}
}
}
}

if ($PostRun)
{
RunApp($PostRun)
}
[/color red]
--------------------------------------------

So it checks if the app is already running by stripping off the file path and file extension and if no process is found, it will start the app. The echo is there to generate some easy debug output and it tells me that the app should be started.

Despite the echo that tells me the app starts, it is not. When I remove the argument, it does however start.
As you can see I want to keep it as simple as possible so others can use it to and without my help.

Now I hope that somebody has a suggestion that kicks me in the right direction :)

Thanks Acumen





 
I haven't tried this myself, but looking at the help the following seems to be the issue. Start-Process expects the program to run (the -FilePath parameter) to be just the program and nothing else. There is a separate parameter to Start-Process, -ArgumentList, which can be used to pass parameters to the process you're trying to start. You might want to try Invoke-Expression instead:
Code:
else
{
    Invoke-Expression $app
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top