NDog Posted August 8, 2016 Posted August 8, 2016 Hi Unfortunately I'm in a situation where I am forced to use .vbs script files to do a task. I need to be able to detect if a particular script has been run multiple instances, however it may not the exact same file, eg patha\script.vbs and pathb\script.vbs. The idea is that only one can run at a time and if a second script is launched it should exit. However that is not to say that any vbscript type process should exit, only these scripts that are 'marked' as such. In autoit you can do simple 3 lines, which sets a window version and then checks to see if it already running as such $g_szVersion = 'ScRiPt' If WinExists($g_szVersion) Then Exit ; It's already running AutoItWinSetTitle($g_szVersion) Is there an equivalent in a .vbs script? Ideally I would like to set a 'unique' szVersion string as above and then detect that string. Thanks
Moderators JLogan3o13 Posted August 8, 2016 Moderators Posted August 8, 2016 @NDog probably the easiest option, as it sounds like you could be running multiple copies from multiple locations, would be to lay down some specific machine-setting when your script launches, then remove it when it completes. For example, you could create a temp file in the system temp directory, then delete when you are done, something like this: strFile = "myScript.tmp" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile(objFSO.GetSpecialFolder(2) & "\" & strFile) Set objFile = nothing You could do the same with a registry entry. Then just have your script check for the existence of that file/registry item on startup. The only thing you'll need to be careful about is a prematurely aborted script, which would leave the file/registry key on the machine. Ensure you're taking every precaution to prevent script crash. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
NDog Posted August 15, 2016 Author Posted August 15, 2016 Thanks for the suggestion. Ideally I would like to check something in memory, however you gave me good ideas to consider.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now