I had a requirement to easily display some information contained in a users Hybrid profile.
The Hybrid profile information is stored in REG Binary files so cannot be viewed with a regular text editor. Loading the binary file manually into REGEDT32 and reviewing is to long winded for first line support staff so I incorporated this code into one of their support tools.
They basically input the userID and it outputs the the path the user has mapped as their
Network drive J
This VB script reads the binary file into the registry HKCU\Tempuser where it can then be read and output as plain text as required. The Sub routine below is what I incorporated into the service desk GUI. The only variable that the Sub needs is the USERID of the persons whos drive mapping is to be queried.
Sub ReadJDriveMapping
const HKLM = &H80000002
const HKU = &H80000003
strFilePath = " \\dfswz001\users\" & UserID & "\HybridProfile\Environment\Drives\Network.UK_" & UserID
const strComputer = "." 'Current Computer
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ObjShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strSysRoot = WshShell.ExpandEnvironmentStrings("%SystemRoot%")
StrRegKey = "HKEY_USERS\TempUser\J\RemotePath"
strHiveNm = "TempUser"
' Load the Hive
set OExec = ObjShell.Exec("REG LOAD HKU\" & StrHiveNm & strFilePath)
Do While oExec.Status = 0
Wscript.Sleep 1000
Loop
' Read the value in the hive
StrKeyVal = Objshell.RegRead(StrRegKey)
msgbox "Users J: Drive Mapping = " & StrKeyVal
' Unload the Hive
set OExec = Objshell.Exec("%COMSPEC% /C Reg Unload HKU\" & strHiveNm )
Do While oExec.Status = 0
Wscript.Sleep 1000
Loop
End Sub
Note : If you put this into a HTA wscript.sleep does not work. So i used a call to a SLEEP.VBS to make the script sleep for 1000
No comments:
Post a Comment