[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3416
  • Last Modified:

Registry location for home folder

I really can't seem to understand this.

I'm trying to write a vbscript to search the registry for a specified user's home folder, but there is no absolutely consistent key I can find. I have seen the two following:

HKEY_USERS\<sid>\Volatile Environment\HOMESHARE and
HKEY_USERS\<sid>\Software\Microsoft\WIndows\CurrentVersion\Explorer\User Shell Folders\Personal

The problem is, neither one of these match (100% of the time) the variable located in the user's Active Directory "Profile" tab.

In every case, we have "\\server\users$\username" as the share mapped to the user's "H" drive. But on any given server (we have over 200 to support) the above keys can vary. For example: On a test server we have here, the HOMESHARE key is set to "\\server\users$", while the "Personal" key is what I am looking for. On another server, the HOMESHARE is what I want, and the "Personal" key has the share, but with "My Documents" appended to the end.

So how in the hell can I programatically find a user's share (at \\server\users$\username) while I'm not logged in as that user?
0
qisadmin
Asked:
qisadmin
  • 4
2 Solutions
 
devinnoelCommented:
I think you might have actually touched on the correct answer yourself. Pull it from Active Directory rather than the registry.

http://www.geekshangout.com/node/27
0
 
-tjsCommented:
AD itself would be more authoritative over any possible locally cached location of a user who is not currently logged in.  Assuming one domain, an example command line to get the home folder for a given user would be:
dsquery * -filter "(samaccountname=insert_the_user_login_name_here)" -attr samaccountname homedirectory
0
 
qisadminAuthor Commented:
We have some older servers not using AD, but the local SAM database instead. I would need a neutral method that works on all servers, so we can deploy the script universally. Would WMI suffice for this?

I have the following WMI call already being used to get the user's SID. I wonder if there exists a way to get the info I want.


Function getSID(myUserName)
' This function uses WMI to find a user's SID.
' It is required in order to reference the user's
' branch of the HKEY_USERS registry area.

   Dim strComputer, objWMIService, objAccount

   strComputer = "."
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

   Set objAccount = objWMIService.Get _
       ("Win32_UserAccount.Name='" & myUserName & "',Domain='" & DOMAIN & "'")

   getSID = objAccount.SID
End Function

Open in new window

0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
qisadminAuthor Commented:
I think I might have found it, thanks to both of your suggestions. I have a bit further testing to do though.


On Error Resume Next
 
Const myUserName = "test"
Const DOMAIN = "domain"

Dim strComputer, objWMIService, objAccount

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objProfile = objWMIService.Get _
   ("Win32_NetworkLoginProfile.Name='" & DOMAIN & "\" & myUserName & "'")

Wscript.echo objProfile.HomeDirectory

Open in new window

0
 
qisadminAuthor Commented:
OK then, this makes no sense. Some user accounts work, some do not. I commented out the "On error Resume Next" line, so sometimes I get a "Not Found" error. So this doesn't seem to be viable.
0
 
qisadminAuthor Commented:
OK. I figured it out. It works on users who are currently logged in, and this is perfectly OK, because my script only works on users who are logged in anyhow.

Thanks to the both of you for suggesting pulling from AD instead of the registry.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now