// ExecutableRunner.cpp : Defines the entry point for the console application. // #define UNICODE #include "stdafx.h" #include #include #include #include #include #include #include #include #include using namespace std; #define PATH_SIZE 512 // Headers void RunExecutable(_TCHAR* path, _TCHAR* program); bool IsDotNet2Installed(); int _tmain(int argc, _TCHAR* argv[]) { _TCHAR path[PATH_SIZE]; // find the index of the last "\" or "/" int length = _tcsclen(argv[0]); int endOfPath = -1; for(int i = length-1; i > -1; i--) { if(argv[0][i] == _T('/') || argv[0][i] == _T('\\')) { endOfPath = i; argv[0][i] = _T('\0'); break; } } // this can be called without the PATH_SIZE - why? _tcscpy_s(path, PATH_SIZE, argv[0]); RunExecutable(path, _T("dotnetfx.exe")); return 0; } // Runs an executable. The path should have enough room to append // the program name at the end of it. This may be changed in future // versions, but for now, this is a small program, and this will work fine void RunExecutable(_TCHAR* path, _TCHAR* program) { _tcscat(path, _T("\\")); _tcscat(path, program); ShellExecute(NULL, _T("open"), path, _T(""), _T(""), SW_SHOW); } bool IsDotNet2Installed() { struct _tstat buffer; _TCHAR* pathOfInterest = _T("%systemroot%\\Microsoft.NET\\Framework\\v2.0.50727"); bool exists = _tstat ( "filename", &buffer ); return exists; }