How do I convert the following VBScript code to JScript which is used for getting the user profile paths for all users?
Set oWshNet = CreateObject("Wscript.Network")
sComputer = oWshNet.ComputerName
'For remote computer
'sComputer = "some name or IP"
Const HKLM = &H80000002
sProfileRegBase = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
Set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
& sComputer & "/root/default:StdRegProv")
Set oWMI = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
& sComputer & "/root/cimv2")
Set colItems = oWMI.ExecQuery _
("Select Name,SID from Win32_UserAccount WHERE Domain = '" _
& sComputer & "'",,48)
For Each oItem In colItems
sAddInfo = ""
Wscript.Echo "User name: " & oItem.Name & sAddInfo
oReg.GetExpandedStringValue HKLM, sProfileRegBase& "\" & oItem.SID, _
"ProfileImagePath", sProfilePath
If IsNull(sProfilePath) Then
sProfilePath = "(none defined)"
End If <br>
Wscript.Echo "Profile path: " & sProfilePath
Wscript.Echo ' blank line
Next
I was partially succeeded in converting but stuck at 2 things.
-
Please confirm whether my usage of
oReg = GetObject("WinMgmts:\\\\.\\root\\default:StdRegProv");is correct and is same as the one that was given in the code. If not please suggest the right usage. -
What is the equivalent for
GetExpandedStringValuein JScript? If there is none, what is the better way to validate if a registry key exists before getting the value?
Here is a sample solution: (from http://www.windowsitpro.com/content/content/93402/Listing_05.txt)