배치 파일에서 메시지 상자를 표시하는 방법 xmessage이 있습니까 (Linux의 bash 스크립트에서 사용 하는 방법과 유사 )?
배치 파일에서 메시지 상자를 표시하는 방법 xmessage이 있습니까 (Linux의 bash 스크립트에서 사용 하는 방법과 유사 )?
답변:
매우 간단한 VBScript 파일을 만들고 CScript를 사용하여 호출하여 명령 줄 매개 변수를 구문 분석합니다.
다음과 같은 것이 저장되었습니다 MessageBox.vbs.
Set objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox messageText
다음과 같이 전화하십시오.
cscript MessageBox.vbs "This will be shown in a popup."
우선, DOS는 그것과 아무 관련이 없습니다. 아마도 Windows 명령 행 솔루션을 원할 것입니다.
boflynn에서 제공하는 VBScript 방법을 사용 net send하거나 또는 잘못 사용하거나을 사용할 수 있습니다 msg. net send이전 버전의 창에서만 작동합니다.
net send localhost Some message to display
그러나 이것은 메신저 서비스 실행에 달려 있습니다.
최신 버전 (XP 이상) :
msg "%username%" Some message to display
를 사용하여 보낸 메시지 상자는 msg.exe60 초 동안 만 지속됩니다. 그러나 이것은 /time:xx스위치 로 재정의 될 수 있습니다 .
약간의 플래시가 표시 될 수 있지만 임시 파일은 필요하지 않습니다. (IIRC) IE5 시대로 돌아 가야합니다.
mshta javascript:alert("Message\n\nMultiple\nLines\ntoo!");close();
if 1 == 1 (
mshta javascript:alert^("1 is equal to 1, amazing."^);close^(^);
)
close() was unexpected at this time합니다.
^ 박쥐 파일에서 이스케이프 문자
다른 명령 프롬프트 창이 나타납니다.
START CMD /C "ECHO My Popup Message && PAUSE"
start cmd /c "@echo off & mode con cols=18 lines=2 & echo My Popup Message & pause>nul", cols=18메시지의 문자 수를 +2로 변경하십시오 . 그리고 lines=2라인의 양에 관계없이 +1입니다.
cmd /k
시도 :
Msg * "insert your message here"
Windows XP의 command.com을 사용하는 경우 메시지 상자가 열립니다.
새로운 cmd 창을 여는 것은 당신이 요구 한 것이 아닙니다. VBScript 를 사용하고 .bat 파일과 함께 사용할 수도 있습니다 . 다음 명령을 사용하여 bat 파일에서 열 수 있습니다.
cd C:\"location of vbscript"
이것이하는 일은 디렉토리 command.com이 다음 줄에서 파일을 검색하는 것입니다.
"insert name of your vbscript here".vbs
그런 다음 새 메모장 문서 를 작성하고 다음을 입력하십시오.
<script type="text/vbscript">
MsgBox "your text here"
</script>
그런 다음 파일 이름 끝에 ".vbs"를 넣어 .vbs 파일로 저장하고 파일 이름 아래 드롭 다운 상자에 "모든 파일"로 저장합니다 (따라서 .txt로 저장되지 않음) )을 클릭 한 다음 저장을 클릭하십시오.
<script/>태그 가 필요하지 않습니다 .
msg *하면 메시지를 입력하라는 메시지가 표시되고 ctrl-Z가 표시됩니다. 메시지에 나타날 줄 바꿈을 여기에 입력 할 수 있습니다.
더 많은 방법이 있습니다.
1) 가장 괴상하고 가장 까다로운-IEXPRESS를 사용하여 작은 exe를 만들어 단일 버튼 으로 팝업을 만듭니다 (두 가지 유형의 팝업 메시지를 만들 수 있음 ). XP 이상의 모든 창에서 작동합니다.
;@echo off
;setlocal
;set ppopup_executable=popupe.exe
;set "message2=click OK to continue"
;
;del /q /f %tmp%\yes >nul 2>&1
;
;copy /y "%~f0" "%temp%\popup.sed" >nul 2>&1
;(echo(FinishMessage=%message2%)>>"%temp%\popup.sed";
;(echo(TargetName=%cd%\%ppopup_executable%)>>"%temp%\popup.sed";
;(echo(FriendlyName=%message1_title%)>>"%temp%\popup.sed"
;
;iexpress /n /q /m %temp%\popup.sed
;%ppopup_executable%
;rem del /q /f %ppopup_executable% >nul 2>&1
;pause
;endlocal
;exit /b 0
[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=1
HideExtractAnimation=1
UseLongFileName=0
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles
[SourceFiles]
SourceFiles0=C:\Windows\System32\
[SourceFiles0]
%FILE0%=
[Strings]
AppLaunched=subst.exe
PostInstallCmd=<None>
AdminQuietInstCmd=
UserQuietInstCmd=
FILE0="subst.exe"
DisplayLicense=
InstallPrompt=
2) 사용 MSHTA. 또한 XP 이상의 모든 Windows 시스템에서 작동합니다 (OP는 "외부"언어를 원하지 않지만 JavaScript는 최소화됩니다). 다음과 같이 저장해야합니다 .bat.
@if (true == false) @end /*!
@echo off
mshta "about:<script src='file://%~f0'></script><script>close()</script>" %*
goto :EOF */
alert("Hello, world!");
또는 한 줄로 :
mshta "about:<script>alert('Hello, world!');close()</script>"
또는
mshta "javascript:alert('message');close()"
또는
mshta.exe vbscript:Execute("msgbox ""message"",0,""title"":close")
3) 여기에 매개 변수가있는 .bat/jscript하이브리드가 있습니다 (bat ). OP 요청에도 불구하고 JavaScript를 다시 사용하지만 박쥐이므로 걱정하지 않고 박쥐 파일로 호출 할 수 있습니다. 그것은 대중적인 MSGBOX 보다는 조금 더 많은 통제를 허용하는 POPUP 를 사용합니다 . 위의 예와 같이 WSH를 사용하지만 MSHTA는 사용하지 않습니다.
@if (@x)==(@y) @end /***** jscript comment ******
@echo off
cscript //E:JScript //nologo "%~f0" "%~nx0" %*
exit /b 0
@if (@x)==(@y) @end ****** end comment *********/
var wshShell = WScript.CreateObject("WScript.Shell");
var args=WScript.Arguments;
var title=args.Item(0);
var timeout=-1;
var pressed_message="button pressed";
var timeout_message="timed out";
var message="";
function printHelp() {
WScript.Echo(title + "[-title Title] [-timeout m] [-tom \"Time-out message\"] [-pbm \"Pressed button message\"] [-message \"pop-up message\"]");
}
if (WScript.Arguments.Length==1){
runPopup();
WScript.Quit(0);
}
if (args.Item(1).toLowerCase() == "-help" || args.Item(1).toLowerCase() == "-h" ) {
printHelp();
WScript.Quit(0);
}
if (WScript.Arguments.Length % 2 == 0 ) {
WScript.Echo("Illegal arguments ");
printHelp();
WScript.Quit(1);
}
for (var arg = 1 ; arg<args.Length;arg=arg+2) {
if (args.Item(arg).toLowerCase() == "-title") {
title = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-timeout") {
timeout = parseInt(args.Item(arg+1));
if (isNaN(timeout)) {
timeout=-1;
}
}
if (args.Item(arg).toLowerCase() == "-tom") {
timeout_message = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-pbm") {
pressed_message = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-message") {
message = args.Item(arg+1);
}
}
function runPopup(){
var btn = wshShell.Popup(message, timeout, title, 0x0 + 0x10);
switch(btn) {
// button pressed.
case 1:
WScript.Echo(pressed_message);
break;
// Timed out.
case -1:
WScript.Echo(timeout_message);
break;
}
}
runPopup();
4) 하나 jscript.net/.bat 하이브리드 ( .bat) 로 저장해야합니다. 이번에는 삭제할 수 .NET있는 작은 .exe파일을 사용 하고 컴파일합니다 .
@if (@X)==(@Y) @end /****** silent jscript comment ******
@echo off
::::::::::::::::::::::::::::::::::::
::: compile the script ::::
::::::::::::::::::::::::::::::::::::
setlocal
::if exist "%~n0.exe" goto :skip_compilation
:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
if exist "%%v\jsc.exe" (
rem :: the javascript.net compiler
set "jsc=%%~dpsnfxv\jsc.exe"
goto :break_loop
)
)
echo jsc.exe not found && exit /b 0
:break_loop
call %jsc% /nologo /out:"%~n0.exe" "%~f0"
::::::::::::::::::::::::::::::::::::
::: end of compilation ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation
::
::::::::::
"%~n0.exe" %*
::::::::
::
endlocal
exit /b 0
****** end of jscript comment ******/
import System;
import System.Windows;
import System.Windows.Forms
var arguments:String[] = Environment.GetCommandLineArgs();
MessageBox.Show(arguments[1],arguments[0]);
5) 마지막으로 팝업을 생성하는 powershell을 한 번만 호출합니다 (powershell이 설치된 경우 명령 행 또는 배치에서 호출 가능).
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show("""Hello World""", """My PopUp Message Box""")
6) 그리고 여기에 보이는 dbenham의 접근
start "" cmd /c "echo(&echo(&echo Hello world! &echo(&pause>nul"
7 ) 시스템 트레이 알림을 위해 당신은 시도 할 수 있습니다 이 :
call SystemTrayNotification.bat -tooltip warning -time 3000 -title "Woow" -text "Boom" -icon question
다음은 창을 만들기 전에 어셈블리를로드하지 않아도되는 PowerShell 변형이지만 @npocmaka가 게시 한 PowerShell MessageBox 명령보다 눈에 띄게 느리게 실행됩니다 (~ + 50 %).
powershell (New-Object -ComObject Wscript.Shell).Popup("""Operation Completed""",0,"""Done""",0x0)
대화 상자에 아이콘을 표시하기 위해 마지막 매개 변수를 "0x0"에서 아래 값으로 변경할 수 있습니다 (자세한 내용은 팝업 방법 참조).
0x10 중지
0x20 물음표
0x30 느낌표
0x40 정보 표시
Microsoft TechNet 기사 PowerTip : PowerShell을 사용하여 팝업 창 표시 에서 수정되었습니다 .
echo X=MsgBox("Message Description",0+16,"Title") >msg.vbs
–0 대신에 0,1,2,3,4의 숫자를 쓸 수 있으며 ( '+'기호 앞) 각 숫자의 의미는 다음과 같습니다.
0 = Ok Button
1 = Ok/Cancel Button
2 = Abort/Retry/Ignore button
3 = Yes/No/Cancel
4 = Yes/No
– (+ 기호 뒤에) 16 대신 16,32,48,64의 숫자를 쓸 수 있으며 각 숫자의 의미는 다음과 같습니다.
16 – Critical Icon
32 – Warning Icon
48 – Warning Message Icon
64 – Information Icon
이렇게하려면 메시지 상자를 표시하고 배치 파일에서 실행하는 작은 프로그램이 있어야합니다.
프롬프트를 표시하는 콘솔 창을 열 수는 있지만 cmd.exe 및 친구 만 사용하여 GUI 메시지 상자를 얻는 것은 불가능합니다 (AFAIK).
여기에서 msgbox.exe라는 유틸리티를 사용합니다. http://www.paulsadowski.com/WSH/cmdprogs.htm
user32.dll에서 dll 함수를 호출 할 수 있습니다.
Rundll32.exe user32.dll, MessageBox (0, "text", "titleText", {최상위 메시지 상자와 같은 추가 플래그})
내 전화에서 입력하면 나를 판단하지 마십시오 ... 그렇지 않으면 여분의 플래그를 연결합니다.
rundll32.exe user32.dll,MessageBoxA X실행 상자에서 X를 사용하여 메시지 상자를 제목으로 표시 할 수 있습니다 . X를 무엇으로 만들 든 여러 매개 변수로 해석 할 수는 없습니다. 모든 것이 제목에 들어갑니다. 그래서 rundll32.exe user32.dll,MessageBoxA (0, "MyTitle", "MyText", 0)디스플레이의 제목을 가진 메시지 박스 (0, "MyTitle", "MyText", 0) 하지만이 명령 줄에서 AT ALL을 동작하지 않습니다 - 단지 실행 상자에서. 커맨드 라인에서는 전혀 작동하지 않습니다. 명령 줄이나 배치 파일 또는 실행 상자에서만 제대로 작동합니까?
msg * /server:127.0.0.1 여기에 메시지를 입력
where msg반환합니다 C:\Windows\System32\msg.exe. 당신이 생각하는 것net send
배치 파일을 실행 파일로 변환 (랩핑)하면 이 응용 프로그램에서 이를 수행 할 수 있습니다.
간단한 메시지 박스
%extd% /messagebox Title Text
오류 메시지 상자
%extd% /messagebox Error "Error message" 16
다시 시도하기
%extd% /messagebox Title "Try again or Cancel" 5
4) "다시 묻지 마십시오"메시지 상자
%extd% /messageboxcheck Title Message 0 {73E8105A-7AD2-4335-B694-94F837A38E79}
더 나은 옵션
set my_message=Hello world&& start cmd /c "@echo off & mode con cols=15 lines=2 & echo %my_message% & pause>nul"
설명 :
lines= 줄 수, cols= 메시지에 1
자 더하기, 3 더하기 (단, 최소값은이어야 함 15)
cols버전 :set my_message=Hello world&& (echo %my_message%>EMPTY_FILE123 && FOR %? IN (EMPTY_FILE123 ) DO SET strlength=%~z? && del EMPTY_FILE123 ) && start cmd /c "@echo off && mode con lines=2 cols=%strlength% && echo %my_message% && pause>nul"
start cmd /c "@echo off & mode con cols=18 lines=2 & echo My Popup Message & pause>nul"). 당신은하지 않습니다. 그것은 메시지를 에코하지만 The screen cannot be set to the number of lines and columns specified.적어도 내 Windows 7에서 반환 창 크기를 설정하지 못했습니다 .
x현재 디렉토리에 이름이 지정된 파일 이 없거나 잃어 버릴 염려 가 없다면 실제로 작동 합니다.
여기에 좋은 답변을 기반으로 한 다른 배치 스크립트가 있습니다.
제목 시간 초과를 설정하고 심지어 후자에 대해 예약하도록 잠자기 및 \ n 새 줄에 대해 예약 할 수 있습니다
이름을 popup.bat로 지정하고 Windows 경로 폴더에 넣어 PC에서 전체적으로 작동하십시오.
예를 들어 popup Line 1\nLine 22 줄 팝업 상자 ( popup /?사용 유형 )가 생성됩니다.
여기 코드가 있습니다
<!-- : Begin CMD
@echo off
cscript //nologo "%~f0?.wsf" %*
set pop.key=[%errorlevel%]
if %pop.key% == [-1] set pop.key=TimedOut
if %pop.key% == [1] set pop.key=Ok
if %pop.key% == [2] set pop.key=Cancel
if %pop.key% == [3] set pop.key=Abort
if %pop.key% == [4] set pop.key=Retry
if %pop.key% == [5] set pop.key=Ignore
if %pop.key% == [6] set pop.key=Yes
if %pop.key% == [7] set pop.key=No
if %pop.key% == [10] set pop.key=TryAgain
if %pop.key% == [11] set pop.key=Continue
if %pop.key% == [99] set pop.key=NoWait
exit /b
-- End CMD -->
<job><script language="VBScript">
'on error resume next
q =""""
qsq =""" """
Set objArgs = WScript.Arguments
Set objShell= WScript.CreateObject("WScript.Shell")
Popup = 0
Title = "Popup"
Timeout = 0
Mode = 0
Message = ""
Sleep = 0
button = 0
If objArgs.Count = 0 Then
Usage()
ElseIf objArgs(0) = "/?" or Lcase(objArgs(0)) = "-h" or Lcase(objArgs(0)) = "--help" Then
Usage()
End If
noWait = Not wait()
For Each arg in objArgs
If (Mid(arg,1,1) = "/") and (InStr(arg,":") <> 0) Then haveSwitch = True
Next
If not haveSwitch Then
Message=joinParam("woq")
Else
For i = 0 To objArgs.Count-1
If IsSwitch(objArgs(i)) Then
S=split(objArgs(i) , ":" , 2)
select case Lcase(S(0))
case "/m","/message"
Message=S(1)
case "/tt","/title"
Title=S(1)
case "/s","/sleep"
If IsNumeric(S(1)) Then Sleep=S(1)*1000
case "/t","/time"
If IsNumeric(S(1)) Then Timeout=S(1)
case "/b","/button"
select case S(1)
case "oc", "1"
button=1
case "ari","2"
button=2
case "ync","3"
button=3
case "yn", "4"
button=4
case "rc", "5"
button=5
case "ctc","6"
button=6
case Else
button=0
end select
case "/i","/icon"
select case S(1)
case "s","x","stop","16"
Mode=16
case "?","q","question","32"
Mode=32
case "!","w","warning","exclamation","48"
Mode=48
case "i","information","info","64"
Mode=64
case Else
Mode=0
end select
end select
End If
Next
End If
Message = Replace(Message,"/\n", "°" )
Message = Replace(Message,"\n",vbCrLf)
Message = Replace(Message, "°" , "\n")
If noWait Then button=0
Wscript.Sleep(sleep)
Popup = objShell.Popup(Message, Timeout, Title, button + Mode + vbSystemModal)
Wscript.Quit Popup
Function IsSwitch(Val)
IsSwitch = False
If Mid(Val,1,1) = "/" Then
For ii = 3 To 9
If Mid(Val,ii,1) = ":" Then IsSwitch = True
Next
End If
End Function
Function joinParam(quotes)
ReDim ArgArr(objArgs.Count-1)
For i = 0 To objArgs.Count-1
If quotes = "wq" Then
ArgArr(i) = q & objArgs(i) & q
Else
ArgArr(i) = objArgs(i)
End If
Next
joinParam = Join(ArgArr)
End Function
Function wait()
wait=True
If objArgs.Named.Exists("NewProcess") Then
wait=False
Exit Function
ElseIf objArgs.Named.Exists("NW") or objArgs.Named.Exists("NoWait") Then
objShell.Exec q & WScript.FullName & qsq & WScript.ScriptFullName & q & " /NewProcess: " & joinParam("wq")
WScript.Quit 99
End If
End Function
Function Usage()
Wscript.Echo _
vbCrLf&"Usage:" _
&vbCrLf&" popup followed by your message. Example: ""popup First line\nescaped /\n\nSecond line"" " _
&vbCrLf&" To triger a new line use ""\n"" within the msg string [to escape enter ""/"" before ""\n""]" _
&vbCrLf&"" _
&vbCrLf&"Advanced user" _
&vbCrLf&" If any Switch is used then you must use the /m: switch for the message " _
&vbCrLf&" No space allowed between the switch & the value " _
&vbCrLf&" The switches are NOT case sensitive " _
&vbCrLf&"" _
&vbCrLf&" popup [/m:""*""] [/t:*] [/tt:*] [/s:*] [/nw] [/i:*]" _
&vbCrLf&"" _
&vbCrLf&" Switch | value |Description" _
&vbCrLf&" -----------------------------------------------------------------------" _
&vbCrLf&" /m: /message:| ""1 2"" |if the message have spaces you need to quote it " _
&vbCrLf&" | |" _
&vbCrLf&" /t: /time: | nn |Duration of the popup for n seconds " _
&vbCrLf&" | |<Default> untill key pressed" _
&vbCrLf&" | |" _
&vbCrLf&" /tt: /title: | ""A B"" |if the title have spaces you need to quote it " _
&vbCrLf&" | | <Default> Popup" _
&vbCrLf&" | |" _
&vbCrLf&" /s: /sleep: | nn |schedule the popup after n seconds " _
&vbCrLf&" | |" _
&vbCrLf&" /nw /NoWait | |Continue script without the user pressing ok - " _
&vbCrLf&" | | botton option will be defaulted to OK button " _
&vbCrLf&" | |" _
&vbCrLf&" /i: /icon: | ?/q |[question mark]" _
&vbCrLf&" | !/w |[exclamation (warning) mark]" _
&vbCrLf&" | i/info|[information mark]" _
&vbCrLf&" | x/stop|[stop\error mark]" _
&vbCrLf&" | n/none|<Default>" _
&vbCrLf&" | |" _
&vbCrLf&" /b: /button: | o |[OK button] <Default>" _
&vbCrLf&" | oc |[OK and Cancel buttons]" _
&vbCrLf&" | ari |[Abort, Retry, and Ignore buttons]" _
&vbCrLf&" | ync |[Yes, No, and Cancel buttons]" _
&vbCrLf&" | yn |[Yes and No buttons]" _
&vbCrLf&" | rc |[Retry and Cancel buttons]" _
&vbCrLf&" | ctc |[Cancel and Try Again and Continue buttons]" _
&vbCrLf&" ---> | ---> |The output will be saved in variable ""pop.key""" _
&vbCrLf&"" _
&vbCrLf&"Example:" _
&vbCrLf&" popup /tt:""My MessageBox"" /t:5 /m:""Line 1\nLine 2\n/\n\nLine 4""" _
&vbCrLf&"" _
&vbCrLf&" v1.9 By RDR @ 2020"
Wscript.Quit
End Function
</script></job>