How do I create a file in C++ when UAC is on, but with out running as administrator?
I'm trying to create a text file in the following path: "C:\Programdata\Desktop" in VC++ 6.0 when Vista's UAC is on. However, Createfile(...)
failed with 'permission denied'.
When I run the sample application with "run as administrator" it works. But my sample application should not "run as administrator".
Is there any API to give permission to the above path, when UAC is on?
sample code: const nSize = 100; CStdioFile file; CFileException obFileExp; CString csFilePath(_T("C:\ProgramData\Desktop\sample.txt"));
if (!file.Open( csFilePath , CFile::modeCreate | CFile::modeWrite ,&obFileExp ) )
{
// opening of file failed
TCHAR szErr[nSize];
obFileExp.GetErrorMessage(szErr,nSize);
AfxMessageBox(szErr);
return ;
}
file.WriteString( "welcome" );
file.Close( );
NOTE: UAC should ON and VC++ 6.0 should NOT run as administrator