• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

how do i add my application in the start up

i want to add my application in the start up menu of windows
programatically in windows. How can i do it ?
0
chari112598
Asked:
chari112598
1 Solution
 
nil_dibCommented:
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
 
ZoppoCommented:
// 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
 
chari112598Author Commented:
I will have to try it out before any more comments.
0

Featured Post

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now