2015-02-09 36 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