Solved

how do i add my application in the start up

Posted on 1999-01-14
3
171 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
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 100 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

823 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