Locate AppData \ LocalLow

I am trying to find the path to the AppData\LocalLow .

I found an example that uses:

 string folder = "c:\users\" + Environment.UserName + @"\appdata\LocalLow"; 

which for one is tied to c: and to users , which seems a little fragile.

I tried to use

 Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) 

but this gives me AppData\Local , and I need LocalLow due to the security restrictions that the application works with. It was also empty for my service user (at least when connected to a process).

Any other suggestions?

+11
c #
Dec 20 '10 at 21:49
source share
1 answer

The Environment.SpecialFolder enumeration displays the CSIDL , but there is no CSIDL for the LocalLow folder. Therefore, you should use KNOWNFOLDERID using 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); 
+18
Dec 20 '10 at 23:45
source share



All Articles