怎么在自己的程序中调用别人的程序,并且传入参数
别人给我提供了一个小工具,是用来改变某个对象的属性的, 该工具名为changeTest.exe, 如果直接用的时候,我是打开cmd.exe ,然后先输入该工具全路径,然后再输入对象ID,然后是要改变的值, 比如
F:\\software\\changTest.exe 20201 100
其中F:\\software\\changTest.exe是全路径,20201是对象ID,100是改变的值,.那么我在我的程序中该怎么调用该工具,然后能够传入对象ID和值, 我想到过用Createprocess,但是不知道怎么传入参数,
不知道我有没把我的问题描述清楚,请各位大虾帮忙,谢谢先
------解决方案--------------------
不会CreateProcess,帮你顶一下~
用system调用dos命令也许可以(不过可能不具备通用性):
sprintf(cmdStr,"%s %d %d",exePath,ID,newVal);
system(cmdStr);
------解决方案--------------------
MSDN上的例子.
- C/C++ code
#include <windows.h> #include <stdio.h> #include <tchar.h> void _tmain( int argc, TCHAR *argv[] ) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); if( argc != 2 ) { printf("Usage: %s [cmdline]\n", argv[0]); return; } // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) argv[1], // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { printf( "CreateProcess failed (%d)\n", GetLastError() ); return; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); }