Solved

Set default working folder to the application folder

Posted on 2003-11-11
5
327 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
ID: 9726682
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
ID: 9726779
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
ID: 9726789
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
ID: 9727064
0
 

Author Comment

by:KjartanM-S
ID: 9727134
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 73
Hide vba in gp 7 104
Macro Excel - Multiple If conditions 2 81
pop out of webbrowser1 control vba6 5 25
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

860 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