2016-02-29 57 views
1

嗨我想爲我運行的最常見的程序製作一個小的GUI菜單。我有一個批量菜單,但我想使用ShowUI模塊製作PowerShell GUI版本(Show UI HomepagePowershell顯示UI設置變量

菜單運行正常,它將所有程序加載爲預期的高架用戶,不工作的是I有我的批處理菜單,讓我設置一個PC名稱變量,它允許我運行遠程程序的第二部分。 (I.E.Ping/test-connection,tasklist/get-process,interactive cmd.exe)

這被證明是困難的,顯示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 

正如你可以看到使其使用顯示用戶界面模塊PowerShell腳本使得腳本一個更容易管理,但如果我不能得到這個變量的問題就解決了我可能不得不繼續使用批處理菜單進行遠程工作,並使用PowerShell對la進行操作解開應用程序。

所以,如果有人已經使用過ShowUI模塊,並有一個想法如何解決這個,將不勝感激。

乾杯,

納特

+0

當你點擊「顯示PC名稱」按鈕時它顯示正確的PC名稱嗎? – Bum

+0

不僅顯示我在開始時推送的本地主機。它在運行時不會更新。 –

+1

'$ script:pcname = [Microsoft.VisualBasic.Interaction] :: InputBox(「輸入計算機名稱」,「計算機」)' –

回答

0

$腳本:pcname = [Microsoft.VisualBasic.Interaction] ::的InputBox( 「請輸入 計算機名」, 「電腦」)

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