AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

#SingleInstance, filename check

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
HuBa



Joined: 24 Feb 2007
Posts: 172
Location: Budapest, Hungary

PostPosted: Mon Dec 24, 2007 9:03 pm    Post subject: #SingleInstance, filename check Reply with quote

I suppose the #SingleInstance condition is evaluated against the script's full path.

Now my problem is that my script directory can be accessed from various ways.

I use subst to map a dir as a drive and also a local network share.

For example a D drive linking to C:\Dev
C:\Dev\AHK source\MyScript.ahk
D:\AHK source\MyScript.ahk

MyScript.ahk is physically the same.

I can launch a script from either way but it will start as a new instance even if I specified the "#SingleInstance force" flag, because the path for the filename is different and AHK believes that they are different files.

So I suggest an instance check considering only the filename without the directory path.
Maybe an option for the #SingleInstance directive.
Back to top
View user's profile Send private message Visit poster's website
Tuncay



Joined: 07 Nov 2006
Posts: 384
Location: Berlin

PostPosted: Mon Dec 24, 2007 9:13 pm    Post subject: Reply with quote

A check based on the PID would make more sense to me.
Back to top
View user's profile Send private message Send e-mail
HuBa



Joined: 24 Feb 2007
Posts: 172
Location: Budapest, Hungary

PostPosted: Mon Dec 24, 2007 9:17 pm    Post subject: Reply with quote

Tuncay wrote:
A check based on the PID would make more sense to me.

You misunderstood it. The ProcessID cannot help here.

I want to start the same script from different locations and I want to be sure there is only one instance running.
Back to top
View user's profile Send private message Visit poster's website
Tuncay



Joined: 07 Nov 2006
Posts: 384
Location: Berlin

PostPosted: Mon Dec 24, 2007 9:25 pm    Post subject: Reply with quote

Why cannot the PID help? The PID is the identity from all windows processes. You should not forget, that others could name the script exactly you did. Why not changing the command to use PID?
Back to top
View user's profile Send private message Send e-mail
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Thu Dec 27, 2007 1:31 pm    Post subject: Reply with quote

You have to use some other way to achieve that. Although your wish is semanticaly correct, when processes are in question it isn't a practice.

Generaly, u must use Mutex to achieve that.

My suggestion - on startup, you BROADCAST the message that only your running instnace can respond. That way you don't need to know hwnd or anything, so it can even be used for totaly different scripts if you don't want them to be run in paralel. If you don't get response that means there is no instance running. If you get the response, you will also get the hwnd of the responder in which case you can direct it to shutdown, or you can kill it and run normaly.

Only other way to check if script is the same as some other script is to use checksum, and that will slowdown startup a lot.
_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group