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 bkrike 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 using VBS?

Thanks,
Dot
 
[1] To put a monitor into a standby mode, the best I can think of is to run the screensaver, xxx.scr, directly with whatever basic method like wshshell.run. This is still the one I would be more likely to recommend.

[2] The sophisticated approach can often backfired. Sometimes, users might no longer be able to wake it up or get so confused and have to reboot.
[2.1] Use sendmessage api of user32 library with parameters wm_syscommand (&h112) and sc_monitorpower (&hf170). The 4th parameter determines whether you want to turnoff (2), standby(1), turnon (-1). The first parameter is some window's handle like the calling form itself.
[tt] sendmessage(me.hwnd,&h112,&f170,1)[/tt]
(me the calling form.)
[2.2] To do it from native vbs, you have to use an extension to wrap the api allowing the script to call the api (not all api with complex data-type, but sendmessage is in the category of allowable api.)
[2.3] You better script a timer to wake it up automatically. Else, users may take the consequence of some bad surprise.
[2.4] Details of the implementations can be found out-there on the net. You won't them miss out doing some search with appropriate keywords such as those used in the above.

[3] wmi has classes implemented to assess the controlling devices, cim_controller, cim_unitarycomputersystem... But, they are more for readonly purposes. Methods are not implemented and in particular, in this context, setpowerstate methods. So, there is something waiting on the line when those methods will be implemented and be available. Not for now.

- tsuji
 
Thanks for your thorough reply, Tsuji, but I really need to know how to put the PC itself into Standby mode, not the monitor...

Thanks,
Dot
 
>I really need to know how to put the PC itself into Standby mode

If you have in mind using api along the line I outline in [2], it would be very similar and I would rather send you directly to vb 5&6 forum for full entertaining where you should find more ideas, and that I have done my bit on this topic with the above and worn out for the day---unless you still do not find satisfaction there later.

I think [3] will have same functionality along the line in the future.

As a supplement note: I think you can as well use small utility (some .exe) to do it through vbs if scripting is the media you use to get to it. You won't fail to find some on the net, even open source. Some might find it unattractive for doing so due to some psychological barrier with some fixed idea behind on what programming is. I don't.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top