Jump to content

Run a file with a semi-unknown path


Go to solution Solved by JohnOne,

Recommended Posts

In my script I've included a button to fix an issue for the user, by running a .reg file that changes the registry.

Now I got this to work because I knew the excact path of the file I wanted to run.. However when I share this I will not know where they place the file.
The file will either be placed like so:

C:usersnamedesktopprogramfolder

Or

C:usersnamedesktopprogramfolderfolderinsidetheprogramfolder

without knowing anything before "Programfolder"

I would prefer second option so it's in another folder than the .exe.

Now I have no way of knowing what drive, what the user is called, or where they place it on the drive.

So I have to find a way to run it even though it doesnt know that.

I have searched the forum for maybe 1-2 hours

looked at the help file for 4 hours

and I found _fullpath etc

but it just doesnt make sense to me.

I've read on of the dev's soloution but I just dont want to C&P something, I want to understand it.. if it makes sense, and I had no idea what all the values did etc.

Is there an easy way or is it incredible hard?

Case $ButtonFixWinAcc
          $MsgBoxWinAcc = MsgBox(35, "Windows Version", "Yes means Windows 8 - No means Windows 7")
          If $MsgBoxWinAcc = 6 Then
                Run("C:\Users:\MYNAME\desktop\HCC\Windows8andHigher.reg")
         ElseIf $MsgBoxWinAcc = 7 Then
                Run("c:\users:\myname\desktop\HCC\Windows7andLower.reg")
         EndIf

Also out of curiosity

how much harder (if possible) 

is it to run the file IF you have no idea whatsoever where it is ?

I think I need something in this direction:

Local $filePath $filePath = _PathFull("Folder\File.txt", @AppDataDir)
MsgBox (0, "Path", $filePath)

I'm aware that this is a bit helpless ish becuase I don't really have anything, because every try I did has completely failed, and after like 10 hours of trying this.. I'm a bit short on focus. So if someone could point me in the right direction or something you would save my day

Edited by Srex
Link to comment
Share on other sites

Local $sFileSelectFolder = FileSelectFolder("Select file location", "")

If Not @error Then
    $sFilePath = $sFileSelectFolder & '\file.reg'
    Exit MsgBox(0, 'File Path', $sFilePath)
EndIf ;==>

Exit MsgBox(0, 'File Path', 'Error')

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Local $sFileSelectFolder = FileSelectFolder("Select file location", "")

If Not @error Then
    $sFilePath = $sFileSelectFolder & '\file.reg'
    Exit MsgBox(0, 'File Path', $sFilePath)
EndIf ;==>

Exit MsgBox(0, 'File Path', 'Error')

 

Actually helped me alot with another problem so thanks alot for that :)!

Seems like it asks the user WHERE the file is, is it possible for it to simply using the variable to run it using this method?

Link to comment
Share on other sites

Hmm I applied this and it doesn't seem to run the desired files

Its a fix for mouse acceleration so if a user is asked about his windows.

Atm I just did it with yes/no

so yes (return 6) = win 8

no (return 7) = win 7

I tried to run it within the while 1

also tried to call it in by making it a func first:

Case $ButtonFixWinAcc
            $MsgBoxWinAcc = MsgBox(4, "Windows Version", "Yes Windows 8 - No Windows 7")
            If $MsgBoxWinAcc = 6 Then
                Win8MouseFixDir()
ElseIf $MsgBoxWinAcc = 7 Then
                $FixRegWin7 = @ScriptDir & '\Windows7andLower.reg'
                Run($FixRegWin7)
            Else
                MsgBox(0, "Error", "Uknown Error. Try Again.")
            EndIf

This displays the 2 methods I tried this is inside the While 1 .

The func looks like:
 

Func Win8MouseFixDir()
    $sFilePath = @ScriptDir & '\Windows8andHigher.reg'
    Run($sFilePath)
EndFunc

I have no idea how this can cause me so many troubles -.- sorry.

Edited by Srex
Link to comment
Share on other sites

Okay sorry.

http://puu.sh/9ihks/26455a1810.png

This is the section of my GUI.

I would like when the user Clicks Fix ( so it fixes windows acc for the user automaticly )

the fix varies from windows versions

There is a fix for windows 8 and later

and a fix for  windows 7 and earlier

When user clicks button fix:

A yes/no (for now) msgbox pops up asking the user if his windows is windows 8 or newer,

If yes it should apply the "Windows8andLater.reg" fix

if no it should apply the "Windows7andEarlier.reg" fix

The reg file is in the same folder as the script.

Or in the '"ressource'" folder

LIke shown here:

http://puu.sh/9ihGr/f7c17b2815.png

Excuse my english in that picture 

Edited by Srex
Link to comment
Share on other sites

  • Solution

;If user selects win8+
$filepath = _GetPath(1)

;If not
$filepath = _GetPath()


Func _GetPath($win8 = 0)
    Local $File = '\Windows7andEarlier.reg'
    
    If $win8 Then 
        $File = '\Windows8andLater.reg'
    EndIf
    
    If FileExists(@ScriptDir & $File) Then
        Return @ScriptDir & $File
    EndIf
    
    If FileExists(@ScriptDir & '\resources' & $File) Then
        Return @ScriptDir & '\resources' & $File
    EndIf
    
    Return SetError(1, 0, '')
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Have tried now for a good 5 hours -.-
And nomatter what i try to tweak it just doesnt work for me.

Could it because the file doesn't have a digital sig and then needs some kind of special permission?

 

http://imgur.com/Z7vfz6B

Here's where I call it to

Case $ButtonFixWinAcc
            $MsgBoxWinAcc = MsgBox(4, "Windows Version", "Yes Windows 8 - No Windows 7")
            If $MsgBoxWinAcc = 6 Then
                $FilePath = _GetPath(1)
            ElseIf $MsgBoxWinAcc = 7 Then
                $FilePath = _GetPath()
            EndIf

Here's the func I call 

Func _GetPath($win8 = 0)
    Local $File = '\Windows7andEarlier.reg'

    If $win8 Then
        $File = '\Windows8andLater.reg'
    EndIf

    If FileExists(@ScriptDir & $File) Then
        Return @ScriptDir & $File
    EndIf

    If FileExists(@ScriptDir & '\Resources' & $File) Then
        Return @ScriptDir & '\Resources' & $File
    EndIf

    Return SetError(1, 0, '')
EndFunc   ;==>_GetPath

It asks for what windows version, nomatter what I press nothing happens whatsoever.

EDIT: Actually doesnt it seem like I just tell it the loc? And not to run it xD

Just going to try that 

Edit2: hmm seems like that didn't help either

Edited by Srex
Link to comment
Share on other sites

Try this for the function

Func _GetPath($win8 = 0)

    Local $File = ""


    If $win8 Then
        $File = @ScriptDir & '\Windows8andLater.reg'
    Else
        $File = @ScriptDir & '\Resources\Windows7andEarlier.reg'
    EndIf

    If FileExists($File) Then
        Return $File
    Else
        Return SetError(1, 0, '')
    EndIf
EndFunc   ;==>_GetPath

It's a little cleaner and you should be able to follow the code flow a lot better.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Nothing wrong with those functions.

It's running the file is it not?

Sorry mate it's not, I tried to place it in the resource folfder and in the folder with the script..

Does it need to be .exe to execute it ?

 

Link to comment
Share on other sites

Try this for the function

Func _GetPath($win8 = 0)

    Local $File = ""


    If $win8 Then
        $File = @ScriptDir & '\Windows8andLater.reg'
    Else
        $File = @ScriptDir & '\Resources\Windows7andEarlier.reg'
    EndIf

    If FileExists($File) Then
        Return $File
    Else
        Return SetError(1, 0, '')
    EndIf
EndFunc   ;==>_GetPath

It's a little cleaner and you should be able to follow the code flow a lot better.

 

 

Try this for the function

Func _GetPath($win8 = 0)

    Local $File = ""


    If $win8 Then
        $File = @ScriptDir & '\Windows8andLater.reg'
    Else
        $File = @ScriptDir & '\Resources\Windows7andEarlier.reg'
    EndIf

    If FileExists($File) Then
        Return $File
    Else
        Return SetError(1, 0, '')
    EndIf
EndFunc   ;==>_GetPath

It's a little cleaner and you should be able to follow the code flow a lot better.

Okay I'll give it a shot

Link to comment
Share on other sites

Nothing wrong with those functions.

It's running the file is it not?

It's not running at all no.

Does it need to be .exe to do so?

I tried both folders mate

Try this for the function

Func _GetPath($win8 = 0)

    Local $File = ""


    If $win8 Then
        $File = @ScriptDir & '\Windows8andLater.reg'
    Else
        $File = @ScriptDir & '\Resources\Windows7andEarlier.reg'
    EndIf

    If FileExists($File) Then
        Return $File
    Else
        Return SetError(1, 0, '')
    EndIf
EndFunc   ;==>_GetPath

It's a little cleaner and you should be able to follow the code flow a lot better.

Ok I'll try thanks

Link to comment
Share on other sites

ShellExecute

 

Works now for the windows7.

Just need to get windows8 to work now

I thought ShellExecute was only for webpages.. Read that part too quickly.

Thanks :D !!

Now that we're on topic.

BrewManNH said his was 'cleaner' will that mean that your program will be faster the less lines there is right?

Or is number of lines not nescessarily equal to how fast / effective the program is?

Edited by Srex
Link to comment
Share on other sites

Try this for the function

Func _GetPath($win8 = 0)

    Local $File = ""


    If $win8 Then
        $File = @ScriptDir & '\Windows8andLater.reg'
    Else
        $File = @ScriptDir & '\Resources\Windows7andEarlier.reg'
    EndIf

    If FileExists($File) Then
        Return $File
    Else
        Return SetError(1, 0, '')
    EndIf
EndFunc   ;==>_GetPath

It's a little cleaner and you should be able to follow the code flow a lot better.

Yeah I think that would be easier for me to understand sir :)! Thanks

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