Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem here is that Microsoft has not provided an API method of doing this directly. Perhaps it was an oversight. That being said, any solution you find is going to be some kind of workaround and is going to present some kind of limitations.</p> <p>Using the registry to get this information is not officially supported by Microsoft and thus, may not work going forward.</p> <p>Iterating through user profile folders is unreliable because the folder is not always named after its user and because you can change its location.</p> <p>And so on.</p> <p>All of that being said, I use a combination of WMI and the registry to accomplish this. Here's what it looks like in VBScript, you should be able to adapt it to your needs.</p> <pre><code> ' Create some arrays to hold the data. arrUsers = Array() arrSIDs = Array() arrAppDataFolders = Array() ' Get a list of all the non-system users with their SID strComputer = "." Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2" Set colUsers = objWMIService.ExecQuery _ ("Select * from Win32_UserAccount Where Status = 'OK'") i = 0 For Each objUser in colUsers ReDim Preserve arrUsers(i) ReDim Preserve arrSIDs(i) arrUsers(i) = objUser.Name arrSIDs(i) = objUser.SID i = i + 1 Next Set colUsers = Nothing Set objWMIService = Nothing ' Now go to the registry and get the Document folder location using the SID Const HKEY_USERS = &amp;H80000003 Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ &amp; strComputer &amp; "\root\default:StdRegProv") ReDim arrAppDataFolders(UBound(arrSIDs)) For i = 0 to UBound(arrSIDs) strKeyPath = arrSIDs(i) &amp; "\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" strValueName = "AppData" ' or "Local AppData" intReturn = objRegistry.GetExpandedStringValue HKEY_USERS, strKeyPath, strValueName, strValue If (intReturn = 0) And (Err.Number = 0) Then arrAppDataFolders(i) = strValue Else arrAppDataFolders(i) = vbNull End If Next Set objRegistry = Nothing </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload