我很困惑。我有作为非管理员用户运行的程序。该程序可以将文件写入我的C:\ Program Files \文件夹中。Windows 7 CreateProcess,子进程无法写入文件?
但是,如果我从第一个程序中使用CreateProcess启动第二个程序,则第二个程序无法写入C:\ Program Files \文件夹。
传入CreateProcess()以使用与第一个启动程序相同的访问权限的正确参数是什么?我已经尝试将第三和第四个参数设置为NULL,但这似乎不起作用。
BOOL RunCmd(char *pCmd,
char *pParams,
char *pWorkingDir,
int nWaitSecs,
BOOL fQuietMode,
DWORD *pdwExitCode)
{
BOOL fSuccess = TRUE;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = (fQuietMode) ? SW_HIDE : SW_SHOW;
// PDS: This is the important stuff - file handle needs to be inheritable..
SECURITY_ATTRIBUTES sFileSecurity;
ZeroMemory(&sFileSecurity, sizeof(sFileSecurity));
sFileSecurity.nLength = sizeof(sFileSecurity);
sFileSecurity.bInheritHandle = TRUE;
char txCmdLine[ MAX_PATH * 2 ];
strcpy(txCmdLine, "\"");
strcat(txCmdLine, pCmd);
strcat(txCmdLine, "\"");
if(pParams)
{
// PDS: Add any parameters if we have them..
strcat(txCmdLine, " ");
strcat(txCmdLine, pParams);
}
int rc;
// Start the child process.
rc = CreateProcess(NULL, // No module name (use command line).
txCmdLine, // Command line.
&sFileSecurity, // Process handle not inheritable.
&sFileSecurity, // Thread handle not inheritable.
FALSE,
// PDS: Don't pop up window for application.. quiet mode!
CREATE_NO_WINDOW,
NULL, // Use parent's environment block.
pWorkingDir, // Working folder
&si, // Pointer to STARTUPINFO structure.
&pi); // Pointer to PROCESS_INFORMATION structure.
感谢您的回应。它是一个运行在32位笔记本电脑上的32位进程。我确实有尝试在VirtualStore中创建文件的问题。在使用VS2010重新编译辅助程序之后,我使用ProcMon.exe确认CreateFile()调用肯定发生在C:\ Program Files \中。这是什么显示结果“ACCESS DENIED”。所以..这两个程序都是用相同的VS2010构建的,都是由我自己编写的,它们都是相同的代码风格。两者都是32位的..所以我能想到的是它从继承父程序的安全访问凭据不足的问题。 –
SparkyNZ
2012-02-09 20:39:34