execute an app from code
-
I have an app that I want to run (dtsrun.exe) I can run it from the command line, but how do I do that in code with the specified switches? I know in vb I could use the ShellExecute() function, but how do I do that in C++ if I want to run this: 'dtsrun /S localhost /p jt'? thanks in advance for any help!! If it's broken, I probably did it bdiamond
-
I have an app that I want to run (dtsrun.exe) I can run it from the command line, but how do I do that in code with the specified switches? I know in vb I could use the ShellExecute() function, but how do I do that in C++ if I want to run this: 'dtsrun /S localhost /p jt'? thanks in advance for any help!! If it's broken, I probably did it bdiamond
hi, in c++ you also use ShellExecute(), and it is quite easy to use, here is the online MSDN link i found: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp --- kick ash. http://sprdsoft.bigmoron.com http://t1tan.cjb.net
-
I have an app that I want to run (dtsrun.exe) I can run it from the command line, but how do I do that in code with the specified switches? I know in vb I could use the ShellExecute() function, but how do I do that in C++ if I want to run this: 'dtsrun /S localhost /p jt'? thanks in advance for any help!! If it's broken, I probably did it bdiamond
Don't remember where I picked this up but most likely somewhere here...Best site around!!
BOOL LaunchChild(LPCSTR lpszCmdLine, BOOL bShowChildWindow) { HANDLE hProcess = ::GetCurrentProcess(); PROCESS_INFORMATION pi; // Set up the start up info struct. STARTUPINFO si; ::ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; // Note that dwFlags must include STARTF_USESHOWWINDOW to // use the wShowWindow flags. si.wShowWindow = bShowChildWindow ? SW_SHOW: SW_HIDE; // Create the NULL security token for the process LPVOID lpSD = NULL; LPSECURITY_ATTRIBUTES lpSA = NULL; lpSD = ::GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); ::InitializeSecurityDescriptor(lpSD, SECURITY_DESCRIPTOR_REVISION); ::SetSecurityDescriptorDacl(lpSD, -1, 0, 0); lpSA = (LPSECURITY_ATTRIBUTES)::GlobalAlloc(GPTR, sizeof(SECURITY_ATTRIBUTES)); lpSA->nLength = sizeof(SECURITY_ATTRIBUTES); lpSA->lpSecurityDescriptor = lpSD; lpSA->bInheritHandle = TRUE; // Try to spawn the process. BOOL bResult = ::CreateProcess(NULL, (LPTSTR)(LPCTSTR)lpszCmdLine, lpSA, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); // Cleanup memory allocation if (lpSA != NULL) ::GlobalFree(lpSA); if (lpSD != NULL) ::GlobalFree(lpSD); // Return if an error occurs. if (!bResult) return FALSE; // Close the handles to reduce kernal usage count ::CloseHandle(pi.hThread); ::CloseHandle(pi.hProcess); // return true return bResult; }
Just pass in the command line and whether or not you want the console window displayed. Thanks to whomever submitted this! ed The absence of evidence is not evidence of absence. -
hi, in c++ you also use ShellExecute(), and it is quite easy to use, here is the online MSDN link i found: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp --- kick ash. http://sprdsoft.bigmoron.com http://t1tan.cjb.net
-
Don't remember where I picked this up but most likely somewhere here...Best site around!!
BOOL LaunchChild(LPCSTR lpszCmdLine, BOOL bShowChildWindow) { HANDLE hProcess = ::GetCurrentProcess(); PROCESS_INFORMATION pi; // Set up the start up info struct. STARTUPINFO si; ::ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; // Note that dwFlags must include STARTF_USESHOWWINDOW to // use the wShowWindow flags. si.wShowWindow = bShowChildWindow ? SW_SHOW: SW_HIDE; // Create the NULL security token for the process LPVOID lpSD = NULL; LPSECURITY_ATTRIBUTES lpSA = NULL; lpSD = ::GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); ::InitializeSecurityDescriptor(lpSD, SECURITY_DESCRIPTOR_REVISION); ::SetSecurityDescriptorDacl(lpSD, -1, 0, 0); lpSA = (LPSECURITY_ATTRIBUTES)::GlobalAlloc(GPTR, sizeof(SECURITY_ATTRIBUTES)); lpSA->nLength = sizeof(SECURITY_ATTRIBUTES); lpSA->lpSecurityDescriptor = lpSD; lpSA->bInheritHandle = TRUE; // Try to spawn the process. BOOL bResult = ::CreateProcess(NULL, (LPTSTR)(LPCTSTR)lpszCmdLine, lpSA, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); // Cleanup memory allocation if (lpSA != NULL) ::GlobalFree(lpSA); if (lpSD != NULL) ::GlobalFree(lpSD); // Return if an error occurs. if (!bResult) return FALSE; // Close the handles to reduce kernal usage count ::CloseHandle(pi.hThread); ::CloseHandle(pi.hProcess); // return true return bResult; }
Just pass in the command line and whether or not you want the console window displayed. Thanks to whomever submitted this! ed The absence of evidence is not evidence of absence. -
thanks ed, but the answer I got before yours worked perfectly and it only uses one line:
ShellExecute(NULL,"open","dtsrun.exe","/S localhost /U admin /P admin /N ImportDistTextToTable",NULL,SW_HIDE);
If it's broken, I probably did it bdiamond
-
Actually his way defines the whole function... good way to learn... and his function takes in less parameters and too could be in one line of code :) Actual Linux Penguins were harmed in the creation of this message.