1

I have a powershell GUI that launches a secound ps1 file (a GUI as well) it works fine and passes the argu on to the second one without a problem when its on the C: drive im trying to use it with a UNC path of \share\service desk\sdtools.ps1 but it does not open

The below works

Function login {

$sdnum = $numInputBox.text

Start-Process "powershell.exe" -windowstyle hidden -ArgumentList "-File C:\servicedesk\sdtool.ps1 -a $sdnum"

#Close login-form so the first script will finish.
$form.Close()

}

The below never launches the second file

Function login {

$sdnum = $numInputBox.text

Start-Process "powershell.exe" -windowstyle hidden -ArgumentList "-File \\share\service desk\sdtool.ps1 -a $sdnum"

#Close login-form so the first script will finish.
$form.Close()

}

i think it is how i have encapsulated the file name but i have tried many ways and none with luck it can open the file as a text document so i do manage to get it to call the file but not to run in powershell(i have also tried it with the full path to powershell and that dosnt work)

as \share\service desk\sdtool.ps1 is the same as g:\service desk\sdtool.ps1 i have also tried that with no luck.

2 Answers 2

2

You have a space in the path, so you need to encapsulate it in quotes:

Start-Process "powershell.exe" -NoNewWindow -ArgumentList "-File `"\\share\service desk\sdtool.ps1`" -a $sdnum"
Sign up to request clarification or add additional context in comments.

8 Comments

Hi your first way give me "the string is missing a terminator: '. and the second still dosnt open the file.
ah it does call the gui if i remove -windowstyle hidden but i need to hide the background command window when it runs if i put it back in it dosnt open But it dosnt pass the argument to the second scrypt
Yes, that -windowstyle hidden parameter doesn't like GUIs, I also have the same problem when testing.
OK, maybe a solution. I used the -NoNewWindow switch
top man now working (the argument didnt pass as i had typed wrong name) so now its working as should thank you :)
|
0

below is the full ps1 file i am using

Add-Type -AssemblyName System.Windows.Forms
$form = New-Object Windows.Forms.Form
$form.Size = New-Object Drawing.Size @(230,75)
$form.StartPosition = "CenterScreen"
$Form.Text = "Please Login"
$Label = New-Object System.Windows.Forms.Label
$Label.Location = New-Object System.Drawing.Size(5,5) 
$Label.Size = New-Object System.Drawing.Size(55,20) 
$Label.Text = "Staff no:"
$Form.Controls.Add($Label) 
$numInputBox = New-Object System.Windows.Forms.TextBox
$numInputBox.Location = New-Object System.Drawing.Size(60,5) 
$numInputBox.Size = New-Object System.Drawing.Size(50,26) 
$numInputBox.text = ""
$numInputBox.add_Keydown({if ($_.KeyCode -eq "Enter") 
{login}})
$form.Controls.Add($numInputBox)

Function login {

$sdnum = $numInputBox.text

#Start-Process "powershell.exe" -WindowStyle Hidden -ArgumentList "-File ‘”\\share\Service              Desk\sdtool.ps1`" -a $sdnum"
Start-Process "powershell.exe" -ArgumentList "-File `"\\share\Service Desk\sdtool.ps1`" -a         $sdnum"
$Form.Close()

}

$loginbutton = New-Object System.Windows.Forms.Button
$loginbutton.Size = New-Object System.Drawing.Size(75,21)
$loginbutton.Location = New-Object System.Drawing.Size(115,4)
$loginbutton.add_click({login})
$loginbutton.Text = "Login"
$form.Controls.Add($loginbutton)
$drc = $form.ShowDialog() 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.