无法从GUI的unc路径调用powershell GUI脚本

时间:2015-01-03 17:29:49

标签: powershell unc

我有一个powershell GUI,可以启动一个有限的ps1文件(也是一个GUI),它工作正常,并且当它在C:驱动器上时,将争论传递给第二个没有问题 我试图使用UNC路径\ share \ service desk \ sdtools.ps1 但它没有打开

以下作品

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()

}

以下内容从不启动第二个文件

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()

}

我认为这是我如何封装文件名但我已经尝试了很多方法,没有运气它可以打开文件作为文本文件,所以我设法让它来调用文件,但不是在PowerShell中运行(我也尝试过使用powershell和dosnt工作的完整路径)

as \ share \ service desk \ sdtool.ps1与g:\ service desk \ sdtool.ps1相同我也尝试过没有运气。

2 个答案:

答案 0 :(得分:2)

路径中有空格,因此需要将其封装在引号中:

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

答案 1 :(得分:0)

下面的

是我正在使用的完整ps1文件

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()