Noob Posted January 3, 2007 Share Posted January 3, 2007 (edited) Run("notepad") HotKeySet("{F2}", "open_notepad") While 1 Sleep(100) WEnd Func open_notepad() Run("notepad") EndFuncI've been unsuccessfully trying to find a way to achieve the following:1. It should run Notepad when a user clicks on script.exe2. It should run Notepad when a user presses F2-key3. It should run the script, but not open Notepad, if a user places a shortcut to the script.exe in the Windows startup folder and the user either just logs on or starts the computer.The #3 is my problem. If the script is started just because a user just started his computer or he just logged on (and the shortcut to the script happens to be in the Windows startup folder), the script should run, but Notepad should not open. Notepad should only open when the user either clicks on the script icon on his desktop or presses F2-key. I attempted to use FileExists() to check if there was a shortcut in the Windows startup folder, but this fails working when users change the name of the shortcut. I wonder if there is a way to check if there is a startup folder shortcut to script.exe created by ANY name? Or perhaps I would be happy with a solution which would prevent a function from running within first 30 seconds of users loging on? Is there a way? Or perhaps there are better solutions to my dilemma I haven't thought of? Edited January 3, 2007 by Noob Link to comment Share on other sites More sharing options...
someone Posted January 3, 2007 Share Posted January 3, 2007 There might be a easier way to do this, but you could simply make your script create a shortcut into the startup folder (what might make the most sense is make 2 scripts, one that 'installs' your first script and use fileinstall to compile it into one .exe) and have your script make a shortcut to notepad on the users desktop. That would allow for everything you want. If your set on not using a normal windows notepad shortcut you could make another small script to fileinstall on the users desktop.. Does that work for you? I'm sorry I dont know a way to keep it only to one script but hopefully this helps anyway. If this is what you want I'll code up an example to get you started While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
Noob Posted January 3, 2007 Author Share Posted January 3, 2007 (edited) Thanks for replying. My script actually allows users to create a shortcut in the Windows startup folder by selecting an item in the sys tray icon menu. When I use If FileExists() to look for that shortcut, I can achieve what I want. But my problem is that if a user doesn't use my sys tray icon menu to create a shortcut, but instead creates his own with a different name (or renames mine), in such case this will no longer work.I'd like to stick with one file (avoiding an installation). Edited January 3, 2007 by Noob Link to comment Share on other sites More sharing options...
someone Posted January 3, 2007 Share Posted January 3, 2007 Your more then welcome for the reply... I'll keep thinking about this one it seems like such a simple thing it bugs me I dont know how. hmm... While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
someone Posted January 3, 2007 Share Posted January 3, 2007 (edited) Alright heres something... this is what you can do to eliminate the script running notepad on startup... $StartMenuPath = @StartupDir MsgBox(0, "", @ScriptDir);for testing MsgBox(0, "", $StartMenuPath);for testing If @ScriptDir = $StartMenuPath Then ; Else Run("notepad") EndIf oÝ÷ Ù8Z·¥»§^¥§b~+lj|°êÞnëbØ^²Ö«¶ê_¢W^¬ýYz(®H§íçn¦Xj׬µªíºç§¶¼ºØ^ë,¢g)àjÙ^jËDȶ§(¶+iºÛaƶ¢Ê«±Êâ¦Ö®¶sc²Æ6RBFRF÷öb÷W"67&@¢b33c¶u÷7¥fW'6öâÒgV÷C´æ÷FWB67&BgV÷C°¤bväW7G2b33c¶u÷7¥fW'6öâFVâWB²Bb33·2Ç&VG'Væææp¤WFôEvå6WEFFÆRb33c¶u÷7¥fW'6ö⣲&W7Böb÷W"67&BvöW2W&R oÝ÷ Ù8Zµ©e£(¨è§²Ö§qêÊ«±Êâ¦Ûh®éÛz÷§ÿÛ¶W§jg¢²·§jgmçºÇ¢¶ ²ß¡ý7ê3Uêìçjg¢'íë¬zºn¶Ëp¢æ¢·¨*.®Ç+l{azËZ®Û©~]z¼"¶b}÷«z{gjg¬¢¹¨ëazz'zÈh®×.¶íëç±zØ^±Êâ¦Ü"Z''±yËzÜx 趫2êÞ²+-ì!¢W¬r¸©¶Ú¾rߺȨ«¢+ØìA±ÐѡѽÀ½å½ÕÈÍÉ¥ÁÐ(ÀÌØí}ÍéYÉÍ¥½¸ôÅÕ½Ðí9½ÑÁMÉ¥ÁÐÅÕ½Ðì)%]¥¹á¥ÍÑÌ ÀÌØí}ÍéYÉÍ¥½¸¤Q¡¸á¥Ðì%ÐÌäí̱ÉäÉÕ¹¹¥¹)Õѽ%Ñ]¥¹MÑQ¥Ñ± ÀÌØí}ÍéYÉÍ¥½¸¤(ìIÍнå½ÕÈÍÉ¥Áн̡É((ÀÌØíMÑÉÑ5¹ÕAÑ ôMÑÉÑÕÁ¥È)5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°MÉ¥ÁѥȤí½ÈÑÍÑ¥¹)5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°ÀÌØíMÑÉÑ5¹ÕAÑ ¤í½ÈÑÍÑ¥¹)%MÉ¥ÁÑ¥ÈôÀÌØíMÑÉÑ5¹ÕAÑ Q¡¸($ì)±Í)IÕ¸ ÅÕ½Ðí¹½ÑÁÅÕ½Ðì¤)¹%()!½Ñ-åMÐ ÅÕ½ÐííÉôÅÕ½Ðì°ÅÕ½Ðí½Á¹}¹½ÑÁÅÕ½Ðì¤()]¡¥±Ä(M±À ÄÀÀÀ¤)]¹()Õ¹½Á¹}¹½ÑÁ ¤(IÕ¸ ÅÕ½Ðí¹½ÑÁÅÕ½Ðì¤)¹Õ¹)á¥Ð Let me know how this works for you. Edited January 3, 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...
Noob Posted January 3, 2007 Author Share Posted January 3, 2007 Hmm, I think the combination of the two of your ideas would do the trick if users would place my script in the Windows startup folder. But people place "shortcuts" in startup folders, not actual files. That's why I think @StartupDir will never be the same as @ScriptDir Link to comment Share on other sites More sharing options...
Emperor Posted January 3, 2007 Share Posted January 3, 2007 (edited) CheckDir(@StartupDir) Exit Func CheckDir($Dir) Local $Search = FileFindFirstFile($Dir & "\*.lnk") If $Search = -1 Then ; No shortcuts found Return False EndIf While True Local $File = FileFindNextFile($Search) If @error Then ExitLoop Local $Temp = FileGetShortcut($Dir & "\" & $File) If $Temp[0] = @ScriptFullPath Then FileClose($Search) ; Found a shortcut to this file Return True EndIf WEnd FileClose($Search) ; No shortcut to this file found Return False EndFuncThis function returns true if it finds a shortcut to your script in the directory you specify. I'm sure you can modify this to suit your needs.Edit: Changed an error in the function. Edited January 3, 2007 by Emperor Link to comment Share on other sites More sharing options...
/dev/null Posted January 3, 2007 Share Posted January 3, 2007 ; Place at the top of your script $g_szVersion = "Notepad Script" If WinExists($g_szVersion) Then Exit ; It's already running AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here That allows only one instance of your script to run even if the file name is renamed, because it goes off of $g_szVersion name. So if the user puts two (or more) of your scripts in the startup folder with different names (or more then one shortcut of the same .exe) the script will only execute once. better use _Singleton(). 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 More sharing options...
Noob Posted January 3, 2007 Author Share Posted January 3, 2007 Emperor, you just made this Noob very very happy :D A brief test shows that this is exactly what I need. It returns True no matter what the name of the *.lnk file in the @StartupDir, as long as it points to @ScriptFullPath ! That's exactly what I needed! I'm going to now add this to my script. Thanks very much to you and others for their time. 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