Shut down a computer from within vba

drom

Well-known Member
Joined
Mar 20, 2005
Messages
527
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007

hi and many thanks in advance!



is there a way to shut down a computer from within vba

to quit excel we use:

Code:
Application.Quit

1) to quit a computer?

thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about this?:

Code:
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiExitWindowsEx Lib "user32" _
        Alias "ExitWindowsEx" _
        (ByVal uFlags As Long, ByVal dwReserved As Long) _
        As Long

Public Const EWX_FORCE = 4      'Forcibly terminates processes
                                'that do not respond.
Public Const EWX_LOGOFF = 0     'Terminates processes, then logs off.
Public Const EWX_SHUTDOWN = 1   'Powers the system off, if possible.
Public Const EWX_REBOOT = 2     'Reboots the system.

Function fTerminateWin(lngExitVal As Long)
    fTerminateWin = apiExitWindowsEx(lngExitVal, 0)
End Function

Sub test()
    fTerminateWin (4)           'Only 4 and 0 work on my machine
End Sub

HTH
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top