2

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.?

leppie
  • 115,091
  • 17
  • 196
  • 297
Mahadeva
  • 1,584
  • 4
  • 23
  • 56

1 Answers1

1

did you try this: Get CSIDL_LOCAL_APPDATA path for any user on Windows

Community
  • 1
  • 1