?
Solved

how do i add my application in the start up

Posted on 1999-01-14
3
Medium Priority
?
176 Views
Last Modified: 2010-04-02
i want to add my application in the start up menu of windows
programatically in windows. How can i do it ?
0
Comment
Question by:chari112598
[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
3 Comments
 
LVL 4

Expert Comment

by:nil_dib
ID: 1182213
You can create a shortcut in your startup(autostart) folder ....
Look for IShellLink and sample 'Creating a Shortcut to a File' (MSVC++)
the other option is to run your app as a service

0
 
LVL 31

Accepted Solution

by:
Zoppo earned 300 total points
ID: 1182214
// call this once while initializing your app
CoInitializeEx( NULL, COINIT_MULTITHREADED )

// get path for startup menu from registry
// for non user localized startup menu, replace HKEY_CURRENT_USER with
// HKEY_LOCAL_MACHINE and "Startup" with "Common Startup"

HKEY hkey;
char szLink[MAX_PATH];
DWORD lpType;
ULONG ulSize = MAX_PATH;

RegOpenKeyEx(
    HKEY_CURRENT_USER,
    "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
    0,
    KEY_QUERY_VALUE,
    &hKey
    );
RegQueryValueEx(
    hKey,
    "Startup",
    NULL,
    &lpType,
    (unsigned char *)&szLink,
    &ulSize
    );
RegCloseKey(
    hKey
    );

// creating the link using IShellLink & IPersistFile.
// yourAppName : name of your .exe, i.e. "MyApp.exe"
// yourAppPath : path to your app, i.e. "C:\\Programs\\MyAppPath"


CString lnkPath;
CString appPath;
CString description;
lnkPath.Format( "%s\\%s", szLink, yourAppName );
appPath.Format( "%s\\%s", yourAppPath, yourAppName );
description.Format( "Link to %s", yourAppName );

HRESULT hres;
IShellLink* psl;
hres = CoCreateInstance(
    CLSID_ShellLink,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IShellLink,
    &psl
    );
if (SUCCEEDED(hres))    
{
    IPersistFile* ppf;
    hres = psl->QueryInterface(IID_IPersistFile, &ppf);
    if (SUCCEEDED(hres))      
    {
        WORD wsz[MAX_PATH];
        hres = psl->SetPath( (LPCTSTR)appPath);
        if (!SUCCEEDED(hres))
            AfxMessageBox("SetPath failed!");
        hres = psl->SetDescription( (LPCTSTR)descrition);
        if (!SUCCEEDED(hres))
            AfxMessageBox("SetDescription failed!");
        MultiByteToWideChar(
            CP_ACP,
            0,
            (LPCSTR)lnkPath.GetBuffer( lnkPath.GetLength() ),
            -1,
            wsz,
            MAX_PATH
            );
        hres = ppf->Save(wsz, TRUE);    
        ppf->Release();
    }
}
psl->Release();    

This seems to be very complicated, but this seems to work fine with both NT4 and 9x.
I found this within MSDN in an article named "Using Shell Links in Windows 95".

hope this helps,

ZOPPO
0
 

Author Comment

by:chari112598
ID: 1182215
I will have to try it out before any more comments.
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

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…
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 …
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.
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.
Suggested Courses

762 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