Thread: add your program to start menu ?

  1. #1
    Registered User
    Join Date
    Nov 2002

    add your program to start menu ?

    i am looking for the api to add your program to the windows start menu , so you can select it from there and launch it ? , thanks

  2. #2
    Registered User
    Join Date
    Dec 2006
    Scranton, Pa
    I don't know the procedures for that, but most simply use a program installer (such as inno setup, I think that's the name (free)) which handles that for you. There are probably some other good ones out there as well, but can't think of any other names at the moment.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    create short cut and copy it to the appropriate folder
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  4. #4
    Registered User
    Join Date
    Mar 2005
    Mountaintop, Pa
    Quote Originally Posted by Anddos View Post
    i am looking for the api to add your program to the windows start menu , so you can select it from there and launch it ? , thanks
    // Adds program to startup folder
    #include <windows.h>
    #include <objbase.h>
    #include <shlobj.h>
    #include <objidl.h>
    #include <shlwapi.h>
    #include <stdio.h>
    #pragma comment(lib,"uuid.lib")
    #pragma comment(lib,"ole32.lib")
    #pragma comment(lib,"shell32.lib")
    #pragma comment(lib,"user32.lib")
    HRESULT CreateMyStartupShortcut (
    	LPCTSTR lpCommandLine,
    	LPCTSTR lpArguments,
    	WORD wHotKey,
    	LPCTSTR lpIconLocation,
    	int iIconIndex,
    	int iShow,
    	LPCTSTR lpWorkingDirectory,
    	LPCTSTR lpDescription,
    	LPCTSTR lpLinkName )
    	HRESULT hres;
    	IShellLink *psl;
    	BOOL bUninitializeCom = FALSE;
    	if( (lpCommandLine == NULL) || (lpLinkName == NULL))
    		return E_INVALIDARG;
    	if ( SUCCEEDED(CoInitialize(NULL)))
    		bUninitializeCom = TRUE;
    	hres = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **) &psl);
    	if( SUCCEEDED(hres) )
    		IPersistFile *ppf;
    		psl->lpVtbl->SetPath( psl, lpCommandLine );
    		if( lpDescription != NULL )
    			psl->lpVtbl->SetDescription( psl, lpDescription );
    		if( lpArguments != NULL )
    			psl->lpVtbl->SetArguments( psl, lpArguments );
    		if( wHotKey != 0 )
    			psl->lpVtbl->SetHotkey( psl, wHotKey );
    		if( lpIconLocation != NULL )
    			psl->lpVtbl->SetIconLocation( psl, lpIconLocation, iIconIndex);
    		if( iShow != -1 )
    			psl->lpVtbl->SetShowCmd( psl, iShow );
    		if( lpWorkingDirectory != NULL )
    			psl->lpVtbl->SetWorkingDirectory( psl, lpWorkingDirectory );
    		hres = psl->lpVtbl->QueryInterface( psl, &IID_IPersistFile, (void **) &ppf );
    		if( SUCCEEDED(hres))
    #ifndef UNICODE
    			WCHAR wsz[MAX_PATH];
    			MultiByteToWideChar( CP_ACP, 0, lpLinkName, -1, wsz, MAX_PATH);
    			LPCWSTR wsz = lpLinkName;
    			hres = ppf->lpVtbl->Save( ppf, wsz, TRUE );
    	if (bUninitializeCom)
    	return hres;
    BOOL GetFolderPath(LPTSTR szFolder, int csidlFolder)
    	BOOL         bRet = FALSE;
    	if(SUCCEEDED(SHGetSpecialFolderLocation(NULL, csidlFolder, &pidl)))
    		if(SHGetPathFromIDList(pidl, szFolder))
    			bRet = TRUE;
    	return bRet;
    BOOL AddMeAsAStartupShortcut(LPCTSTR szLinkTitle, LPCTSTR szDescription,
    	LPCTSTR szArguments, int IconResourceID)
    	TCHAR szLinkName[MAX_PATH + MAX_PATH + 10];
    	TCHAR szPathToSelf[MAX_PATH];
    	if (!GetModuleFileName(NULL, szPathToSelf, MAX_PATH))
    		return FALSE;
    	if (FAILED(GetFolderPath(szLinkName, CSIDL_STARTUP)))
    		return FALSE;
    	lstrcat(szLinkName, TEXT("\\"));
    	lstrcat(szLinkName, szLinkTitle);
    	lstrcat(szLinkName, TEXT(".lnk"));
    	return SUCCEEDED(CreateMyStartupShortcut(szPathToSelf, szArguments, 0,
    		IconResourceID != -1 ? szPathToSelf : NULL,
    		IconResourceID, -1, NULL, szDescription, szLinkName));
    int main(void)
    	if (!AddMeAsAStartupShortcut(TEXT("My Demo Program"), TEXT("DemoIt"), NULL, -1))
    		MessageBox(NULL, TEXT("AddMeAsAStartupShortcut Failed to install!!!"), NULL, 0);
    		MessageBox(NULL, TEXT("AddMeAsAStartupShortcut installed successfully!!!"), NULL, 0);
    	return 0;

  5. #5
    Registered User
    Join Date
    Apr 2007
    All the code with IShellLink is in MSDN.
    Just copy-paste...

  6. #6
    Registered User
    Join Date
    Nov 2002
    i am wondering why you are using HRESULT , i am not using directx
    but thanks alot for the example , just what i needed

  7. #7
    Join Date
    Oct 2007
    Inside my computer
    Because it returns a HRESULT.
    It's COM and COM always returns HRESULT.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. How to start program from subfolder
    By trancedeejay in forum C Programming
    Replies: 2
    Last Post: 04-01-2006, 03:39 PM
  3. Best "Menu" method?
    By SSJMetroid in forum Game Programming
    Replies: 11
    Last Post: 12-08-2005, 12:05 AM
  4. Program using menu selection and subprograms
    By hopeolicious in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 12:36 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM