Jump to content
Sign in to follow this  
arminius

working directory not being @scriptdir

Recommended Posts

arminius

ok, I want to change the working directory from the @scriptdir, to somewhere else

here is the code

CODE
While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1

ShellExecute("Good.au3", "", @C:\Documents and Settings\Bill\My Documents\Scripts\Screensaver, "Run")

Case $msg = $Button_2

ShellExecute("Bad.au3", "", @ScriptDir, "Run")

Case $msg = $Button_3

ShellExecute("Surreal.au3", "", @ScriptDir, "Run")

EndSelect

Wend

buttons 2 and 3 are the old ones and they work, button 1 is what I wanna do, but it's not working, I looked through all the help file and the solution didn't jump out at me so your help is appritiated

Share this post


Link to post
Share on other sites
herewasplato

First, the working directory does not "help" the ShellExexute function "find" the file named "Good.au3" --- but you might actually already understand that. If you are changing from a marco like @ScriptDir to text, you need quotes around that text... and, seeing as how you have a path with a space in it, you may need to play with double quotes and single quotes. I'm the MSP atm.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
arminius

thanks, worked perfectly

Share this post


Link to post
Share on other sites
MHz

First, the working directory does not "help" the ShellExexute function "find" the file named "Good.au3" --- but you might actually already understand that.

I am probably going to confuse you here :) . AFAIK, ShellExecute() tells the system shell to execute the file and when you tell the shell to use a working directory, then that is where it looks amongst other places associated in the registry and system path etc. It can can be similar to using Run() with @Comspec and setting a working directory with it so that @Comspec can find a filename (only) passed to it in the working directory that you passed to @Comspec using Run(). That is my current understanding of the working directory parameter used in ShellExecute() and the example below confirms the behavior.

Example tested working on XP

$file = 'test.cmd'
$path = @TempDir
FileDelete($path & '\' & $file)
FileWrite($path & '\' & $file, _
        '@echo off' & @CRLF & _
        'echo FilePath=%0' & @CRLF & _
        'echo WorkingDir=%cd%' & @CRLF & _
        'pause')
ShellExecuteWait('"' & $file & '"', '', $path)

Exit

Func OnAutoItExit()
    FileDelete($path & '\' & $file)
EndFuncoÝ÷ Ú«¨µ

and output is

FilePath="C:\Program Files\7-Zip\test.cmd"

WorkingDir=C:\Program Files\7-Zip

Press any key to continue . . .

It seems to work in any directory that I choose including paths on a drive separate from the system drive so the behavior seems constant.

:P

Share this post


Link to post
Share on other sites
herewasplato

..

I am probably going to confuse you here :) ...

Thanks for your kind correction. Sadly, I don't know where I got that idea from.

I stand corrected - well, I'm not actually standing :-)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
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
Sign in to follow this  

×