在本地执行PowerShell GUI,但通过网络发送输出

问题描述 投票:0回答:1

我正在使用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/,但没有运气。

这是GUI代码:

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)例子,我非常怀疑,所以它可以以某种方式终止)

有关如何做到这一点的任何提示?

windows powershell user-interface scripting
1个回答
0
投票

好的,所以这就是我为完成这项工作所做的工作。我创建了服务器端脚本,用于检查2个特定文件的文件夹,一旦看到它们就会将该数据发送到期望监视器编号和URL的主脚本。希望有人觉得这很有用。

您需要从https://alextomin.wordpress.com/2015/04/10/kiosk-mode-in-windows-chrome-on-multiple-displays/下载原始Chrome-Kiosk

服务器脚本

我把它们放在一个名为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
}
© www.soinside.com 2019 - 2024. All rights reserved.