How to create a file association program?

This is a discussion on How to create a file association program? within the Windows Programming forums, part of the Platform Specific Boards category; Hello everyone! Recently, at my job, I've been getting fairly involved with Microsoft Access database design and implentation. However, I'm ...

  1. #1
    Registered User eShain's Avatar
    Join Date
    Mar 2006
    Location
    Texas
    Posts
    1

    Question How to create a file association program?

    Hello everyone! Recently, at my job, I've been getting fairly involved with Microsoft Access database design and implentation. However, I'm not a programmer, I know nothing about programming! Despite my ignorance, I need to create a simple program, and I'm hoping the cprogramming.com faithful can lead this horse to water!

    If I'm in the wrong forum, feel free to correct my error.

    The function of this program would be to simply:

    1) Open
    2) Display one button, that when pressed, will automatically create a shortcut to a particular .exe file (found from another network drive, we'll call it JPGopener.exe) on the user's desktop. As well as, automatically create a windows file association for, all ".jpg" files to open with the JPGopener.exe application by default.

    The purpose of this program is for certain people who use computers on our Windows XP network system, that have no idea how to create a file association to a particular program! I'd like to create the proverbial "one-click" program, to stop getting phone calls and having to walk them through it, every time!

    If anyone has any ideas which software (Visual Basic?) or programming language (C, C++ ?) would be the easiest to complete this project, I'd be extremely grateful!

    If needed, please email me at webmaster@eshain.com

    Thanks for your time,
    Shain

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    You'll have to create the "one button" GUI to execute the Shortcut function. Also, you'll have to verify that the network path to the executable, JPGopener.exe is available. Finally, Creating File Associations

    Creating desktop shortcut sample:
    Code:
    // Compile as follows:
    // CL /MT MyCode.cpp ole32.lib
    
    #include <afxole.h>
    #include <shlobj.h>
    
    HRESULT Shortcut(const CString ExecutableName, const CString ExecutableArguments, const CString
    	LinkName)
    {
    	HRESULT hres;
    	CString Desktop=getenv("USERPROFILE");  //Get the path to the desktop
    	Desktop += "\\Desktop\\";
    	CString Link = Desktop + LinkName;
    
    	IShellLink* pIShellLnk;
    	hres = CoInitialize(NULL);
    	hres = CoCreateInstance(CLSID_ShellLink, 
    		NULL, 
    		CLSCTX_INPROC_SERVER, 
    		IID_IShellLink,
    		(LPVOID*) &pIShellLnk);
    	IPersistFile* pIPersist;
    	pIShellLnk->SetPath(ExecutableName);
    	pIShellLnk->SetArguments(ExecutableArguments);
    	hres = pIShellLnk->QueryInterface( IID_IPersistFile, 
    		(LPVOID *) &pIPersist);
    	if (SUCCEEDED(hres))
    	{
    		CString Temp = Link;
    		Temp.MakeLower();
    		if (Temp.Find(".lnk")==-1) 
    			Link += ".lnk";  
    		WORD wString[MAX_PATH];
    		MultiByteToWideChar(CP_ACP, 
    			MB_PRECOMPOSED, 
    			Link, 
    			-1, 
    			wString,
    			MAX_PATH);
    		hres = pIPersist->Save(wString, TRUE);
    		pIPersist->Release();
    	}
    	else
    		pIShellLnk->Release();
    	return hres;
    }
    
    int main(void)
    {
    	Shortcut("notepad.exe", "", "My Notepad");
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21