Pages

Showing posts with label remote computer. Show all posts
Showing posts with label remote computer. Show all posts

Tuesday, July 26, 2011

How to start Windows Service on Remote Computer using VB.NET

Dim co As ConnectionOptions = New ConnectionOptions()
'CREDENTIALS
With co

 .Username = "username" 
 .Password = "password"
End With
Dim strComputer As String = "computername"

Dim scope As New System.Management.ManagementScope
scope=New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
'CONNECT TO THE BOX
scope.Connect()
Dim query As ObjectQuery = New ObjectQuery("Select * from Win32_Service Where Name ='SERVICENAME' ")
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)
Dim observer As ManagementOperationObserver = New ManagementOperationObserver()
Dim queryCollection As ManagementObjectCollection=searcher.Get()Dim m As ManagementObject
Dim args As Object
'START THE SERVICE

For Each m In queryCollection
 m.InvokeMethod("StartService", args)
Next

Monday, July 18, 2011

WMI Script to get BIOS details

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_BIOS",,48)
For Each objItem in colItems
  Msgbox "Win32_BIOS instance"
   If isNull(objItem.BIOSVersion) Then
     Msgbox "BIOSVersion: "
   Else
     Msgbox "BIOSVersion: " & Join(objItem.BIOSVersion, ",")
   End If
  Msgbox "Caption: " & objItem.Caption
  Msgbox "Description: " & objItem.Description
  Msgbox "InstallDate: " & objItem.InstallDate
  Msgbox "Manufacturer: " & objItem.Manufacturer
  Msgbox "Name: " & objItem.Name
Next

Tuesday, July 5, 2011

WMI Script to get details about local Computer System

Below script will give you the computer system details of a remote computer

strComputer = "FullComputerName"
strDomain = "DOMAIN"

strUser = "username"
strPassword = "password"

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, _
    "root\CIMV2", _
    strUser, _
    strPassword, _
    "MS_409", _
    "ntlmdomain:" + strDomain)

Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_ComputerSystem",,48)

For Each objItem in colItems
    Wscript.Echo "Win32_ComputerSystem instance"
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Domain: " & objItem.Domain
    Wscript.Echo "InstallDate: " & objItem.InstallDate
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Model: " & objItem.Model
Next