‘!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
‘SYSTEM ADMINISTRATION AND NETWORK ADMINISTRATION USING WMI SCRIPTING
‘!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
‘**********************************************************************************************************************************
‘Getting the Computer Name
‘**********************************************************************************************************************************
Public Function funcGetComputerName ()
‘ Create Network Object
Set objNetwork = CreateObject("Wscript.Network")
‘ Get the Computer Name
strComputer = objNetwork.ComputerName
WScript.Echo "Computer Name "& strComputer
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Getting the Logged In User for your Computer
‘**********************************************************************************************************************************
Public Function funcGetUser ()
strComputer = "."
‘ Create WMI Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
‘ Displaying Logged In User
For Each objComputer In colComputer
Wscript.Echo objComputer.UserName & " is logged on"
Next
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Getting all the System Drives in your Computer
‘**********************************************************************************************************************************
Public Function funcGetSystemDrives ()
strComputer = "."
‘ Create WMI Object
Set objWMIServices = GetObject("winmgmts:\\" & strComputer)
‘ Get All System Drives
Set objSysDrives= objWMIServices.InstancesOf("Win32_LogicalDisk")
‘ Display all System Drives
For Each objSysDrive In objSysDrives
Wscript.Echo objSysDrive.DeviceID
Next
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Start and Stop WMI Service
‘**********************************************************************************************************************************
Public Function funcStopAndStartWMI ()
‘ Stop Windows Mangagment Script
net stop winmgmt
‘ Start Windows Mangagment Script
net start winmgmt
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Getting Free Space in C Drive
‘**********************************************************************************************************************************
Public Function funcGetFreeSpace ()
Create WMI Object
Set objWMIObject = GetObject("winmgmts:")
‘ Get Free Space
Set objDisk = objWMIObject.Get("Win32_LogicalDisk.DeviceID=‘ C:’ ")
‘Display Free Disk Space
Wscript.Echo "Free Space in KB " & objDisk.FreeSpace
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Retrieve all the Services Installed in your Computer
‘**********************************************************************************************************************************
Public Function funcGetAllServices ()
strComputer = "."
‘ Create Object
Set objWMIObject = GetObject("winmgmts:\\" & strComputer)
‘ Get Services
Set objServices = objWMIObject.InstancesOf("Win32_Service")
‘ Display All Services
For Each objService In objServices
Wscript.Echo "Name: " & objService.Name & vbCrLf & _
"Display Name: " & objService.DisplayName & vbCrLf & _
"Description: " & objService.Description & vbCrLf & _
"Path Name: " & objService.PathName & vbCrLf & _
"Start Mode: " & objService.StartMode & vbCrLf & _
"State: " & objService.State & vbCrLf
Next
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Retrieve the Operating System Information Installed in your Computer
‘**********************************************************************************************************************************
Public Function funcGetOSInfo ()
strComputer = "."
‘ Create WMI Object
Set objWMIObject = GetObject("winmgmts:\\" & strComputer)
‘ Get Operatin System Inforamtion
Set ObjColOperatingSystems = objWMIObject.InstancesOf("Win32_OperatingSystem")
‘Display Operating System Information
For Each objOperatingSystem In ObjColOperatingSystems
Wscript.Echo "Name: " & objOperatingSystem.Name & vbCrLf & _
"Caption: " & objOperatingSystem.Caption & vbCrLf & _
"CurrentTimeZone: " & objOperatingSystem.CurrentTimeZone & vbCrLf & _
"LastBootUpTime: " & objOperatingSystem.LastBootUpTime & vbCrLf & _
"LocalDateTime: " & objOperatingSystem.LocalDateTime & vbCrLf & _
"Locale: " & objOperatingSystem.Locale & vbCrLf & _
"Manufacturer: " & objOperatingSystem.Manufacturer & vbCrLf & _
"OSType: " & objOperatingSystem.OSType & vbCrLf & _
"Version: " & objOperatingSystem.Version & vbCrLf & _
"Service Pack: " & objOperatingSystem.ServicePackMajorVersion & _
"." & objOperatingSystem.ServicePackMinorVersion & vbCrLf & _
"Windows Directory: " & objOperatingSystem.WindowsDirectory
Next
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Joining Domain and Create Account
‘**********************************************************************************************************************************
Public Function funcJoinDomain ()
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
‘Create WMI Object Computer
Set objComputerSystem = GetObject ("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & _
"\root\cimv2:Win32_ComputerSystem.Name=‘ " & strComputer & "‘ ")
ReturnValue = objComputerSystem.JoinDomainOrWorkGroup _
("FABRIKAM", "password", "FABRIKAM\shenalan", NULL, JOIN_DOMAIN+ACCT_CREATE)
WScript.Echo ReturnValue
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Retrieving Default Namespaces for Scripting
‘**********************************************************************************************************************************
Public Function funcJoinDomain ()
strComputer = "."
‘ Create WMI Object
Set objWMIObject = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
‘ WMI Settings
Set colWMISettings = objWMIObject.InstancesOf("Win32_WMISetting")
For Each objWMISetting In colWMISettings
Wscript.Echo "Default namespace for scripting: " objWMISetting.ASPScriptDefaultNamespace
Next
End Function
‘**********************************************************************************************************************************
‘**********************************************************************************************************************************
‘Setting Default Namespaces for Scripting
‘**********************************************************************************************************************************
Public Function funcJoinDomain ()
strComputer = "."
‘ Create WMI Object
Set objWMIObject = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
‘ WMI Setting for Scripting
Set colWMISettings = objSWbemServices.InstancesOf("Win32_WMISetting")
For Each objWMISetting In colWMISettings
objWMISetting.ASPScriptDefaultNamespace = "root\cimv2"
bjWMISetting.Put_
Next
End Function
‘**********************************************************************************************************************************
‘!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
No comments:
Post a Comment