如何將以下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