Moonwaltz Posted January 4, 2007 Share Posted January 4, 2007 need to only let one instance of my script run at a time. compiled my script is called disable firewall.exeI only want one instance of the script to be active at a time but I'm having trouble figuring it out. when I make the processexist lines active the script won't run at all. everything else works as needed just need help with the script only running one at a time.CODE; Check for FIO already running;If ProcessExists("Disable Firewall.exe") Then; Exit;Else; EndIf;check for exported fileIf FileExists("C:\Firewall Temp\sever.xml") Then Else; Export current policyRunWait (@ComSpec & " /c " & '"FIO.exe O "C:\firewall temp\server.xml""', "C:\firewall temp", @SW_HIDE)EndIf; Import zero firewallRunWait (@ComSpec & " /c " & '"FIO.exe I "C:\firewall temp\Disable.cfp" /displayProgress"', "C:\firewall temp", @SW_ENABLE)MsgBox (4096, "Sara Lee Connections", "The firewall has been disabled for 5 min", 0)sleep(300000) Runwait (@ComSpec & " /c " & '"FIO.exe I "C:\firewall temp\server.xml" /displayProgress"', "C:\firewall temp", @SW_ENABLE)FileDelete ("C:\firewall temp\server.xml") MsgBox (4096, "Sara Lee Connections", "The firewall has been Re Enabled", 0) Link to comment Share on other sites More sharing options...
jvanegmond Posted January 4, 2007 Share Posted January 4, 2007 Function _Singleton. github.com/jvanegmond Link to comment Share on other sites More sharing options...
someone Posted January 4, 2007 Share Posted January 4, 2007 (edited) I believe there are two ways to do this I'm not sure which way is better. Check out _singleton in the help file... also the faq lists this as the manner to make sure your script is running only once. ; Place at the top of your script $g_szVersion = "My Script 1.1" If WinExists($g_szVersion) Then Exit ; It's already running AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here I was told posting in a topic yesterday and someone told me to use _singleton instead of the other way but I didn't understand why. Play around with them and see how they work for you. EDIT: Since there are other people here can someone explain why _singleton is better or more prefered? Edited January 4, 2007 by someone While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
/dev/null Posted January 4, 2007 Share Posted January 4, 2007 EDIT: Since there are other people here can someone explain why _singleton is better or more prefered?search the posts of valik for an explanation...CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Selmak Posted January 4, 2007 Share Posted January 4, 2007 My ten cents, but there are clearly two scenarios with this: 1. Script already running, and the user starting a second process could foul things up, so we stop them from doing that. 2. User wants to start script but there's an old, hung-up copy still in memory. In this case we want to nuke the old copy and allow the new process to continue. Requires two slightly different approaches, but in both cases the key is in renaming the current process after the check is completed, so we can distinguish old from new. In most cases (2) is the better approach as it allows for recovery from a fault, whereas (1) tends to lock the computer into any fault-situation that develops. Link to comment Share on other sites More sharing options...
Moonwaltz Posted January 4, 2007 Author Share Posted January 4, 2007 _singleton works perfectly. Thanks once again for all the help. Link to comment Share on other sites More sharing options...
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