I'm confused. I have program which I run as a non-administrator user. This program can write files in my C:\Program Files\ folder.
However, if I launch a second program using CreateProcess from within the first program, the second program cannot write to the C:\Program Files\ folder.
What are the correct parameters to pass into CreateProcess() to use the same access privileges as the first launching program? I've tried setting the 3rd and 4th parameters as NULL but that didn't seem to work.
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.