Solved

Set default working folder to the application folder

Posted on 2003-11-11
5
324 Views
Last Modified: 2010-05-01
Hi

When i'm deploying a program i need to read from a file. For some reason the default working directory is "c:\documents and settings\my name"
and not "My Documents" which is the users personal data folder in the deployment project.

How do i set the default working folder to be e.g. the application folder (where the .exe file resides) for the program. I can't set it hardcoded in the code coz i don't know the exact path on the target computer.

I'd rather not dump files in the documents and setting folders or especially the My Documents folder since then the files might accidently be deleted by user. I'd rather use the application folder.

Thanks

KjartanM-S
0
Comment
Question by:KjartanM-S
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:tim_mcgue
Comment Utility
Have you tried:

CurDir

See this URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctcurdir.asp

If you are using vbscript instead of VB it is:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.CurrentDirectory 'this is the directory where the script was launched
0
 

Author Comment

by:KjartanM-S
Comment Utility
HI

Sorry, my fault for not specifying properly. I'm developing in VB.NET and have used the getCurrentDirectory call there (equal to CurDir in VB i think). When program is deployed and running it returns the c:\Documents and Settings\KjartanM-S.

I'd rather it be something like
"c:\program files\my program"
where the .exe file is (or as the deployment calls it - application folder)
Problem is that i don't know the exact path on the target computer, depending on where he chooses to install the program.

I need to find the exact path of the application folder on once the program is deployed and running.

KjartanM-S
0
 
LVL 28

Expert Comment

by:vinnyd79
Comment Utility
Is there an app.path equivalent in .Net?

Dim myFile As String
If Right$(App.Path, 1) <> "\" Then
    myFile = App.Path & "\SomeFile.txt"
Else
    myFile = App.Path & "Somefile.txt"
End If

0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 500 total points
Comment Utility
0
 

Author Comment

by:KjartanM-S
Comment Utility
vinnyd79

Thanks.....the link you provided answered my question about the startup path.

A note on my problem though.....following the instructions in a book on how to create a folder in your programs menu with link to program in the deployment project.....it actually said to included the .exe files in this folder which then created two instances of the .exe file. This one pointing to the documents and setting folder when using getCurrentDir.
Rather than including the .exe file one create a shortcut from the primary outputs in application folder and then copy this one to the programs menu folder. Then you get a proper shortcut here and the .exe file from the application folder is launched and getCurrentDir will return the same as application.startUpPath

KjartanM-S
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now