Active Directory
Scripts
Windows Server
VB Script to Lookup and Open Home Directory
·
Mike Hosker
In a school network, teachers often need to access a student's home folder — to retrieve a file, check submitted work, or troubleshoot. The problem: teachers don't know UNC paths, folder structures vary by year group, and display names in File Explorer don't always match usernames in the system.
This VBScript takes a username, queries Active Directory for the home directory path, and opens it directly in Windows Explorer.
The Script
Option Explicit
Dim sUser, sDomain, sQuery, oUser, sHomePath
' Accept username from command line or prompt
If WScript.Arguments.Count > 0 Then
sUser = WScript.Arguments(0)
Else
sUser = InputBox("Enter the student username:", "Open Home Directory")
End If
If Trim(sUser) = "" Then WScript.Quit
' Set your domain
sDomain = "YOURDOMAIN"
' Query Active Directory
On Error Resume Next
Set oUser = GetObject("WinNT://" & sDomain & "/" & sUser & ",user")
If Err.Number <> 0 Or IsNull(oUser) Then
MsgBox "User '" & sUser & "' not found in Active Directory.", vbExclamation
WScript.Quit
End If
sHomePath = oUser.HomeDirectory
If Trim(sHomePath) = "" Then
MsgBox "No home directory configured for '" & sUser & "'.", vbInformation
WScript.Quit
End If
On Error GoTo 0
' Show info and open the folder
MsgBox "Opening home directory for: " & oUser.FullName & vbCrLf & sHomePath, vbInformation
Dim oShell
Set oShell = CreateObject("Shell.Application")
oShell.Open sHomePath
Set oShell = Nothing
Set oUser = Nothing
Deployment
- Save as
OpenHomeDir.vbson a shared staff area (e.g.,\\server\staff\tools\) - Create a desktop shortcut pointing to the script (set a custom icon if desired)
- Distribute via logon script:
copy "\\server\staff\tools\OpenHomeDir.vbs" "%USERPROFILE%\Desktop\" /Y
Teachers can then double-click the shortcut, type the student's username, and Explorer opens the folder directly — no knowledge of UNC paths or folder structures needed.



Command-Line Use
The script also accepts a username as an argument, useful for running from other scripts:
wscript "\\server\tools\OpenHomeDir.vbs" jsmith