What is a "Current Working Directory"? Windows maintains an internal working directory for every program running. The working directory is used for accessing any relative filenames, however it has no effect when accessing absolute filenames.
Example Relative Filenames ..\test.dat
subdir\test.dat
Example Absolute Filenames c:\mydir\test.dat
c:\mydir\subdir\test.dat
\\netshare\test.dat Depending on how your program is run, the current directory will vary. If your program is run by Internet Explorer Directory from a download link, the current working directory can be any value. If the program is run from the command line, it may also start with any working directory. If your program accesses filenames using relative paths this may cause it to fail.
How to control the "Current Working Directory" using Thinstall.
By default Thinstall does not change the Current Working Directory when your program is run. This behaviour can be changed by using the Menu option from the "Link" pulldown menu.
By unchecking "Use system supplied current working directory", you can specify your own starting current working directory. If this value is "%InstallPath%", then the current directory becomes the same directory where the EXE file is located.
When should I change the current working directory?
If your program accesses files using relative filenames, then it may fail to work properly if run from a different directory than your EXE is located in. Your EXE may be run with a different current working directory in the following situations:
·
When run from the command line
·
When run directly from an Internet Explorer download link.
·
When run from a program shortcut with a different starting directory.
OpenFile("mydata.txt"); // this statement will fail if mydata.txt is not in the current directory.
When should I *not* change the current working directory?
If your program accepts command-line parameters which include filenames, then changing the current working directory may invalidate the relative path supplied by the user.
How can I open virtual files using absolute path names?
If you do not want to change the current working directory, but still want to access virtual filenames, you must use absolute filenames. Thinstall allows virtual files to be located at any path, even if it does not exists on the hard drive. This allows you to use virtual filenames such as "x:\test.dat" both in Thinstall and in your program. Alternatively if you want to use %InstallPath% so the virtual files always appear to be in the same directory as your EXE,
you can obtain the value of %InstallPath% and prepend this before all of your filenames.