I'm trying to locate the path for the AppData\LocalLow
folder.
I have found an example which uses:
string folder = "c:\users\" + Environment.UserName + @"\appdata\LocalLow";
which for one is tied to c:
and to users
which seems a bit fragile.
I tried to use
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
but this gives me AppData\Local
, and I need LocalLow due to the security constraints the application is running under. It returned blank for my service user as well (at least when attaching to the process).
Any other suggestions?
LocalLow is the same folder as local, but it has a lower integrity level. For example, Internet Explorer 8 can only write to the LocalLow folder (when protected mode is on).
To access it, one has to select “Show hidden files and folders” in the folder options. When you open the AppData folder, you will see three folders: Local. LocalLow.
Can I Delete the Local, LocalLow, and Roaming Folders? Yes, but no. Deleting these folders can not only possibly break Windows, but they will also indeed remove most of your program settings. Since these folders are protected, you'd have to boot into safe mode, then delete them and immediately regret it.
The Environment.SpecialFolder
enumeration maps to CSIDL
, but there is no CSIDL
for the LocalLow
folder. So you have to use the KNOWNFOLDERID
instead, with the SHGetKnownFolderPath
API:
void Main()
{
Guid localLowId = new Guid("A520A1A4-1780-4FF6-BD18-167343C5AF16");
GetKnownFolderPath(localLowId).Dump();
}
string GetKnownFolderPath(Guid knownFolderId)
{
IntPtr pszPath = IntPtr.Zero;
try
{
int hr = SHGetKnownFolderPath(knownFolderId, 0, IntPtr.Zero, out pszPath);
if (hr >= 0)
return Marshal.PtrToStringAuto(pszPath);
throw Marshal.GetExceptionForHR(hr);
}
finally
{
if (pszPath != IntPtr.Zero)
Marshal.FreeCoTaskMem(pszPath);
}
}
[DllImport("shell32.dll")]
static extern int SHGetKnownFolderPath( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr pszPath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With