Monday, March 2, 2009

Put your system to hibernate in a double click

So I am back with more tips for people who are lazy like me.

In one of my earlier, blogs I had mentioned, how lazy I felt to lock my desktop and how I wanted it in a double-click.

Well, being lazy again, now I have decided to put my system in hibernate or standby in a double click too.

Here's the code:

#include "windows.h"
#include "atlbase.h"

void create(TCHAR argv[100])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( & si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( & pi, sizeof(pi) );

// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
argv, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}

// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

}
int _tmain(int argc, _TCHAR* argv[])
{
USES_CONVERSION;
char tmp_path[MAX_PATH];
char cmd[MAX_PATH];
strcpy_s(tmp_path, MAX_PATH,"%windir%\\System32\\rundll32.exe powrprof.dll,SetSuspendState");
ExpandEnvironmentStringsA(tmp_path, cmd, MAX_PATH);

TCHAR* str= A2T(cmd);
create(str);
}

Yahooooo... You are done!

Its too bad that blogger doesnt allow me to upload executables..else I would have just uploaded it for you. Maybe I should start a website for all these executables :)

2 comments:

Alexander said...

Could you send me the executables by email? I am interested in all of them.
My email is alvatov@gmail.com




P.S. I would create a site for the executables. Summerhost is a good hosting, and Dot TK can give you a free forwarding domain.

Dj PoMMe-Lux(e) said...

for rookies like me, what is suposed to do with that code?
With which program shall I compile it?
if you feel on the mood, please, send me the program to pomme_lux@yahoo.es
Thank you :-)