需要帮助VBS Classes

时间:2011-08-11 15:19:37

标签: class scripting vbscript

Class GetUserName
Private internal_Username
Private internal_strComputer
Private internal_objWMIService
Private internal_colComputer
Private internal_objComputer

Public Property Get EmployeeName
    strComputer = "."
    Set internal_objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set internal_colComputer = internal_objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
    For Each objComputer In internal_colComputer
        internal_Username = LCase(Right(internal_colComputer.UserName, Len(internal_colComputer.UserName) - Len(Left(internal_colComputer.UserName, 7))))
    Next
    EmployeeName = internal_Username
End Property
End Class
Dim objEmployee
Set objEmployee = New GetUserName

WScript.Echo objEmployee.EmployeeName

我收到错误说

Microsoft VBScript runtime error (13, 4) : Object doesn't support this property or method: 'internal_colComputer.UserName'

2 个答案:

答案 0 :(得分:2)

尝试更改行

internal_Username = LCase(Right(internal_colComputer.UserName, Len(internal_colComputer.UserName) - Len(Left(internal_colComputer.UserName, 7))))

internal_Username = LCase(Right(objComputer.UserName, Len(objComputer.UserName) - Len(Left(objComputer.UserName, 7))))

我怀疑(虽然我不确定)UserNameobjComputer的属性,而不是你正在循环的集合。

答案 1 :(得分:0)

>> cnHeadLen = 8
>> s = "CONTOS\firstname.lastname"
>> WScript.Echo Mid( s, cnHeadLen )
>>
firstname.lastname