DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

brotherS

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

Code
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?
Thank you.

PhilKC

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 117
    • Coding Snacks
Re: IDEA: make script only work if not started from USB stick
« Reply #1 on: December 23, 2005, 11: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 24, 2005, 03:01 AM by PhilKC »

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,261
Re: IDEA: make script only work if not started from USB stick
« Reply #2 on: December 24, 2005, 01:37 PM »
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 :)
Thank you.

brotherS

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

Script looks like this now:

Code
#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
Thank you.

Original address: https://www.donationcoder.com/forum/index.php?topic=1904.0