Solved

how do i add my application in the start up

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

713 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