// ========================================================================= // // 功 能:以指定系统用户身份执行指定程序 // // 参 数:sUser,用户名 sPass,密码 // // sFileName,执行程序路径 sCmdLine,命令参数 // // 返回值:TRUE,FALSE // // 备 注:无 // // ========================================================================= // BOOL ExcuteProcess(CString sUser,CString sPass,CString sFileName,CString sCmdLine) ... { PROCESS_INFORMATION pi; STARTUPINFO si; si.cb = sizeof(STARTUPINFO); si.lpReserved = NULL; si.lpDesktop = NULL; si.lpTitle = NULL; si.dwFlags = 0; si.cbReserved2 = 0; si.lpReserved2 = NULL; STARTUPINFO sinf; GetStartupInfo(&sinf); try ...{ if(!CreateProcessWithLogonW(sUser, NULL, sPass, LOGON_WITH_PROFILE, sFileName, (LPWSTR)(LPCWSTR)sCmdLine, CREATE_NEW_PROCESS_GROUP, NULL, NULL, &si, &pi)) ...{ CString sError=FormartLastError(GetLastError()); ::WriteLogFile(sError); AfxMessageBox(sError); return FALSE; } } catch(...) ...{ AfxMessageBox(FormartLastError(GetLastError())); return FALSE; } return TRUE;}