Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to run my program on startup

Status
Not open for further replies.

samibami

Programmer
Oct 12, 2003
28
0
0
IL
i want to add to my program the option to run on startup.
i know i can use the registry to do that.the problem is i don't know where the user will put the executable file.i don't use install shield at all.

on borland c++ builder5:
how can the executable know its own location,so it can update the path to the registry run on startup key?

is there an easier way?

 
put it in registry:
HKCU/SoftWare/Microsoft/Windows/Current Version/Run

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Ion Filipski

10x 4 replaying so fast. but,
you should read all the way before you answer.
registry needs the path of the executable.
the path could be anything (anywhere the user decides to put the program).i need to know how the executable can retrieve its own path.

10x again
samibami
 
use GetModuleFileName( 0,....
instead of 0 you can use GetModuleHandle(0) or hInstance

or GetProcessImageFileName(hProcess, ....


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
thanks, that worked greate.

where can i find a reference to functions
like GetModuleFileName and other?
 
in MSDN

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I've written special for you a short sample:
Code:
#include<windows.h>
#include<iostream>
using namespace std;
int main()
{
    char xx[1024];
    GetModuleFileName(NULL, xx, 1024);
    //instead of null you can put GetModuleHandle(0)
    //or hInstance if you have it
    
    cout<< xx<< endl;
    return 0;
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
>butthead
getcwd (); returns the current directory,
not the programs directory. Supposing the following scenarios, you have theNeededProg.exe what uses getcwd()
to know where are configuration files; for example, you type in command line:

cd c:\works
&quot;d:\Program Files\theNeededProgDir&quot;\theNeededProg.exe

the function getcwd will return c:\works, but the programs directory is &quot;d:\Program Files\theNeededProgDir&quot;. So if program uses getcwd to find it's configuration files what are in programs directory, it will get a wrong path.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top