Я в замешательстве.У меня есть программа, которую я запускаю как пользователь без прав администратора.Эта программа может записывать файлы в мою папку 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.