【发布时间】:2012-02-09 04:05:34
【问题描述】:
我很困惑。我有以非管理员用户身份运行的程序。该程序可以在我的 C:\Program Files\ 文件夹中写入文件。
但是,如果我在第一个程序中使用 CreateProcess 启动第二个程序,则第二个程序无法写入 C:\Program Files\ 文件夹。
传递给 CreateProcess() 以使用与第一个启动程序相同的访问权限的正确参数是什么?我尝试将第 3 和第 4 个参数设置为 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.
【问题讨论】:
标签: windows createprocess