バッチ ファイルからメッセージ ボックスを表示する方法はありますか ( xmessageLinux の bash スクリプトから使用できる方法と同様です)。
22 に答える
まず第一に、DOS はそれとは何の関係もありません。おそらく Windows コマンド ライン ソリューションが必要です (繰り返しますが、DOS はなく、純粋な Windows であり、ウィンドウではなくコンソールです)。
boflynn が提供する VBScript メソッドを使用するか、 または を誤用することができnet sendますmsg。 net send古いバージョンの Windows でのみ動作します。
net send localhost Some message to display
ただし、これは実行する Messenger サービスにも依存します。
新しいバージョンの場合 (明らかに XP 以降):
msg "%username%" Some message to display
msg.exeを使用して送信されたメッセージ ボックスは60 秒間しか続かないことに注意してください。ただし、これはスイッチでオーバーライドできます/time:xx。
非常に単純な VBScript ファイルを作成し、CScript を使用してそれを呼び出し、コマンド ライン パラメーターを解析します。
に保存された次のようなものMessageBox.vbs:
Set objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox messageText
あなたは次のように呼びます:
cscript MessageBox.vbs "This will be shown in a popup."
少しフラッシュが表示される場合がありますが、一時ファイルは必要ありません。(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"
これが行うことは、command.com がファイルを検索するディレクトリを変更してから、次の行に変更することです。
"insert name of your vbscript here".vbs
次に、新しいメモ帳ドキュメントを作成し、次のように入力します
<script type="text/vbscript">
MsgBox "your text here"
</script>
次に、これを .vbs ファイルとして保存し (ファイル名の末尾に「.vbs」を付けて)、ファイル名の下のドロップダウン ボックスに「すべてのファイル」として保存します (したがって、.txt として保存されません)。 )、[保存] をクリックします。
さらにいくつかの方法。
1)最もマニアックでハック - IEXPRESS を使用して、1 つのボタンでポップアップを作成する小さな exe を作成します (さらに 2 種類のポップアップ メッセージを作成できます)。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!");
または1行で:
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)と 1 つの 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 を 1 回呼び出します (powershell がインストールされている場合は、コマンド ラインまたはバッチから呼び出すことができます)。
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show("""Hello World""", """My PopUp Message Box""")
6)そしてここに見られるドベンハムのアプローチ
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
このようにして、バッチファイルはVBSスクリプトを作成し、ポップアップを表示します。実行後、バッチファイルはその中間ファイルを削除します。
MSGBOXを使用する利点は、MSG.exeがそれほど多くないのに、実際にカスタマイズ可能(タイトル、アイコンなどを変更)できることです。
echo MSGBOX "YOUR MESSAGE" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q
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 メッセージ ボックスを取得することはできません。
ここから msgbox.exe という名前のユーティリティを使用します: http://www.paulsadowski.com/WSH/cmdprogs.htm
@Fowl's answer に続いて、次を使用してタイムアウトを 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 ここにメッセージを入力してください
バッチ ファイルを実行可能ファイルに変換 (ラップ)すると、このアプリケーションでそれが可能になります。
シンプルなメッセージボックス
%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}