Jump to content

Run a compiled Autoit exe only from specified folder


Willow
 Share

Recommended Posts

Is it possible for a compiled autoit executable to be only run from a specified folder. For example: the .exe is in c:\myfolder and when launched, checks to see if the folder is named c:\mysavedprograms. If not, a msgbox will prompt the user to the effect "This program can only be run from c:\mysavedprograms" then exit the program.

I checked the help files and searched the forum but did not find anything regarding this specific scenario.

Thanks

Willow

Edited by Willow
Link to comment
Share on other sites

Have a look at FileExists() and @AutoItExe. You can see if it is being executed from the correct path upon load up then exit if it is not.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Have a look at FileExists() and @AutoItExe. You can see if it is being executed from the correct path upon load up then exit if it is not.

Thanks, I ended up using @scriptdir. Not sure if this is the most elegant method as compared to your suggestion....

If @ScriptDir <> "c:\mysavedprograms" Then
MsgBox(16, "Stop", "This program can only be run from c:\mysavedprograms", @ScriptDir)
exit

Else
EndIf
Link to comment
Share on other sites

That works well. For a profesional look, I would use tidy. It comes with the fill version of Scite. The Else is not required.

This is easier to read.

If @ScriptDir <> "c:\mysavedprograms" Then
    MsgBox(16, "Stop", "This program can only be run from c:\mysavedprograms", @ScriptDir)
    Exit
EndIf

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Or you could do it with 1 line, for example like so=

If @ScriptDir <> "c:\mysavedprograms" Then Exit MsgBox(16, "Stop", "This program can only be run from c:\mysavedprograms", @ScriptDir)

(from 6 to 1 lines, talk about compressing! :) )

Link to comment
Share on other sites

If you dont want to pop a message box you can also use a tray tip to send a message to the user which pops above the AutoIT or your own icon assignment that appears on the Windows notification taskbar: You can have any number of messages inbedded at intervals within your script showing events and progress which uses one piece of code to produce the display. You can also use the same stratgy for 'splashtexton'

;//Message 1

_MessageDisplay("STARTUP ")

;//Message 2

_MessageDisplay("SHUTTING DOWN ")

Func _MessageDisplay($Message)

sleep(500) ;Time Delay between Multiple Messages

TrayTip("", $Message, 5)

Sleep($Duration * 100)

TrayTip("Clear Previous TrayTip","",0)

EndFunc ;==>_MessageDisplay

Edited by anixon
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...