Solved

Run at StartUp option

Posted on 2002-07-10
6
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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