Skip to content

Instantly share code, notes, and snippets.

@Ishibasystems
Created December 22, 2017 14:08
Show Gist options
  • Save Ishibasystems/58e261c721ff56099b20644a88d51f47 to your computer and use it in GitHub Desktop.
Save Ishibasystems/58e261c721ff56099b20644a88d51f47 to your computer and use it in GitHub Desktop.
コマンドラインからWindowsをスリープする
/* SetSuspendState suspend.c */
/* コマンドラインからWindowsをスリープする */
/* 2017.12.22, 10RU004, 石橋祥太 */
/* lcc-win32、lcc-win64でコンパイル確認 */
/* lcc.exe suspend.c */
/* lcclnk.exe -subsystem windows -o suspend.exe suspend.obj */
/* del suspend.obj */
#include <windows.h>
typedef BOOL ( WINAPI *Func ) ( BOOL, BOOL, BOOL );
int main ( HINSTANCE hCurInst, HINSTANCE hPrevInst, WCHAR* lpsCmdLine, int nCmdShow )
{
BOOL res = 0;
Func f;
HMODULE hMod = LoadLibrary ( "powrprof.dll" );
if ( hMod != NULL )
{
f = ( Func ) GetProcAddress ( hMod, "SetSuspendState" );
if ( f ) res = ( *f ) ( FALSE, FALSE, FALSE );
FreeLibrary ( hMod );
}
return ( res == 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment