Showing posts with label WMI. Show all posts
Showing posts with label WMI. Show all posts

GetProcessInfo using WMI

Sub GetProcess()
  Set objWMI = GetObject("winmgmts:")
  Set instanzen = objWMI.InstancesOf("Win32_Process")
  'MakeTabH "Instance","CommandLine"
  For Each objInstance In instanzen
    'MakeTabD objInstance.Name , objInstance.CommandLine
  write objInstance.Name  & " : " & objInstance.CommandLine & ""
  'document.frames.myiframe.document.body.style.font="arial"
  Next
End Sub

DomainRole

strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & strComputer & "\root\cimv2")

Create a System Restore Point

' Create a System Restore Point
' supported on: Windows XP

dim spi
Set spi = Createobject("sapi.spvoice")
spi.speak "Well come napstr"
spi.speak "Initialising Automated Restore"
Const DEVICE_DRIVER_INSTALL = 10
Const BEGIN_SYSTEM_CHANGE = 100

strComputer = "."
Set objWMI = GetObject("winmgmts:" _
& "\\" & strComputer & "\root\default")

Set objItem = objWMI.Get("SystemRestore")
errResults = objItem.CreateRestorePoint _
("AUTOMATED NAPSTR RESTORE", DEVICE_DRIVER_INSTALL, BEGIN_SYSTEM_CHANGE)

spi.speak "Automated Restore point Created" 

Battery Status using WMI

'Battery information

Set objWMI = GetObject("winmgmts:\\.\root\CIMV2")
Set objA = objWMI.InstancesOf("Win32_Battery",48)
For Each objFish In objA
' The remaining time to charge the battery fully in minutes at the current charging rate and usage.
str= objFish.SystemName & VbCrLf
str=str & objFish.EstimatedChargeRemaining & " % Percent Remaining" & VbCrLf
minutes=objFish.EstimatedRunTime
hrs = Int(minutes/60)
miin = minutes Mod 60

str = str & " " & Int(minutes/60) & ":" & miin & " Hrs left" & VbCrLf

Next
'MsgBox str
Set objWMI = GetObject("winmgmts:\\.\root\WMI")
Set objA = objWMI.InstancesOf("BatteryStatus", 48)

For Each objFish In objA
'WScript.Echo objFish.getObjectText_
disch= objFish.Discharging
powe= objFish.PowerOnline

criti= objFish.Critical
chrg= objFish.Charging

Next

If disch < 0 Then
disch = "Discharging"
Else
disch =""
End If
If powe < 0 Then
powe = "Power Online"
Else
powe=""
End If
If criti < 0 Then
criti = "Critical"
Else
criti = ""
End If
If chrg < 0 Then
chrg = "Charging"
Else
chrg = ""
End If
'MsgBox ,,"Status"
Ststus="STATUS: " & disch & " " & powe & " " & criti & " " & chrg
MsgBox Ststus & VbCrLf & str, ,
" ЦГТІШΛТΞ ΠΛΡΣΤЯ "

Create a Process in a Hidden Window

' Create a Process in a Hidden Window

Const HIDDEN_WINDOW = 12
cmd=InputBox("Create the following process ie notepad.exe","Enter")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup"

)
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create(cmd, Null, objConfig, intProcessID)