windows - 在本地执行 PowerShell GUI,但通过网络发送输出
问题描述
我正在使用来自https://github.com/alex-tomin/Tomin.Tools.KioskMode的优秀 Chrome-Kiosk 脚本,它运行良好。我在工作中为我们的显示板修改了它,我们在 11 个屏幕上完美地使用它。
我想修改它来制作一个单屏启动器,所以我可以打开一个小 GUI 框,输入要显示的 URL,然后输入它应该显示的屏幕编号。我创建了一个小脚本,它可以在我的本地机器上完美运行。我要做的是在我的屏幕上打开 GUI,然后通过网络将这两个变量发送到网络上的显示 PC。我曾希望我能够通过远程执行来做到这一点,如下所示:https ://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/ ,但没有运气.
这是图形用户界面代码:
function button ($title,$mailbx, $WF, $TF) {
[void][System.Reflection.Assembly]::LoadWithPartialName( "System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.VisualBasic")
$form = New-Object "System.Windows.Forms.Form";
$form.Width = 500;
$form.Height = 150;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
$textLabel1 = New-Object "System.Windows.Forms.Label";
$textLabel1.Left = 25;
$textLabel1.Top = 15;
$textLabel1.Text = $mailbx;
$textLabel2 = New-Object "System.Windows.Forms.Label";
$textLabel2.Left = 25;
$textLabel2.Top = 50;
$textLabel2.Text = $WF;
$textBox1 = New-Object "System.Windows.Forms.TextBox";
$textBox1.Left = 150;
$textBox1.Top = 10;
$textBox1.width = 200;
$textBox2 = New-Object "System.Windows.Forms.TextBox";
$textBox2.Left = 150;
$textBox2.Top = 50;
$textBox2.width = 200;
$defaultValue = ""
$textBox1.Text = $defaultValue;
$textBox2.Text = $defaultValue;
$button = New-Object "System.Windows.Forms.Button";
$button.Left = 360;
$button.Top = 85;
$button.Width = 100;
$button.Text = "Ok";
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$textBox2.Text;
$form.Close();
};
$button.Add_Click($eventHandler) ;
# Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textLabel2);
$form.Controls.Add($textLabel3);
$form.Controls.Add($textBox1);
$form.Controls.Add($textBox2);
$form.Controls.Add($textBox3);
$ret = $form.ShowDialog();
return $textBox1.Text, $textBox2.Text#, $textBox3.Text
}
$return= button "Monitoring Screen Selector" "Enter URL" "Enter Screen # from 1 to 11" #"Target Folder"
$return[0]
$return[1]
脚本的第一部分是 GUI,它传递$return[0]
并$return[1]
进入脚本的第二部分,如下所示:
$chromePath = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
$chromeArguments = '--new-window'
# if Window not moved (especially on machine start) - try increasing the delay.
$ChromeStartDelay = 3
Set-Location $PSScriptRoot
. .\HelperFunctions.ps1
# Kill all running instances
# &taskkill /im chrome* /F
Chrome-Kiosk $return[0] -MonitorNum $return[1]
所以 GUI 应该在本地 PC 上打开,然后发送并发$return[0]
送到$return[1]
插入所有显示器的计算机,以便脚本的第二部分可以接收来自 GUI 的这两个输入,然后激活屏幕和 URL。
这个想法是在我们的正常屏幕未覆盖的事件或事件期间,我们可以将网页扔到那里直到它被解决,然后手动关闭它(除非有人知道如何捕获特定 Chrome 的 PID例如,我非常怀疑,所以它可以以某种方式终止)
关于我如何做到这一点的任何提示?
解决方案
好的,这就是我为完成这项工作所做的工作。我创建了服务器端脚本来检查文件夹中的 2 个特定文件,一旦看到它们,它就会将该数据发送到需要监视器编号和 URL 的主脚本。希望有人觉得这很有用。
服务器脚本
我已将它们放入名为 c:\scripts\ICVT 的文件夹中
looper.PS1 - 这将不断运行
Set-Location -Path C:\scripts\ICVT
while ($true) {
.\file_checker.ps1;
}
file_checker.PS1 - 这是 looper 运行的脚本。file_checker 扫描文件夹中的 web.txt 和 mon.txt 。两者都必须存在,脚本的其余部分才能执行。
#Checks folder for web.txt and mon.txt . Both must be present for the rest of the
script to execute
Set-Location -Path C:\scripts\ICVT
$a = Test-Path web.txt
$b = Test-Path mon.txt
IF (($a -and $b -eq $True)) {
.\launcher.ps1
}
else {
Write-Host "Scanning For Files"
}
Start-Sleep -Seconds 5
launcher.PS1 - 这只是原始脚本的修改版本
$chromePath = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
$chromeArguments = '--new-window'
$web = (Get-Content -Path web.txt)
$mon = (Get-Content -Path mon.txt)
# if Window not moved (especially on machine start) - try increasing the delay.
$ChromeStartDelay = 5
Set-Location $PSScriptRoot
. .\HelperFunctions.ps1
Chrome-Kiosk $web -MonitorNum $mon
#Delete parameters after use
Start-Sleep -Seconds 5
del web.txt
del mon.txt
客户端
menu.PS1 - 如果您想通过网络将特定屏幕推送到显示计算机,则设置网络路径,但如果您连接到本地 PC,则本地路径是要设置的。只要 looper 能够看到该文件夹,它就可以工作。菜单中有一些逻辑,因此如果您关闭窗口而不输入任何细节,脚本将不会执行。(如果您在没有参数的情况下运行启动器,它仍会执行 chrome 并将其发送到数组之外的屏幕,由于某种原因,该屏幕通常为 2 号)
#################Local Path###################
Set-Location -Path c:\scripts\ICVT
#################Network Path#################
#Set-Location -Path \\somecomputer\c$\scripts\ICVT
function button ($title,$mailbx, $WF, $TF) {
###################Load Assembly for creating form & button######
[void][System.Reflection.Assembly]::LoadWithPartialName( “System.Windows.Forms”)
[void][System.Reflection.Assembly]::LoadWithPartialName( “Microsoft.VisualBasic”)
#####Define the form size & placement
$form = New-Object “System.Windows.Forms.Form”;
$form.Width = 500;
$form.Height = 150;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
##############Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Left = 25;
$textLabel1.Top = 15;
$textLabel1.Text = $mailbx;
##############Define text label2
$textLabel2 = New-Object “System.Windows.Forms.Label”;
$textLabel2.Left = 25;
$textLabel2.Top = 50;
$textLabel2.Text = $WF;
##############Define text label3
#$textLabel3 = New-Object “System.Windows.Forms.Label”;
#$textLabel3.Left = 25;
#$textLabel3.Top = 85;
#$textLabel3.Text = $TF;
############Define text box1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 150;
$textBox1.Top = 10;
$textBox1.width = 200;
############Define text box2 for input
$textBox2 = New-Object “System.Windows.Forms.TextBox”;
$textBox2.Left = 150;
$textBox2.Top = 50;
$textBox2.width = 200;
############Define text box3 for input
#$textBox3 = New-Object “System.Windows.Forms.TextBox”;
#$textBox3.Left = 150;
#$textBox3.Top = 90;
#$textBox3.width = 200;
#############Define default values for the input boxes
$defaultValue = “”
$textBox1.Text = $defaultValue;
$textBox2.Text = $defaultValue;
#$textBox3.Text = $defaultValue;
#############define OK button
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 360;
$button.Top = 85;
$button.Width = 100;
$button.Text = “Ok”;
############# This is when you have to close the form after getting values
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$textBox2.Text;
#$textBox3.Text;
$form.Close();};
$button.Add_Click($eventHandler) ;
#############Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textLabel2);
$form.Controls.Add($textLabel3);
$form.Controls.Add($textBox1);
$form.Controls.Add($textBox2);
$form.Controls.Add($textBox3);
$ret = $form.ShowDialog();
#################return values
return $textBox1.Text, $textBox2.Text#, $textBox3.Text
}
$return= button “Monitoring Screen Selector” “Enter URL” “Enter Screen # from 1 to 11” #“Target Folder”
if ($return[0] -ne "") {
$return[0] > web.txt
}
if ($return[0] -eq "") {
exit
}
if ($return[1] -ne "") {
$return[1] > mon.txt
}
if ($return[0] -eq "") {
exit
}
推荐阅读
- airflow - gcloud composer command fails "executable file not found in $PATH"
- ios - 能够在 IOS 中使用的转换器条带
- javascript - How can I call a variable outside the widget
- python - find peaks and envelope question in python
- reactjs - 将路线直接反应到同一路线不更新
- css - 更改面包屑颜色 bootstrap-vue
- javascript - 结合两个 onEdits
- gitlab - 为什么我无法在 GitLab 中接受合并请求?
- python - Sklearn.metrics.classification_report 混淆矩阵问题?
- blogdown - 发布后可以更改帖子的日期吗?