2015-02-09 39 views
2

有一段时间我问了一个问题(并得到了很好的回应)来创建下面的程序,我想静静地启动它,所以命令提示符不会在后台显示。 下面的程序测试“Agent.exe”,如果它找到它,显示一个消息框给用户,告诉他们程序将在2分钟内关闭,除非他们按下ok。启动Java/Batch混合而不显示命令提示符

现在

我碰到这个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表示欢迎,他回答了我对上述脚本的初步问题)

+0

在这里你可以找到不同的方法,你可以如何启动进程隐藏 - http://stackoverflow.com/questions/28284876/what-are-the-different-ways-to-start-a-hidden-过程与批处理文件和什么 - 一个 – npocmaka 2015-02-09 21:07:35

回答

2

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


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

@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文件而不是发出哔哔声。 :)

+0

嘟嘟声更恼人,它得到了关注,代理商离开他们的桌面上的耳机,所以我们需要提醒他们回到他们的机器。 – Denslat 2015-02-09 17:03:40

+0

啊,非常好。我把哔哔声放回去了。:P – rojo 2015-02-09 17:10:38

+0

好吧,由于您的脚本非常易于编辑,我将它们放回自己 – Denslat 2015-02-09 17:12:01