2017-09-22 4 views
0

많은 것들을 가진 배치 파일이 있습니다. 나는 사용자를위한 정보가있는 Alert Window가 하나있다.cmd/batch에서 PowerShell Net MessageBox를 실행하는 방법

Windows Pro에서는 메시지 명령을 사용하고 있습니다. 정상적으로 작동합니다. 윈도우 홈에

아무 메시지도 없다, 그래서 내가 대신 PowerShell을 사용하는 아이디어를 가지고 : PowerShell에서 잘 작동

[System.Windows.Forms.MessageBox]::Show("my text") 

.

- 그러나, 내가 배치에서 사용하거나 cmd를 직접 실행하려고 할 때, 난 단지 텍스트를 얻을 :

C:\Windows\System32>powershell {[System.Windows.Forms.MessageBox]::Show("\""my text"\"")} 
    [System.Windows.Forms.MessageBox]::Show("my text") 

아니면 내가 오류를 얻을 :

C:\Windows\System32>powershell -command [System.Windows.Forms.MessageBox]::Show("my text") 
At line:1 char:41 
+ [System.Windows.Forms.MessageBox]::Show(my text) 
+           ~ 
Missing ')' in method call. 
At line:1 char:41 
+ [System.Windows.Forms.MessageBox]::Show(my text) 
+           ~~ 
Unexpected token 'my' in expression or statement. 
At line:1 char:48 
+ [System.Windows.Forms.MessageBox]::Show(my text) 
+            ~ 
Unexpected token ')' in expression or statement. 
    + CategoryInfo   : ParserError: (:) [], ParentContainsErrorRecordException 
    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall 

또는

 C:\Windows\System32>powershell -command "& {[System.Windows.Forms.MessageBox]::Show('my text')}" 
Unable to find type [System.Windows.Forms.MessageBox]. 
At line:1 char:4 
+ & {[System.Windows.Forms.MessageBox]::Show('my text')} 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (System.Windows.Forms.MessageBox:TypeName) [], 
    RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

작동하려면 어떻게해야합니까?

당신은 당신이 그것을 호출하기 전에 유형을로드해야

답변

0

(PowerShell을에 전체 스크립트를 다시 작성하지 않고, 즉). 다음을 수행 할 수 있습니다.

powershell -command "[reflection.assembly]::LoadWithPartialName('System.Windows.Forms')|out-null;[windows.forms.messagebox]::Show('my message')" 
1

기술 전문가가 명시했듯이 먼저로드해야 할 수도 있습니다.

이 그들의 같은 대답은 단지 몇 줄에 걸쳐 효율적입니다 : my text 주위

@Echo Off 
PowerShell -Command^ 
"[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')|Out-Null;"^ 
"[System.Windows.Forms.MessageBox]::Show(\"my text\")" 
Pause 

... 그리고 동안 따옴표가 필요하지 않습니다, 나는 당신에게 탈출을 보여주기 위해 사용했습니다.

관련 문제