Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run at StartUp option

Posted on 2002-07-10
6
Medium Priority
?
264 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
Industry Leaders: 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 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

722 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