c++ - Writing a log file with app running in non-admin mode in windows 7 -
My app needs to write and maintain the log file and it is not running in admin mode. My question is, how can my app write in such a situation, how can I get that way?
There are two good options:
-
Windows Event Log You can easily create your own log for your application (if you expect to generate a lot of messages), or you can add messages to standard logs (if you only generate a few, sometimes a message )
Since this is an underlying feature, any technical person wants to know about it and will be able to easily locate their log files. There is also much difference with this centralized management system.
-
Write a text file saved in the application data directory. This is where applications have to store non-user data files, because as you have mentioned, the application directory is not something that you can write privileges.
For a log file that is specific to a particular computer, I can say that this is local (non-roaming) application data, so you want the local app data folder. I'm sure there is a QT cover for this, but in Win32, you can specify the
SHGetKnownFolderPath function to
KNOWNFOLDERID value
FOLDERID_LocalAppData .
Remember that this function allocates memory to store empty strings, when you call the call you will have to call it at
CoTaskMemFree .
Sample code:
// Retrieve the path to the Local App Data folder. Wchar_t * pszpath = 0; SHGetKnownFolderPath (FOLDERID_LocalAppData, 0, NULL, and pszPath); // Make a copy of that path: std :: wstring path (pszpath); // Now the memory is free, so you do not forget! CoTaskMemFree (static_cast & lt; zero * & gt; (pszPath));
Comments
Post a Comment