In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use VBS to call the program and monitor the operation of the program. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
At the same time, you have to use a CAE software to call an external program, but after calling an external program through this CAE software, because the external program has parameters, the calling method is written in the Bat file, and the CAE software calls the Bat. Therefore, the CAE software has no way to monitor the called program, the called program is still running, and the preparation work is not completed, it will go to the next process, so the process will make an error. I wrote two pieces of VBS code that solved this problem by calling it! The two Mini Program are monitored in different ways!
The two programs are called in different ways, one is to monitor the system process, and the other is to monitor the file characteristics generated by the program!
The first one:
This program is used to cooperate with SimCode to call other programs and monitor the operation of the program.
The monitoring method is to find the Log file of the program. If there is an end sign, the program has been executed!
Set WshShell=Wscript.CreateObject ("Wscript.Shell")
Program called by WshShell.Run ("notepad.exe c:\ kw.txt")'
Wscript.sleep 2000 'wait 2 seconds
Dim fso,ts,i
When Do While Not iTunes 1 is not established, it loops all the time!
Set fso=Wscript.CreateObject ("Scripting.FileSystemObject")
Set ts=fso.opentextfile ("c:\ kw.txt") 'opens the log file of the calling program's daily life
Do While Not ts.AtEndOfStream' loops when it doesn't reach the end of the file
Data=ucase (trim (ts.readline)) 'reads a line in the log file
If instr (data, "OK") Then' looks for the content read above to see if there is a sign that the program is finished! In this case, the flag is "OK"
When you get the sign that the program is finished, pass a value to the Do loop to end the loop and no longer monitor the Log file
Exit Do
End If
Loop
Set ts = nothing
Set fso = nothing' closes the created object
Wscript.sleep 2000 'waits for 2 seconds to proceed to the next round of Log file monitoring
Loop
Wscript.echo "OK!"' Give the user a feedback, the execution of the calling program is complete! When in real use, you should not want this line!
Second:
This program is used to cooperate with SimCode to call other programs and monitor the operation of the program.
The monitoring method is to monitor the process of the system.
Set WshShell = Wscript.CreateObject ("Wscript.Shell")
AllApp= "c:\ windows\ system32\ notepad.exe" 'writes down the full path of the program to be called.
AppName= "notepad.exe" write down the name of the calling program.
WshShell.Run (allApp) 'starts the calling program
Dim AppPath
For each ps in getobject ("winmgmts:\\.\ root\ cimv2:win32_process") .instances_ 'lists all running programs in the system
If lcase (ps.name) = AppName then' detects whether the program exists in the process
Command line of the AppPath=ps.commandline' extractor
End if
Next
Do' cycle detection
Myqqin=chkuin (App) 'detects whether the above command line exists in the process!
If if not myqqin then' is not running, tell the user and end the monitoring!
Msgbox "the calling program has exited!" In actual use, please remove this line!
Exit do
Else
Wscript.sleep 3000 'wait 5 seconds
End if
Loop' returns to continue detection.
Function chkuin (App)
For each ps in getobject ("winmgmts:\\.\ root\ cimv2:win32_process") .instances_
If lcase (ps.name) = AppName then
AppPatht1=ps.commandline
If AppPatht1=AppPath then chkuin=true end if
End if
Next
End function
On "how to use VBS to call the program and monitor the operation of the program" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.