在不显示命令提示符的情况下启动 Java/Batch 混合动力车

Launch a Java/Batch hybrid without displaying command prompt

一会儿我问了一个问题(并得到了很好的回应)来创建下面的程序,我想要的是静默启动它,所以命令提示符不会在后台显示。 下面的程序测试 "Agent.exe",如果找到它,会向用户显示一个消息框,告诉他们程序将在 2 分钟后关闭,除非他们按 ok。

现在

我遇到了这个 VBS 脚本

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "Program goes here" & Chr(34), 0
Set WshShell = Nothing

但没有任何线索可以将它与我的脚本结合起来

@if (@CodeSection == @Batch) @then
setlocal
for /f %%I in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "beep=%%I"
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
setlocal
set "task=agent.exe"
set "timeout=120"
rem // Is %task% running?
tasklist /fi "imagename eq %task%" | find /i "%task%" >NUL && (

    rem // Re-launch script with JScript interpreter
    wscript /e:JScript /nologo "%~f0" %timeout% || (
        rem // If timeout or user hits No, kill %task%
        taskkill /im "%task%" /f
    )
)

rem // End main runtime

goto :EOF

rem // Begin JScript portion
@end
var osh = WSH.CreateObject('WScript.Shell'),
    nag = 'Greetings!  Your administrator has requested you to log out of Program '
        + 'after work.  It appears you are still using it.'
        + ' If you are still here, Press Yes to continue working.\n\n'
        + 'Otherwise, press no to close Program.'
        + 'Program will close automatically in less than ' + WSH.Arguments(0) + ' seconds.';
    popup = osh.Popup(nag, WSH.Arguments(0), 'Are you still here?', 0x4 + 0x20 + 0x1000);
WSH.Quit(popup - 6);

有人有什么想法吗? (感谢 Rojo,他用上面的脚本回答了我最初的问题)

为了回答您的问题,该 VBScript 代码段将起作用。只需将其保存为 .vbs 扩展名并将 "Program goes here" 替换为批处理脚本的路径+文件名。当您双击 vbs 文件或使用 wscript /nologo "path\to\vbsfile" 执行它时,它会 运行 隐藏批处理脚本(没有控制台 window)但弹出窗口仍然会出现。


如果您希望将所有代码保存在一个文件中,您可以调用 powershell -windowstyle hidden 来隐藏 window。您仍然会看到黑色 window 片刻,但它会在弹出窗口出现之前消失。

@if (@CodeSection == @Batch) @then
setlocal

rem // hide current window
powershell -windowstyle hidden -command ""

for /f %%I in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "beep=%%I"
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL

set "task=agent.exe"
set "timeout=120"
rem // Is %task% running?
tasklist /fi "imagename eq %task%" | find /i "%task%" >NUL && (

    rem // Re-launch script with JScript interpreter
    wscript /e:JScript /nologo "%~f0" %timeout% || (
        rem // If timeout or user hits No, kill %task%
        taskkill /im "%task%" /f
    )
)

rem // if not in a self-destructing window, re-show
set "caller=%cmdcmdline:"=%"
if /I not "%caller:~0,6%"=="cmd /c" powershell -windowstyle normal -command ""

rem // End main runtime
goto :EOF

rem // Begin JScript portion
@end
var osh = WSH.CreateObject('WScript.Shell'),
    nag = 'Greetings!  Your administrator has requested you to log out of the Cisco '
        + 'Agent Desktop after work.  It appears you are still using it.  If you '
        + 'are still here, Press Yes to continue working.\n\n'
        + 'Otherwise, press No to close the agent.  Agent will close automatically '
        + 'in less than ' + WSH.Arguments(0) + ' seconds.',

popup = osh.Popup(nag, WSH.Arguments(0), 'Are you still here?', 0x4 + 0x20 + 0x1000);

WSH.Quit(popup - 6);

收到并赞赏呼喊。我仍然认为你应该播放一个俗气的 midi 文件而不是哔哔声。 :)