Solved

Run at StartUp option

Posted on 2002-07-10
6
246 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now