Put a computer in hibernate sleep shutdown standby, etc modes

Could someone put me on tracks to put a computer in hibernate sleep shutdown standby modes (if I didn’t forgot any)
TIA

Mac, Windows, Linux ?

Preferably windows, but if it may be applied to any it’ll be good too.
:wink:

maybe this?
https://www.monkeybreadsoftware.net/faq-howtoquitwindows.shtml

TY Christian,
A bunch of questions comes up . . . sorry . . .
I would like to use it with a timer to trigger at scheduled time.
Can I simply copy and paste it as is?
Where to write it?
Is it in a method or property?
Tell me if I’m wrong, but I understand it is ExitWindowsEx lib and
“i1 = 2”
“i2 = 0”
has to be replaced with values in the “notes part”, like 4, 0, 2 or 1
I saw Force, Logoff, Reboot, shutdown
It covers shutdown but not hibernate, sleep, standby
May be other lib is necessary for those actions?
I should be able to try it withing a couple of hours on an XP OS.

Christian, it seems that it is a plug in to buy to use this code, correct me if wrong.
My question is about doing it with xojo coding.

There is no Xojo function for it. You’re going to need declares or a plugin.
Christian’s link was to the Windows declares for Shutdown, Reboot, and Logoff.

At the end of the post it mentions you can use a plugin, but what was linked is simply a declare and does not need a plugin.

Well, the declare should work. But it could be that system blocks your request due to permissions.

The plugin function does the same except it first checks permissions and asks Windows to actually permit the application to logout/shutdown.

Thanks all, I’ll try to make this work, not sure if I’m on pair for the task, I may need some more infos to make it works.
My first attempts was not successful . . .

Hi I’m back to give a little feedback:
On windows XP under admin user the only option which works is Log off the Systemwith parameters:
i1 = 0
i2 = 0
I searched and found this:
for hibernate:
DllCall(“PowrProf\SetSuspendState”, “int”, 1, “int”, 1, “int”, 1)
for Sleep:
DllCall(“PowrProf\SetSuspendState”, “int”, 0, “int”, 1, “int”, 1)
For Shutdown:
Shutdown
and also this:
// Hibernate
'Application.SetSuspendState(PowerState.Hibernate, true, true);
// Standby
'Application.SetSuspendState(PowerState.Suspend true, true);
But nothing I can try as it is not xojo language.
If you can help I’ll be glad.

Haven’t tested, but I think you could get this functionality through the shell (DOS) commands.

ex. shutdown:

Dim s As Shell s = New Shell #If TargetWin32 Then s.Execute("shutdown -t 0")

ex. restart

Dim s As Shell s = New Shell #If TargetWin32 Then s.Execute("shutdown -r -t 0")

Working with the shutdown commands you should be able to achieve what you want.

http://pcsupport.about.com/od/commandlinereference/p/shutdown-command.htm

This link describes all the different command line switch modifiers.

Hi Dorian,

Here is Example9-1.xojo_binary_project from my Book I Wish I Knew How To… Implement Win32 Declares With Xojo on Windows. After a complete chapter has been added then the updated book will be available on RBLibrary.com .

The example is similar to what Christian mentioned and has the options for various types of shutdown.

Happy to help!

Thanks you all, didn’t knew I had other answers,I will work on this as soon as I can.

Great help.

[quote=218514:@David Zeinz]Haven’t tested, but I think you could get this functionality through the shell (DOS) commands.

ex. shutdown:

Dim s As Shell s = New Shell #If TargetWin32 Then s.Execute("shutdown -t 0")

http://pcsupport.about.com/od/commandlinereference/p/shutdown-command.htm

This link describes all the different command line switch modifiers.[/quote]

I tried this code but it only duplicates the current window…

I haven’t digged a lot on this yet, but a little feedback here is that I found that the sleep command that wouldn’t work on my PC under XP:
Either one, they do the same thing: put PC to sleep:

"rundll32.exe powrprof.dll,SetSuspendState 0,1,0" "Rundll32.exe powrprof.dll,SetSuspendState Sleep"
Works if Hibernate is deactivated with a command to write before this one, like that:

"powercfg -hibernate off" // hibernation deactivation needed to put on sleep mode successfully (XP?)

then either one of the above commands:

"rundll32.exe powrprof.dll,SetSuspendState 0,1,0" "Rundll32.exe powrprof.dll,SetSuspendState Sleep"
Hibernate could be reactivated, when needed with:

"powercfg -hibernate on"

I wonder what you could be doing to instanciate a window with that code…

Put this in a button to hibernate :

Sub Action() Dim s As Shell s = New Shell #If TargetWin32 Then s.Execute("shutdown /h") #endif End Sub