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:

  • Maths functions in vbscript Maths functions in vbscript Below is the list of all maths functions in vb script Abs  Atn  Cos  Exp  Fix  Int  Log  Rnd  Sgn  Sin  Sqr  Tan  round Let us … Read More
  • Classes in VBScript Classes in VBScript Here is an example that shows how we can create a class in QTP. Once we define the class, we can create its objects and then access its method and properties. 'declare the class book. Class Bo… Read More
  • Sub Procedures in VBScript Sub Procedures in VBScript Sub procedures are used to perform the specific task. Sub procedures are used to increase the reusability of the code. Simple example of the procedure Suppose you want to find the sum of … Read More
  • String functions in vbscript String functions in vbscript Below is the list of string functions in vb script lcase ucase len left right mid ltrim rtrim trim replace strreverse string Instr Instrrev strcomp We are going to have a look at each St… Read More
  • Difference between procedures and functions in vb script Difference between procedures and functions in vb script Major difference between procedures and functions in vb script is that procedures can not return the value but functions can return the value.Procedure Example… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

150,618

Blog Archive