Jump to content

limit number of times script is active


Recommended Posts

need to only let one instance of my script run at a time. compiled my script is called disable firewall.exe

I 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 file

If FileExists("C:\Firewall Temp\sever.xml") Then

Else

; Export current policy

RunWait (@ComSpec & " /c " & '"FIO.exe O "C:\firewall temp\server.xml""', "C:\firewall temp", @SW_HIDE)

EndIf

; Import zero firewall

RunWait (@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

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 by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

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...

Cheers

Kurt

__________________________________________________________(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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...