문제

배치 파일에서 메시지 상자를 표시하는 방법이 있습니까(방법과 비슷함) 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."

MsgBox 참조 이 경로에 관심이 있다면.

다른 팁

우선, DOS는 그것과 관련이 없습니다. 아마도 Windows 명령 줄 솔루션을 원할 것입니다 (다시 : DOS, 순수한 창, 창문이 아니라 콘솔).

Boflynn에서 제공 한 vbscript 방법을 사용하거나 잘못 사용될 수 있습니다. net send 또는 msg. net send 이전 버전의 Windows에서만 작동합니다.

net send localhost Some message to display

그러나 이것은 또한 메신저 서비스에 달려 있습니다.

최신 버전 (XP 및 이후)의 경우 :

msg "%username%" Some message to display

사용하여 전송 된 메시지 상자가 msg.exe 60 초만 지속됩니다. 그러나 이것은 THE와 함께 대체 할 수 있습니다 /time:xx 스위치.

약간의 플래시가 표시 될 수 있지만 임시 파일이 필요하지 않습니다. (IIRC) IE5 시대의 어딘가로 돌아 가야합니다.

mshta javascript:alert("Message\n\nMultiple\nLines\ntoo!");close();

잊지 마세요 괄호를 피하십시오 사용하는 경우 if:

if 1 == 1 (
   mshta javascript:alert^("1 is equal to 1, amazing."^);close^(^);
)

다른 명령 프롬프트 창이 팝업됩니다.

START CMD /C "ECHO My Popup Message && PAUSE"

노력하다 :

Msg * "insert your message here" 

Windows XP의 Command.com을 사용하는 경우 메시지 상자가 열립니다.

새로운 CMD 창을 여는 것은 당신이 요구했던 것이 아닙니다. 당신은 또한 사용할 수 있습니다 vbscript, .BAT 파일과 함께 사용하십시오. 이 명령을 사용하여 BAT 파일에서 열 것입니다.

cd C:\"location of vbscript"

이것이하는 일은 Directory Command.com을 변경하여 다음 줄에서 파일을 검색합니다.

"insert name of your vbscript here".vbs

그런 다음 새로운 것을 만듭니다 메모장 문서, 입력하십시오

<script type="text/vbscript">
    MsgBox "your text here"
</script>

그런 다음 이것을 filename의 끝에 ".vbs"를 넣어 .vbs 파일로 저장하고 파일 이름 아래의 드롭 다운 상자에 "모든 파일"으로 저장합니다 (따라서 .txt로 저장하지 않습니다. ), 그런 다음 저장을 클릭하십시오!

이렇게하면 배치 파일이 VBS 스크립트를 생성하고 팝업을 표시합니다. 실행되면 배치 파일이 해당 중간 파일을 삭제합니다.

Msgbox를 사용하면 이점은 실제로 CustomAzable (제목 변경, 아이콘 등)이 아니라 MSG.exe가 그리 많지 않다는 것입니다.

echo MSGBOX "YOUR MESSAGE" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q

몇 가지 방법이 더 있습니다.

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를 사용하지만 bat이므로 걱정 없이 bat 파일이라고 부를 수 있습니다.그것은 사용한다 팝업 이는 더 인기 있는 것보다 조금 더 제어할 수 있게 해줍니다. MSGBOX.위의 예와 같이 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

Window를 만들기 전에 로딩 어셈블리를 필요로하지 않는 PowerShell 변형은 다음과 같습니다. 그러나 @NPocmaka에 의해 여기에 게시 된 PowerShell MessageBox 명령보다 눈에 띄게 느리게 실행됩니다 (~+50%).

powershell (New-Object -ComObject Wscript.Shell).Popup("""Operation Completed""",0,"""Done""",0x0)

마지막 매개 변수를 "0x0"에서 아래 값으로 변경하여 대화 상자에 아이콘을 표시 할 수 있습니다 ( 팝업 방법 추가 참조) :

        Stop 0x10 정지
        Question Mark 0x20 물음표
        Exclamation Mark 0x30 느낌표
        Information Mark 0x40 정보 표시

Microsoft Technet 기사에서 조정되었습니다 PowerTIP : PowerShell을 사용하여 팝업 창을 표시하십시오.

echo X=MsgBox("Message Description",0+16,"Title") >msg.vbs

- 0 대신 0,1,2,3,4 ( '+'기호 앞) 대신 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  

msg * "여기에 메시지 삽입"

잘 작동하거나 메모장에서 .BAT 파일로 저장하거나 형식이 "모든 파일"으로 설정되어 있는지 확인하십시오.

이를 위해서는 메시지 상자를 표시하고 배치 파일에서 실행하는 작은 프로그램이 있어야합니다.

그래도 프롬프트가 표시되는 콘솔 창을 열 수 있지만 CMD.EXE와 친구 만 사용하여 GUI 메시지 상자를 얻는 것은 불가능합니다.

여기에서 msgbox.exe라는 유틸리티를 사용합니다.http://www.paulsadowski.com/wsh/cmdprogs.htm

당신이 사용할 수있는 순식. Zenity를 사용하면 명령 줄 및 쉘 스크립트에서 대화 상자를 실행할 수 있습니다. 더 많은 정보도 찾을 수 있습니다 위키 백과.

크로스 플랫폼입니다 : Windows 용 Windows 설치 프로그램을 찾을 수 있습니다. 여기.

msg * /time:0 /w Hello everybody!

이 메시지는 OK가 클릭 될 때까지 영원히 기다립니다 (기본적으로 1 분만 지속) Windows 8.1에서 잘 작동합니다.

@fowl의 답변에 따라 다음을 사용하여 10 초 동안 만 표시되도록 시간 초과로 개선 할 수 있습니다.

mshta "javascript:var sh=new ActiveXObject( 'WScript.Shell' ); sh.Popup( 'Message!', 10, 'Title!', 64 );close()"

보다 여기 자세한 사항은.

user32.dll에서 dll 함수를 호출 할 수 있습니다.

rundll32.exe user32.dll, messagebox (0, "text", "titletext", {가장 큰 메시지 상자 등에 대한 추가 플래그})

내 휴대 전화에서 입력하고 나를 판단하지 마십시오 ... 그렇지 않으면 추가 깃발을 연결합니다.

msg * /server:127.0.0.1 여기에 메시지를 입력하십시오

이것 신청 배치 파일을 실행 파일로 변환 (랩)하면 그렇게 할 수 있습니다.


  1. 간단한 메시지 상자

    %extd% /messagebox Title Text
    

  1. 오류 메시지 상자

    %extd% /messagebox  Error "Error message" 16
    
  2. 취소 메시지 상자를 다시 시도하십시오

    %extd% /messagebox Title "Try again or Cancel" 5
    

4) "다시는 묻지 마십시오"MessageBox

%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= 줄의 양, + 1
cols= 메시지의 문자 양, 추가 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"

VM 내부에있을 때만 팝업이 필요하므로 기술적으로는 다음과 같은 코드가 있어야합니다.

if %machine_type% == virtual_machine then
   echo message box code
else
   continue normal installation code
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top