Solved

Run at StartUp option

Posted on 2002-07-10
6
243 Views
Last Modified: 2010-05-18
I am using Borland C++ Builder 4.0 Pro.

I am trying to add an option to an application on a 'preferences' form using a checkbox that the user can either have the app load on Windows Starup, or not.  I am having no luck at all.  I have tried a Registry Entry that does not function.  I have looked all over the web, my reference books, and the Borland Newsgroups.  I am hoping that someone here can help me out.

I have come to realize that it seems that if I can add (and delete) a shortcut into the Windows Startup directory, then I will have the functionality that I need.

All I need is some sort of an example function I can study, or a snippet of someone's code that I can look at. So I can add this option via a checkbox.

Thank you in advance for any help offered.


0
Comment
Question by:LordDamein
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7144933
The easiest way would be to place an entry under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run - it has to be of the form

"Arbitrary Value Name" = "c:\\mypah\\myprog.exe"
0
 
LVL 86

Expert Comment

by:jkr
ID: 7144937
BTW, if you want to delve deeper into where to place entries to run a program at startup, get check out "Autoruns" and get the source code ar http://www.sysinternals.com/ntw2k/source/misc.shtml#autoruns
0
 

Author Comment

by:LordDamein
ID: 7144995
I have tried going through the Registry, without success.  I have placed my entry in both HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run  and HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run.  Neither work.  I can get my app to show up in Start -> Run -> MsConfig | Startup, but yet the app does not start.

I manually put a shortcut into the Run->Programs->StartUp directory and that works perfectly, therefore I am looking for a way to add (and delete) a shortcut into that directory through my app, with a checkbox.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Accepted Solution

by:
ambience earned 250 total points
ID: 7145153
Well i cannot understand why the registry approach doesnt work, are you sure you are specifying the correct path ?

StartMenu approach is preferred over registry one when you want the user to be able to "see" that the app is being started up. Its more like user consent etc.

You can create a shortcut programatically as follows, this is VC specific code , you have to change it to BC specific

BOOL CreateShortcut(CString linkFileName, CString linkToFile)
{
     HRESULT hres;
     IShellLink* pIShellLink;

     hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
     IID_IShellLink, (LPVOID *)&pIShellLink);

     if (SUCCEEDED(hres))
     {
          IPersistFile *pIPersistFile;
          hres = pIShellLink->SetPath(linkToFile);
          if (!SUCCEEDED(hres))
          hres = pIShellLink->QueryInterface(IID_IPersistFile,
          (LPVOID *)&pIPersistFile);

          if (SUCCEEDED(hres))
          {
               USES_CONVERSION;
               hres = pIPersistFile->Save(T2OLE(linkFileName), TRUE);
               pIPersistFile->Release();
          }

          pIShellLink->Release();
     }
        return TRUE;
}

linkFileName should be path to startmenu which can be found by using

SHGetSpecialFolderPath with CSIDL = CSIDL_STARTMENU.

hope this helps ..
0
 
LVL 22

Expert Comment

by:ambience
ID: 7145155
>> linkFileName should be path to startmenu which can be found by using

i wanted to say linkFileName should be path to startmenu plus link name.

There are other paramters for the link that you can set thru IShellLink, see MSDN for details.

0
 

Author Comment

by:LordDamein
ID: 7150061
Thank you for the help.  If I could have added a comment to the original question, I would have asked for some help in reversing (deleting) the CreateShortcut function.  I am having a rough time trying to delete it, or getting information on how to go about that.

Well, thanks though for the info.  :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 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

21 Experts available now in Live!

Get 1:1 Help Now