现在的位置: 首页 > 综合 > 正文

VBScript判断机器的角色

2012年03月12日 ⁄ 综合 ⁄ 共 612字 ⁄ 字号 评论关闭

下面这个脚本用于判断机器在域里面的角色:

' use "." for local computer

sComputer = "." 
WScript.Echo DomainRole(sComputer)

Function DomainRole(sNode)
Set oWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sNode & "\root\cimv2")
Set colComputer = oWMI.ExecQuery("Select DomainRole from Win32_ComputerSystem")
For Each oComputer in colComputer
     iDR = oComputer.DomainRole
Next

Select Case iDR
Case 0
    DomainRole = "Standalone Workstation"
Case 1
    DomainRole = "Member Workstation"
Case 2
    DomainRole = "Standalone Server"
Case 3
    DomainRole = "Member Server"
Case 4
    DomainRole = "Backup Domain Controller"
Case 5
    DomainRole = "Primary Domain Controller"
Case Else
    DomainRole = "Unknown"
End Select

End Function

抱歉!评论已关闭.