I have an executable that is to be run as a Service in windows. Since the service runs as Local system, what should be the folder I should be writing any data the program uses. As currently, I use %LocalAppData% but when the exe runs as Service it points me to
C:\Windows\System32\config\systemprofile\AppData
I used following code:
std::string GetLocalAppDataPath()
{
HANDLE hfile;
TCHAR szPath[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,NULL,0, szPath)))
{
std::string path = boost::lexical_cast<std::string>(szPath);
boost::replace_all(path, "\\", "\\\\");
return path;
}
}
If I call the above code as:
std::string app_data_path = GetLocalAppDataPath();
std::string log_folder_path = app_data_path + "\\\\lpa\\\\output\\\\";
I get C:\WINDOWS\system32\config\systemprofile\AppData\Local\lpa\output\ instead of my own Local App Data Folder. So Should I be using other folder that LocalSystem can access.?