如何将以下 VBScript 代码转换为用于获取所有用户的用户配置文件路径的 JScript?
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
我在转换方面取得了部分成功,但坚持了两件事。
请确认我的用法
oReg = GetObject("WinMgmts:\\\\.\\root\\default:StdRegProv");
是否正确,是否与代码中给出的相同。如果没有,请建议正确的用法。GetExpandedStringValue
JScript中的等价物是什么?如果没有,在获取值之前验证注册表项是否存在的更好方法是什么?