BOOL MySystemShutdown()但是是用SDK 寫的。
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
SHTDN_REASON_MINOR_UPGRADE |
SHTDN_REASON_FLAG_PLANNED))
return FALSE;
return TRUE;
}
要找一找這些typedef的原型是甚麼...
可以用Visual Studio , New 一個Win32App,加入API Name,就可以用 Go to Definition .. 到declaration 的地方Visual Studio 和 CodeWarrior, SourceInsight 不一樣,winbase.h
不需要build project就可以做到cross-ref edit(browse)HANDLE GetCurrentProcess( ) : kerne32.dll這麼多typedef ,怎麼找 @_@....
BOOL OpenProcessToken ( // int
HANDLE ProcessHandle, // void*
DWORD DesiredAccess, // unsigned long
HANDLE* TokenHandle // void**
) : advapi32.dll
winbase.h
BOOL LookupPrivilegeValue : ( // int
LPCTSTR lpSystemName, // wchar_t
LPCTSTR lpName, // wchar_t
PLUID lpLuid // ----- structre
) : advapi32.dll
typedef struct _LUID {
DWORD LowPart; // unsigned long
LONG HighPart; // long
} LUID, *PLUID;
win
BOOL AdjustTokenPrivileges( // int
HANDLE TokenHandle, // void
BOOL DisableAllPrivileges, // int
PTOKEN_PRIVILEGES NewState, // --- structure
DWORD BufferLength, // unsigned long
PTOKEN_PRIVILEGES PreviousState, // --- structure
PDWORD ReturnLength // unsigned long
) : advapi32.dll
typedef struct _TOKEN_PRIVILEGES {
DWORD PrivilegeCount; // unsigned long
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]; // --- structure, ANYSIZE_ARRAY = 1
} TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
typedef struct _LUID_AND_ATTRIBUTES {
LUID Luid; // --- structure - prev
DWORD Attributes; // unsigned long
} LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
winbase.h
WINBASEAPI
DWORD // unsigned long
WINAPI
GetLastError() : kernel32.dll
winuser.h
BOOL WINAPI ExitWindowsEx( // int
UINT uFlags, // unsigned int
DWORD dwReason // unsigned long
) : user32.dll
利用Visual Studio來找... Create一個Win32 Form App.
到sourcecode...按右鍵就有 - Goto Definition.
在windef.h中有定義
HANDLE : void*
BOOL : int
DWORD : unsigned long
...其實直接在Visual Studio中用 Go to Definition..反覆 就可以到 type definition的地方。
星期三, 7月 05, 2006
More on Shutdown
這一篇msdn是Shutdown的步驟 :
沒有留言:
張貼留言