topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 12, 2024, 4:39 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: make script only work if not started from USB stick  (Read 7455 times)

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,261
    • View Profile
    • Donate to Member
DONE: make script only work if not started from USB stick
« on: December 23, 2005, 04:49 PM »
Thanks to skrommel, I'm using a script that checks for the existence of a file:

IfNotExist,D:\data\program files\Autohotkey\daily\0815_%A_YYYY%-%A_MM%-%A_DD%.txt

If this file doesn't exist, it creates it and starts a process on my PC that I only want to run once a day. My problem: the script is also working when not only the file does not exist, but also when the path itself (D:\data\program files\Autohotkey\daily\) does not exist. So the process is also started when I run AutoHotkey from my USB stick on another PC.

What would be the best way to prevent this?

PhilKC

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 117
    • View Profile
    • BlueScreenOfDeath.co.uk
    • Donate to Member
Re: IDEA: make script only work if not started from USB stick
« Reply #1 on: December 23, 2005, 05:31 PM »
Well, I don't 'do' AutoHotKey, but, surely it allows you to check for directories?

C# code:

if ((Directory.Exists("D:\\data\\program files\\Autohotkey\\daily")) && (! File.Exists("D:\\data\\program files\\Autohotkey\\daily\\" + The_Date + ".txt")))
{
       Backup();
}

English code:

If the directory exists, but the file doesn't, backup...

Edit: IDEA! Put another file, "check.me" on the drive, and only run the backup if it finds that file AND not the other file...

PhilKC
It's not a bug, it's an undocumented and unexplainable feature.
Stick it on your site:
« Last Edit: December 23, 2005, 09:01 PM by PhilKC »

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,261
    • View Profile
    • Donate to Member
Re: IDEA: make script only work if not started from USB stick
« Reply #2 on: December 24, 2005, 07:37 AM »
Edit: IDEA! Put another file, "check.me" on the drive, and only run the backup if it finds that file AND not the other file...
I like the idea, this would easily allow several scripts to use it for this kind of detection too!

Let's see, what our local AHK master, skrommel, thinks about this :)

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,261
    • View Profile
    • Donate to Member
Re: IDEA: make script only work if not started from USB stick
« Reply #3 on: January 02, 2006, 05:03 AM »
Works!

Script looks like this now:

#Persistent
IfExist,D:\data\program files\
SetTimer, X1, 800000
else
return
SetTitleMatchMode, 1
return
#Persistent
X1:
IfNotExist,D:\data\program files\Autohotkey\daily\0815_%A_YYYY%-%A_MM%-%A_DD%.txt
If WinExist("special title")
MsgBox, page already open
Else
{
  Run,IExplore.exe http://www.whatever.bla
  FileCopy,D:\data\program files\Autohotkey\daily\0815_info.txt,D:\data\program files\Autohotkey\daily\0815_%A_YYYY%-%A_MM%-%A_DD%.txt
}
Return