string command = GetWorkDir();
command += "\\NTGraph.ocx";
command = "regsvr32 /s " + command;
bool rult = ExcuteCommand(command);
if (rult == false)
{
return(false);
}
bool ExcuteCommand(string&commandtext)
{
SECURITY_ATTRIBUTES sa;
//Set the parameters uesd for create a pipe.
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
HANDLE hReadPipe, hWritePipe;
//Create a pipe.
//0 is a default value.
CreatePipe( &hReadPipe, &hWritePipe, &sa, 0 );
STARTUPINFO si;
//Set the parameters used for create a process.
ZeroMemory(&si,sizeof(si));
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.hStdOutput = hWritePipe;
si.hStdError = hWritePipe;
si.cb = sizeof(si);
PROCESS_INFORMATION processInfo;
ZeroMemory( &processInfo , sizeof(PROCESS_INFORMATION) );
// Explain the function CreateProcess's parameters list.
// 1.Start the child process.
// 2.No module name (use command line).
// 3.Command line.
// 4.Process handle not inheritable.
// 5.Thread handle not inheritable.
// 6.Set handle inheritance to FALSE.
// 7.No creation flags.
// 8.Use parent's environment block.
// 9.Use parent's starting directory.
// 10.Pointer to STARTUPINFO structure.
// 1 is means true.0 is means false.
INT32 ret = CreateProcess(NULL, (LPSTR)commandtext.c_str(), NULL, NULL, 1, 0, NULL, NULL, &si, &processInfo);
if (!ret)
{
return(false);
}
////0 is means that the exit code.
//TerminateProcess( processInfo.hProcess, 0 );
//// Close process and thread handles.
//CloseHandle( hReadPipe );
//CloseHandle( hWritePipe );
return(true);
}