简体   繁体   English

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

[英]cant call powershell GUI script from unc path from a GUI

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 我有一个powershell GUI,它可以启动secound ps1文件(也有一个GUI),并且可以正常工作,并将argu传递给第二个,而在C上没有问题:驱动器im试图将其与UNC路径一起使用\\共享\\服务台\\ sdtools.ps1,但无法打开

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) 我认为这是我封装文件名的方式,但是我尝试了很多方法,但没有运气,它可以将文件作为文本文档打开,所以我设法设法使其调用文件但不在Powershell中运行(我有还尝试了使用Powershell的完整路径,并且该方法不起作用)

as \\share\\service desk\\sdtool.ps1 is the same as g:\\service desk\\sdtool.ps1 i have also tried that with no luck. 因为\\ share \\ service desk \\ sdtool.ps1与g:\\ service desk \\ sdtool.ps1相同,我也尝试过运气不好。

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

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

below is the full ps1 file i am using 以下是我正在使用的完整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() 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM