Two Examples

上一篇 / 下一篇  2010-03-26 01:19:32 / 个人分类:VBScript

YourNameComputerRoles Solution.vbs

Option Explicit
'On Error Resume Next
Dim strComputer
Dim wmiRoot
Dim wmiQuery
Dim colComputers
Dim objComputer
Dim objWMIService
Dim strComputerRole,strComputerName,strDomainName,strUserName
strComputer = "."
wmiRoot = "winmgmts:\\" & strComputer & "\root\cimv2"
wmiQuery = "Select * from Win32_ComputerSystem"

Set bjWMIService = GetObject(wmiRoot)
Set colComputers = objWMIService.ExecQuery(wmiQuery)
For Each objComputer In colComputers
  strComputerRole = funComputerRole(objComputer.DomainRole)
  strComputerName = objComputer.Name
  strDomainName = objComputer.Domain
  strUserName = objComputer.UserName
  WScript.Echo  strComputerRole & VbCrLf & strComputerName _
  & VbCrLf & strDomainName & VbCrLf & strUserName
  Next
WScript.Echo("all done")
Function funComputerRole(intIN)
 Select Case intIN
  Case 0
    funComputerRole = "Standalone Workstation"
  Case 1
    funComputerRole = "Member Workstation"
  Case 2
    funComputerRole = "Standalone Server"
  Case 3
    funComputerRole = "Member Server"
  Case 4
    funComputerRole = "Backup Domain Controller"
  Case 5
    funComputerRole = "Primary Domain Controller"
  Case Else
  funComputerRole = "Look this one up in SDK"
 End Select
End Function

 

YourNameEnableDHCPSolution.vbs

Option Explicit
'On Error Resume Next
Dim strComputer
Dim wmiRoot
Dim wmiQuery
Dim objWMIService
Dim colNetAdapters,objNetAdapter,DHCPEnabled
strComputer = "."
wmiRoot = "winmgmts:\\" & strComputer & "\root\cimv2"
wmiQuery = "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"

Set bjWMIService = GetObject(wmiRoot)
Set colNetAdapters = objWMIService.ExecQuery (wmiQuery)
For Each objNetAdapter In colNetAdapters
DHCPEnabled = objNetAdapter.EnableDHCP()
If DHCPEnabled = 0 Then
  WScript.Echo "DHCP has been enabled."
  Else
  WScript.Echo "DHCP could not be enabled."
End If
Next

 


TAG:

 

评分:0

我来说两句

Open Toolbar