开发者

Need help with VBS Classes

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

I get an error saying

Microsoft VBScript runtime error (13, 4) : Object开发者_如何学运维 doesn't support this property or method: 'internal_colComputer.UserName'


Try changing the line

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

to

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

I would suspect (although I'm not sure) that UserName is a property of the objComputer, not the collection that you're looping through.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜