-
Dec 10th, 2010, 11:45 PM
#1
Thread Starter
New Member
-
Dec 11th, 2010, 07:43 AM
#2
Re: Shutting down/standby/or hibernate windows with VB6
the api should work fine
what is happening now, error or wrong result?
what value for exit_option when calling shutdown?
what value for selectedoption, or is it a function?
you could also try shelling out to shutdown.exe, system32 directory
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 11th, 2010, 01:11 PM
#3
Thread Starter
New Member
Re: Shutting down/standby/or hibernate windows with VB6
Originally Posted by westconn1
the api should work fine
what is happening now, error or wrong result?
what value for exit_option when calling shutdown?
what value for selectedoption, or is it a function?
you could also try shelling out to shutdown.exe, system32 directory
For the second code, I got an error saying "error loading user the specified module could not be found"
For the first one, nothing would happen.
And there was another one that I tried that was similar to the second code that when I put a value of 0 (I think it was zero) my computer would log off right away. But supposedly there was another value (i think 4) for shut down (as well as others for restarting) that upon trying to use, nothing would happen.
I think the only reason the first code is so long is to that the user can decide if they want to shut down/restart/log off, etc.
Now about that shutdown thing in system32, would that ask the user to save open applications and stuff? I need the computer to just shut down right away after its done. Either that or put it into standby or hibernation so that the computer isnt just running all night.
I tried to make a timed shut down off the power options (as in Hibernate after 40 minutes) but in the morning my computer was still running so I don't really know what happened there. I think it was becaus a message box is desplayed at the end saying that the program is finished and the computer wasn't actually idle while that box was displayed so it never activated the "hibernate after 40 minutes" option
Thoughts?
-
Dec 11th, 2010, 05:29 PM
#4
Re: Shutting down/standby/or hibernate windows with VB6
I think the only reason the first code is so long is to that the user can decide if they want to shut down/restart/log off, etc.
in that case try cutting all the options and just call shutdown with value of ewx_force
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 12th, 2010, 12:33 AM
#5
Thread Starter
New Member
Re: Shutting down/standby/or hibernate windows with VB6
Originally Posted by westconn1
in that case try cutting all the options and just call shutdown with value of ewx_force
ok i simplified it down into this code:
Code:
Private Declare Function Shutdown Lib "user32" Alias _
"ExitWindowsEx" (ByVal uFlags As Long, ByVal _
dwReserved As Long) As Long
Option Explicit
Private Sub Command1_Click()
Shutdown 0, 0
End Sub
it works with values of "0, 0" (log off) and "4, 0" (force log off)
but nothing happens when i click it for values of "1, 0" (shut down) and "2, 0" (reboot)
Last edited by Tagger 24; Dec 12th, 2010 at 12:34 AM.
Reason: clarifying
-
Dec 12th, 2010, 01:41 AM
#6
Re: Shutting down/standby/or hibernate windows with VB6
but nothing happens when i click it for values of "1, 0" (shut down) and "2, 0" (reboot)
probably waiting for some user interaction, if unattended shutdown, use force
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 12th, 2010, 02:59 AM
#7
Re: Shutting down/standby/or hibernate windows with VB6
From the Microsoft documentation for ExitWindowsEx (http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx)
To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information, see Running with Special Privileges.
Even though the process is asynchronous, you ought to be checking the return value from the function.
-
Dec 12th, 2010, 09:06 AM
#8
Re: Shutting down/standby/or hibernate windows with VB6
While you're at it you may want to consider how Anti-Virus software will react to this call if you plan to deploy your app.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing??
-
Dec 15th, 2010, 11:07 PM
#9
Thread Starter
New Member
Re: Shutting down/standby/or hibernate windows with VB6
i kind of found out how to do it.
http://www.vbforums.com/showthread.php?t=396217
this link is to a program that hibernates and unhibernates the computer like an alarm clock - more or less what i wanted. I dont quite understand it but i guess i can try to tinker with it to suit my needs
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|