Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically putting a PC into Standby mode

Status
Not open for further replies.

DotNetter

Programmer
May 19, 2005
194
US
How can you put an XP PC into "standby" mode in VB.NET? How about having a program "log off" a user (out of the OS)?

Thanks,
Dot
 
My PC has both hibernate and suspend enabled - I use them regularly.
 
Since I've tried the suggestions and it seems no one's code works on my PCs (both at home and at work) - although both of them do support Standby and Hibernate mode...

Can anyone suggest a way to log-out using VB.NET?

Thanks (yet again)!
Dot
 
Just a thought - VB Script seems to be able to do most things. Why don't you ask on there, forum 329, and then if they come up with a solution, use the scripting runtime to include it in your VB.NET program.
 
you can also look into the shutdown command in XP. you can use a shell statement to call it, I'm not sure if it support hibernate though.

Most of what I saw on the net for hib/suspend delt with finding the correct dll. If the hibernate/suspend system is being controled by a different set of drivers then the core windows (kernel32) then it won't work. See if there are settings for suspend more in your graphics settings, if so, disable them and set it up in the system settings.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I posted to thread329-1088571 and will post back here with any "winning answers"...

In the meantime, if anyone knows how to do this in pure VB.NET, please post here. BTW, could anyone get their computers to go into standby mode with the code posted above?

Thanks!
Dot
 
Wait a second, as I mentioned, I found that this can be done using the Windows API SetSystemPowerState - no one commented on that. Any suggestions?

Dot
 
Oops - I don't know a whole lot about this, as just became glaringly obvious (in case it wasn't before). I thought that was Rick's own implementation of it...

[blush]
Dot
 
Because the function is in a Win32 dll that Microsoft has not yet incorporated into the .NET Framework we need to tell our program where to find it and what its called:

Declare Function SetSystemPowerState Lib "kernel32" (ByVal fSuspend As Integer, ByVal fForce As Integer) As Integer

Then we can use the function so for example - assume you have a button on your form called btnStandby

In its Click event you would put:
SetSystemPowerState(1,0)


Hope this helps.

 
I do understand - that is what I tried (in a click event) - but unfortunately it didn't work.

Dot
 
I beleive the problem is that kernel32 is not controling your system's suspend mode. There was a thread about this on another forum and the person figure out that he had to use his video card's drivers. The code was exactly the same, but he had a different dll listed then kernel32.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
You ARE using that API. The CORRECT CODE has been posted. The problem is with the configuration of your computer. Using that API from the Kernal32 library will only work if Kernal32 is controling your machines sleep state. It is possible that your video card driver is actually controlling the sleep state, if it is, you either need to call the set power state from that DLL or turn off your video cards sleep state control and turn on the windows sleep state control.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
[nosmiley] [sniffle]

How can I determine which is the right DLL for my video card driver/PC?

Thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top