Page 1 of 1

Posted: Sun Mar 02, 2003 10:18 pm
by BackupUser
Restored from previous forum. Originally posted by Julien Morel.

Hello
I will want to make a small application to stop my PC at one hour precise.
To stop the PC I use the following code:

OpenLibrary(0,"USER32.DLL")

CallFunction(0,"ExitWindowsEx",EWX_POWEROFF,0)



The problem it is that the PC does not stop but Windows closes just the session in progress.
How to make to stop the PC easily?


It would be necessary that the code goes with win9X and NT XP.
Thank you for your assistance.
Also if somebody knows how to know the number of the mother card,
it would be well.

Sorry for my English, but I french


Thank for help me

Posted: Sun Mar 02, 2003 11:39 pm
by BackupUser
Restored from previous forum. Originally posted by TheBeck.

No need to OpenLibrary() for API calls. Do this:

ExitWindowsEx_() #EWX_POWEROFF

For this function don't use 0 for last argument as 0 makes windows write debug code to disk witch takes extra time instead use something like this:
-> #SHTDN_REASON_MAJOR_APPLICATION|#SHTDN_REASON_MINOR_OTHER

Your code should look like this:

Code: Select all

If ExitWindowsEx_(#EWX_POWEROFF, #SHTDN_REASON_MAJOR_APPLICATION|#SHTDN_REASON_MINOR_OTHER) = #false
  MessageRequester("Error", Str$(GetLastError_()), #PB_MessageRequester_Ok) 
  end
EndIf
I am not able to test this code at this time so I hope it works...

Posted: Mon Mar 03, 2003 12:19 am
by BackupUser
Restored from previous forum. Originally posted by Julien Morel.

It is that?


//English

This code Closes the session, but I want that the PC stop
I am under Windows XP home

//French
Est cela comme code ?
Ce code Ferme la session, mais je veux que le PC s’arrête
Je suis sous Windows XP Home



#EWX_POWEROFF=0
#SHTDN_REASON_MAJOR_APPLICATION=0
#SHTDN_REASON_MINOR_OTHER=8

ExitWindowsEx_(#EWX_POWEROFF,#SHTDN_REASON_MAJOR_APPLICATION|#SHTDN_REASON MINOR_OTHER)

Posted: Mon Mar 03, 2003 12:30 am
by BackupUser
Restored from previous forum. Originally posted by TheBeck.

#EWX_POWEROFF=0
#SHTDN_REASON_MAJOR_APPLICATION=0
#SHTDN_REASON_MINOR_OTHER=8

Remove these lines from your program. These are API constants and are NOT to be set by the programmer.

Hope this helps.

Posted: Mon Mar 03, 2003 12:54 am
by BackupUser
Restored from previous forum. Originally posted by Julien Morel.

My code is:

ExitWindowsEx_(#EWX_POWEROFF, #SHTDN_REASON_MAJOR_APPLICATION|#SHTDN_REASON_MINOR_OTHER)


I have an error message (windows): The memory cannot be "read"

Posted: Mon Mar 03, 2003 1:29 am
by BackupUser
Restored from previous forum. Originally posted by TheBeck.

Can anyone verify this error? I will not be able to run this code until I get home several hours from now. If no one else can help then I will work on this when I get home.

Posted: Mon Mar 03, 2003 8:23 am
by BackupUser
Restored from previous forum. Originally posted by Berikco.

You have to change Token Privileges to be able to do this under NT-W2K-XP
This is already a couple of times posted here.
viewtopic.php?t=4278">http://forums.pur ... ebasic.htm

Posted: Mon Mar 03, 2003 9:45 am
by BackupUser
Restored from previous forum. Originally posted by Julien Morel.

:) Thank you, the code goes well :)