Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------
- //Run in new console
- //---------------------------------------------------------
- #include <windows.h> //You need shell32.lib for this one
- bool main() {
- LPCWSTR szPath = TEXT("C:\\WINDOWS\\system32\\Calc.exe");
- HINSTANCE hRet = ShellExecute(
- HWND_DESKTOP, //Parent window
- TEXT("open"), //Operation to perform
- szPath, //Path to program
- NULL, //Parameters
- NULL, //Default directory
- SW_SHOW); //How to open
- /*
- The function returns a HINSTANCE (not really useful in this case)
- So therefore, to test its result, we cast it to a LONG.
- Any value over 32 represents success!
- */
- if((LONG)hRet <= 32)
- {
- MessageBox(HWND_DESKTOP,TEXT("Unable to start program"),TEXT(""),MB_OK);
- return true;
- }
- system("pause");
- return true;
- }
- //---------------------------------------------------------
- //Run inside console
- //---------------------------------------------------------
- #include <iostream>
- #include <windows.h>
- bool main() {
- WinExec("C:\\WINDOWS\\system32\\Calc.exe",SW_SHOW);
- system("pause");
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement