Jump to content

running my script not from c:\


 Share

Recommended Posts

can i restrict my script not to run from @HomeDrive (commonly c:\ Drive) ? like from Desktop, Documents folder, ProgramFiles or any other directory which is in C:\. but it should always work if the path is D:\ or D:\New Folder\Set.

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to comment
Share on other sites

How about this?

If StringLeft(@ScriptDir, 2) = @HomeDrive Then
    MsgBox(0,"", "Running from home drive")
    Exit
EndIf
MsgBox(0,"", "Not running from home drive")
nice idea, but what if i only want to restrict Program Files directory only? i have just changed my idea!
Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to comment
Share on other sites

Use the same idea, but check out the macro @ProgramFilesDir.

Edit: oops beaten to it, but I would still use the macro. (Program Files dir may not always be C:\Program Files)

it will not work if the file is running from

C:\Program Files\MY FOLDER

C:\Program Files\ETC\1234

C:\Program Files\New Directory\First Folder

it will only work if the file is running from only

C:\Program Files\

C:\Program Files

what should i do now?

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to comment
Share on other sites

If not StringInstr(@ScriptDir, @ProgramFilesDir) Then
    MsgBox(0,"", "Not running from inside Program Files")
    Exit
EndIf
MsgBox(0,"", "Runing from " & @ScriptDir & "which is inside" & @ProgramFilesDir)

This program has a small bug that I will leave for you to find. It should never happen in real life, but as a programmer, you should learn to watch out for this type of bug.

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...