Thursday, January 3, 2019


How to shutdown a computer in VBScript?


'Warning - if you run this script, your computer will shut down

'Here you can specify name of the computer you want to  shut-down.....
'. means local computer
strComputer = "."

'create WMI object

Set objWMIService = GetObject_
    ("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
        strComputer & "\root\cimv2")

'Get the reference of all operating systems in your machine using Win32_OperatingSystem


Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")


'Enumerate each OS and shut down .
For Each objOperatingSystem in colOperatingSystems
    objOperatingSystem.Win32Shutdown(1)
Next



Related Posts:

  • How to shutdown a computer in VBScript? How to shutdown a computer in VBScript? 'Warning - if you run this script, your computer will shut down'Here you can specify name of the computer you want to  shut-down.....'. means local computerstrComputer = ".… Read More
  • VBScript Built-in functions VBScript Built-in functions use in UFT. Abs Function: Returns the absolute value of a number.Array Function: Returns a Variant containing an array.Asc Function: Returns the ANSI character code corresponding to the first let… Read More
  • Dynamic Arrays in VBScript example Dynamic Arrays in VBScript example In Vb script we can define the dynamic array in vb script as mentioned below.Size of dynamic array changes at run time. Example -Dim a () - declared dynamic array aTo use dynami… Read More
  • How to read webpage in vbscript How to read webpage in vbscript Here is an example in which I am using xmlhttp object to get the url source  code. We can get data from any website using below code. url="http://www.ebay.com" Set objHTTP = Crea… Read More
  • QTP VB Script Built in Functions QTP VB Script Built-in Functions Types of VBScript Functionso Conversions (25)o Dates/Times (19)o Formatting Strings (4)o Input/Output (3)o Math (9)o Miscellaneous (3)o Rounding (5)o Strings (30)o Variants (8)Important Fun… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

151,840

Blog Archive