Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Run at StartUp option

Posted on 2002-07-10
6
Medium Priority
?
267 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

927 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