Visual Basic > Windows and Controls
Suspend a Computer
Suspend a Computer To suspend a PC use the following routine: Option Explicit Private Declare Function SetSystemPowerState Lib "kernel32" (ByVal fSuspend As Long, ByVal fForce As Long) As Long 'Purpose : To make a machine go into suspended mode. 'Inputs : bPrompt If True will prompt the user before going into suspended mode 'Outputs : Returns True if succeeded 'Requirements: Windows NT/2000: Requires Windows 2000. ' Windows 95/98: Requires Windows 95 or later. Function MachineSuspend(Optional bPrompt As Boolean) As Boolean If bPrompt Then 'Prompts the user before it goes into sleep mode 'if you have dial up open networking you will be prompted MachineSuspend = SetSystemPowerState(1, 0) Else 'Forces your computer into sleep mode 'Note, this will terminate dial up connections MachineSuspend = SetSystemPowerState(1, 1) End If End Function
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows