Powershell显示UI设置变量

时间:2016-02-29 02:05:09

标签: windows powershell batch-file

您好我正在尝试为我运行的最常见程序制作一个小GUI菜单。我有批处理菜单,但我想使用ShowUI模块(Show UI Homepage)制作PowerShell GUI版本

菜单运行良好它加载所有程序作为提升用户按预期,什么是无效的我有我的批处理菜单的第二部分,它让我设置一个PC名称变量,它允许我运行远程程序。 (I.E. Ping /测试连接,任务列表/获取进程,交互式cmd.exe)

事实证明这很困难,Show UI网站上没有太多文档。我已经点击了一个GUI按钮,它会弹出一个窗口来填充变量,但它永远不会更改变量。 (当我手动运行该命令时,它确实有效)

到目前为止,这是我的脚本:(编辑了一些程序,因为我可能会遇到麻烦而显示它们)

Import-Module ShowUI
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$wshell = New-Object -ComObject Wscript.Shell
$pcname = "127.0.0.1"
$getEventInput = UniformGrid -ControlName 'Nats Menu' -Columns 2 -Rows 15 {


       New-Label -VisualStyle 'MediumText' "Nattys Menu"
       new-label " "
            New-Button "SCCM Console" -On_Click { invoke-Item "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.exe" }
            New-Button "SCCM CCC" -On_Click { invoke-Item "C:\Program Files\Client Center for Configuration Manager\SCCMCliCtrWPF.exe" }
            New-Button "Removed Program"
            New-Button "GPeditor" -On_Click { invoke-Item "gpmc.msc" }
            New-Button "Active Directory" -On_Click { invoke-Item "dsa.msc" }
            New-Button "Powershell ISE x86" -On_Click { invoke-Item "C:\WINDOWS\sysWOW64\WindowsPowerShell\v1.0\PowerShell_ISE.exe" }
            New-Button "Powershell" -On_Click { invoke-Item "C:\WINDOWS\sysWOW64\WindowsPowerShell\v1.0\powershell.exe" }
            New-Button "Command Prompt" -On_Click { invoke-Item "cmd.exe" } 
        new-label " "
        new-label " "
            New-Button "Set New PCName" -On_Click {$pcname = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a computer name", "Computer") }
            New-Button -VisualStyle 'MediumText' "Show PC Name" -On_Click {$wshell.Popup("$PCName")}
            New-Button "Ping PC" -On_Click {Test-Connection $PCName -Count 5 |Out-GridView}


} -show 

不知道是否需要,但这是我制作的批处理菜单:

ECHO OFF
set pcname=127.0.0.1
set sysint=c:\TEMP\Sysinternals
set menutemp=c:\temp

pause 
:START
CLS
ECHO.
ECHO.
ECHO ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
ECHO º                             ***Nats Menu***                                 º
ECHO ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
ECHO º (1) Start SCCM Console                        (X) Run Startup Apps          º
ECHO º (2) Start SCCM CCC                                                          º
ECHO º (3) Start SCCM DMT                                                          º
ECHO º (4) Start GPeditor                                                          º
ECHO º (5) Start Active Directory                    (DSM) Open DSM Sessions       º
ECHO º (6) Start Powershell ISE x86                  (G) PS Get-Proc on Remote PC  º
ECHO º (7) Start Powershell                         (T) Task List on Remote PC    º
ECHO º (8) Start Command Prompt                      (P) PS Test-Conn remote PC    º
ECHO º                                               (O) PING Remote PC            º
ECHO º                                               (I) Open CMD on Remote PC     º
ECHO º                                               (C) Open C$ on Remote PC      º
ECHO º                                               (R) SCCM RC to Remote PC      º
ECHO º                                               (D) RDP to Remote PC          º
ECHO º                                               (A) Set Remote PC Name        º
ECHO ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ECHO          Running as: %username%                    Remote PC: %PCNAME%
echo.
echo.

SET /P M=Make Selection then press ENTER:
IF %M%==1 GOTO SCCMCON
IF %M%==2 GOTO SCCMCCC
IF %M%==3 GOTO SCCMDMT
IF %M%==4 GOTO GPO
IF %M%==5 GOTO AD
IF %M%==6 GOTO ISE
IF %M%==7 GOTO PS
IF %M%==8 GOTO CMD
IF %M%==p GOTO PINGPS
IF %M%==o GOTO PING
IF %M%==c GOTO CDRIVE 
IF %M%==r GOTO RCPC
IF %M%==a GOTO SETPC
IF %M%==t GOTO tasklist
IF %M%==g GOTO tasklistps
IF %M%==x GOTO startup
IF %M%==d GOTO RDP
IF %M%==i GOTO ICMD
IF %M%==dsm goto DSM

goto START

:SCCMCON
start "" "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.exe"
goto START

:SCCMCCC
start "" "C:\Program Files\Client Center for Configuration Manager\SCCMCliCtrWPF.exe"
GOTO START

:SCCMDMT
REM start "" "Removed For reasons"
GOTO START

:GPO
start "" "%SystemRoot%\system32\gpmc.msc"
GOTO START

:AD
start "" "%SystemRoot%\system32\dsa.msc"
GOTO START

:SETPC
SET /P PCNAME=Choose PC Name then Press ENTER:
goto START

:RCPC
start "" "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe" %PCNAME%
goto START

:RDP
start "" mstsc /v:%pcname% /f
goto START

:CDRIVE
START "" \\%PCNAME%\c$
GOTO START

:PING
START "Running as %username%" %windir%\system32\ping.exe %PCNAME% -t
GOTO START

:PINGPS
START "" powershell "Test-Connection %pcname% -count 15| out-gridview | pause"
GOTO START

:TASKLIST
%sysint%\psexec.exe \\%pcname% c:\windows\system32\tasklist.exe >%menutemp%\tasklist.txt
start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" %menutemp%\tasklist.txt
GOTO Start

:TASKLISTPS
start "" powershell "get-process -ComputerName %PCNAME% | out-gridview | pause"
GOTO Start

:startup
start "" "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.exe"
start "" "C:\Program Files\Client Center for Configuration Manager\SCCMCliCtrWPF.exe"
start "" "%SystemRoot%\system32\gpmc.msc" /min
start "" "%SystemRoot%\system32\dsa.msc"
goto start

:ise
start "" %windir%\sysWOW64\WindowsPowerShell\v1.0\PowerShell_ISE.exe
goto start

:CMD
start "Running as %username%" cmd.exe
goto start

:PS
start "" powershell.exe
goto start

:ICMD
start "" %sysint%\psexec.exe \\%pcname% cmd.exe
goto start

:DSM
rem Removed for Reasons
goto start

正如您所看到的,使用ShowUI模块制作PowerShell脚本使脚本更易于管理,但如果我无法解决此变量问题,我可能不得不继续使用批处理菜单进行远程工作,并使用PowerShell启动应用程序。

因此,如果有人之前使用过ShowUI模块,并且知道如何解决这个问题,那将非常感激。

干杯,

纳特

1 个答案:

答案 0 :(得分:0)

  

$ script:pcname = [Microsoft.VisualBasic.Interaction] :: InputBox(" Enter   计算机名称","计算机")

- Mathias R. Jessen 2月29日7:05