Solved

how do i add my application in the start up

Posted on 1999-01-14
3
167 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
Comment Utility
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 30

Accepted Solution

by:
Zoppo earned 100 total points
Comment Utility
// 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
Comment Utility
I will have to try it out before any more comments.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now