如何将以下VBScript代码转换为用于获取所有用户的用户配置文件路径的JScript?将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
我部分成功地转换,但坚持2件事。
请确认我的
oReg = GetObject("WinMgmts:\\\\.\\root\\default:StdRegProv");
用法是否正确,是否是相同是在代码中给出的一个。如果不是,请提出正确的用法。JScript中的
GetExpandedStringValue
的等效项是什么?如果没有,在获取该值之前验证注册表项是否存在的更好方法是什么?
非常棒..非常感谢 – svv 2011-04-05 15:19:32
谢谢,你也为我节省了很多时间! – GrandmasterB 2012-07-04 06:59:09