关于VBS程序不能够正常运行
我现在有这么一个例子,就是在我要监控一个web项目的服务,当服务出现问题,通过vbs检测能够自动重启该服务。我的两个环境分别是:win7 64位、windows server 2003
出现症状:
运行相同的vbs程序,当web服务出现问题,自动重启,win7能够正常检测并重启,2003也能够检测但不能够进行重启操作
最主要的是,以前2003还能够正常运行的,现在不知道为什么就是不断的跳dos窗口。(我记得运行正常的时候,之后我给金山毒霸做过安全漏洞补丁)
vbs代码如下:
on error resume Next
Dim a
a = True
data = "restart tomcat8------------>"
set WshShell = WScript.CreateObject("WScript.Shell")
set fs = createobject("scripting.filesystemobject")
Do While a
set http = CreateObject("Microsoft.XMLHTTP")
http.open "GET","http://localhost:8080/oa/system/SysOnline",false
http.send
if http.Status > 299 then
set ts = fs.opentextfile("c:\xfgl_"&date&".txt",8,true)
WshShell.Run("taskkill /F /im Tomcat8.exe /T")
WshShell.Run("net start Tomcat8")
ts.write data
ts.write "error code:"
ts.write http.Status
ts.write "-------error time:"
ts.write now
ts.writeblanklines 2
ts.close
end if
WScript.Sleep(1000)
loop
vbs每一秒访问http://localhost:8080/oa/system/SysOnline页面一次,如果访问不正常,则http.Status > 299,那么就会执行WshShell.Run("taskkill /F /im Tomcat8.exe /T") WshShell.Run("net start Tomcat8")这两个命令。
大 vbs tomcat java ee 如果访问不正常,则http.Status > 299,那么就会执行WshShell.Run("taskkill /F /im Tomcat8.exe /T") WshShell.Run("net start Tomcat8")这两个命令。
net.exe 和 Tomcat8.exe 都是控制台程序吧!它们运行时,当然就会跳DOS窗口出来。
你没有明白我的意思,我的意思是,现在能够通过这个vbs程序正常启动了。
我只能在cmd窗口下手动打这两个命令才有效,而在vbs里面的无效了,是不断的跳闪窗口(打开关闭,就是不启动了)而在我本地一切又是正常的。 用调试器(OD,WINDBG等)调试服务程序
To debug the initialization code of a service application, the debugger must be attached when the service is started. This is accomplished by creating a registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ProgramName
The ProgramName is the image file for the service application you are debugging. Do not specify a path. For example, the ProgramName might look like MyService.exe.
Under this key create a string data value called Debugger. The value of this string should be set to the full path of the debugger that will be used. For example,
c:\Debuggers\windbg.exe
In addition to setting this registry key, the service application must be marked as "interactive". This allows your service to interact with the desktop, and allows the debugger window to appear on your desktop.
This again requires modifying a registry key: you must bitwise-or the type entry for your service with 0x100 (this is the value for SERVICE_INTERACTIVE_PROCESS according to Winnt.h). The exact location and name of this registry entry varies. For example:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyServiceKey
Finally, you need to adjust the service application timeout. Otherwise, the service application will kill the debugger within 20 seconds after starting. Adjusting the timeout involves setting an entry in the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
Under this key, create a DWORD data value called ServicesPipeTimeout. Set this entry to the amount of time in milliseconds that you want the service to wait before timing out. For example, 60,000 is one minute, while 86,400,000 is 24 hours.
设置ServicesPipeTimeout后需要重启系统才生效
Now, when the service is started, the debugger will also start. When the debugger starts, it will stop at the initial process breakpoint, before the service has begun running. This allows you to set breakpoints or otherwise configure your debugging session to let you monitor the startup of your service. Another option is to place calls to the DebugBreak function in your service from the point at which you would like to break into the debugger. (For more information, see DebugBreak in the Platform SDK documentation.)
If your service is running with other services in a Service Host Process, you may need to isolate the service into its own Service Host Process.
补充:VB , 网络编程