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 John Tel 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
 
you can create a button that executes a .bat file


.bat file shout countain


shutdown /s

this wile completly turn of pc
for more info about shutdown and more options
type " shutdown /? " in dos-console

dosconsole = win-key+R --> cmd ----> ok
 
Yeah

type "shutdown" or "shutdown -?" to see the help. Then:

System.Diagnostics.Process.Start("shutdown", "-r") for example to restart the pc (windows XP!).

System.Diagnostics.Process.Start("shutdown -r") will not work because the command is "shutdown" and the arguments is "-r"

:)
 
Thank you, but how can I use that to put the PC into standby mode?

Thanks!
Dot
 
I found that it can be done using the Windows API SetSystemPowerState. But how do I call it with VB.NET?

Thanks,
Dot
 
Try:

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

when you call the function:

fSuspend and fForce are declared as BOOL in the SDK, so presumably you will need 0 for false and non-zero for true. The return value is also BOOL.

Hope this helps.

 
EarthAndFire,

Thanks for your reply.

Sorry - I don't understand the exact syntax that I should be using to get it to go into Standby mode.

Thanks again,
Dot
 
Code:
Declare Function SetSystemPowerState Lib "kernel32" (ByVal fSuspend As Integer, ByVal fForce As Integer) As Integer

Public Sub GotoStandbyMode
  SetSystemPowerState(0,0)
End Sub

Public Sub LeaveStandbyMode
  SetSystemPowerState(1,0)
End Sub

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks, Rick... It compiled, but didn't do anything...

Dot
 
Rick, shouldn't the set values be 1 as in

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

Public Sub GotoStandbyMode
  SetSystemPowerState([b]1[/b],0)
End Sub

Public Sub LeaveStandbyMode
  SetSystemPowerState([b]0[/b],0)
End Sub

with force set to 1 if its required?
 
Does this work for anyone? I have a "Sleep" key on my keyboard that when I press it - puts the PC into Standby mode. It works. But the code (both Rick's and EarthAndFire's) does not do anything...

Dot
 
I can understand that the program will put the computer in standby mode. But how would you wake it programmatically, since the computer is asleep and does no more processing??

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Doesn't Standby just shut down the harddrive and monitor?

Also, my XP (sp1) machine does not respond to the api. But It needs to be patched and I'll check BIOS for any settings there. Now if I could just get the network staff to unblock Windows Update or hand over SP2.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick
You are not alone in those requests....

Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
Some network staffs. These guys called me "Unprofessional" last week for tracking the location or a web user(Front desk/Service Desk) based off of the workstation's ID. The same guys that haven't applied patches to any of the client machines, the same guys that told me to just ask for a user's password for testing, the same guys that want to push everything to terminal server when we have perfectly good hardware...

I have many requests of my Networkers. Most dealing with removing their heads from dark, cramped, stinky tunnels.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Networkers" aside...

My PC is XP SP2 and I can't get the code (above) to do anything at all, i.e. go into Standby mode.

Any ideas as to why not, please?

Thanks,
Dot
 
Check BIOS. Reboot the machine, hit the "Delete" button. That should bring up the BIOS menu, look through the options there for any power related settings. If you see any signs of hibernate or suspend, make sure they are set to enabled.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top