我已经把头撞到了墙上几天了,无法弄清楚我的代码是什么问题。我敢肯定它相当简单但却看不到它。我正在尝试返回登录到计算机的用户列表和时间。由于环境被锁定,我必须阅读注册表。
Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Dim oNet, WMI, strComputer, tz, os, objRegistry, strKeyPath, strSubPath, strValueName, strValue, arrSubkeys, objSubKey, strSID, strUser, objReg, lngHighValue, lngLowValue, Return, strReturn, NanoSecs, DT
Set oNet = CreateObject("WScript.Network")
Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
strComputer = oNet.Computername
tz = 0
For Each os In GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
tz = os.CurrentTimeZone
Exit For
Next
'Set objRegEx = CreateObject("VBScript.RegExp")
'objRegEx.Global = True
'objRegEx.IgnoreCase = True
'objRegEx.Pattern = "default|all users|administrator|localservice|networkservice|ueit-admn-[0-9]|3rd-admn-[0-9]|systemprofile"
Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
For Each objSubkey In arrSubkeys
strValueName = "ProfileImagePath"
strSID = objSubKey
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
'strUser = Replace(strValue,"C:\Documents and Settings\","")
'Set colMatches = objRegEx.Execute(strUser)
'If colMatches.Count < 1 Then
Call ProfileTime(strSID)
'WScript.echo ProfileTime
'End If
Next
Function ProfileTime(strSID)
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv" )
strKeyPath = "SOFTWARE\MICROSOFT\Windows NT\CurrentVersion\ProfileList\" & strSID
strValueName = "ProfileLoadTimeHigh"
Return = objReg.GetDWORDValue(HKEY_LOCAL_MACHINE,strKeyPath,strValueName,lngHighValue)
strValueName = "ProfileLoadTimeLow"
Return = objReg.GetDWORDValue(HKEY_LOCAL_MACHINE,strKeyPath,strValueName,lngLowValue)
If typename(lngHighValue) <> "Null" then
NanoSecs = (lngHighValue * 2 ^ 32 + lngLowValue)
'' /* Returns time in Workstation Timezone */
DT = #1/1/1601# + (NanoSecs / 600000000 / 1440) + (tz / 1440)
Set ProfileTime = CDate(DT)
End If
End Function
运行以上返回
profile.vbs(36, 5) Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment: 'ProfileTime'
咬了一下
答案 0 :(得分:3)
on error resume next
,直到您的错误得到解决。Option Explicit
并声明所有变量。你会看到你有一些范围问题(例如strReturn)Return = "my return value"
Call ProfileTime(objsubkey)
。否则,可以将其作为Sub处理,然后将其作为ProfileTime objsubkey
处理。使用ProfileTime(objsubkey)
意味着“在将objsubkey投入函数之前对其进行评估。”看看this blog article它的工作原理。这些步骤将使您的代码更清晰,为您提供出现问题的提示。当发生错误时(=接下来错误恢复)并期望它正常工作时,您无法通过查看另一种方式来创建代码。也不尊重你的工人,因为他们没有将他们放在适当的贷款清单上(=选项明确,宣布和范围界定)将使他们不顺从你。