如何以管理员身份运行CreateProcess?

时间:2011-07-14 07:40:54

标签: c++ windows winapi visual-c++ createprocess

  

可能重复:
  CreateProcess to run as administrator
  How can I run a child process that requires elevation and wait?

如何在此处修改我当前的代码,使其以管理员身份运行CreateProcess

  SECURITY_ATTRIBUTES secattr; 
  ZeroMemory(&secattr,sizeof(secattr));
  secattr.nLength = sizeof(secattr);
  secattr.bInheritHandle = TRUE;
  HANDLE rPipe, wPipe;

  //Create pipes to write and read data
  CreatePipe(&rPipe,&wPipe,&secattr,0);  
  STARTUPINFO sInfo; 
  ZeroMemory(&sInfo,sizeof(sInfo));
  PROCESS_INFORMATION pInfo; 
  ZeroMemory(&pInfo,sizeof(pInfo));
  sInfo.cb=sizeof(sInfo);
  sInfo.dwFlags=STARTF_USESTDHANDLES;
  sInfo.hStdInput=NULL; 
  sInfo.hStdOutput=wPipe; 
  sInfo.hStdError=wPipe;
  sInfo.wShowWindow;

  CString parameterB = _T(" -format \"%h\" ") + pictureName;  
  CString parameterA = mycustompath + _T("identify.exe");

  if (CreateProcess(parameterA.GetBuffer(), parameterB.GetBuffer(),0,0,TRUE,
          NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo))
          {
            WaitForSingleObject (pInfo.hProcess, INFINITE);
          }

  CloseHandle(wPipe);

我正在使用Visual Studio 2008,如果重要的话。

0 个答案:

没有答案