救救我呀(0分)

  • 主题发起人 主题发起人 阿宏
  • 开始时间 开始时间

阿宏

Unregistered / Unconfirmed
GUEST, unregistred user!
我用D6做的。<br>语句如下:<br>....<br>begin<br>&nbsp; &nbsp; exitwindowsex(ewx_shutdown and ewx_poweroff,1);<br>end;<br><br>可是它只做注销。<br><br>我想用API &nbsp; &nbsp;Initiatesystemshutdown()<br>不知道有没有那位大哥做过。帮帮小弟。<br>
 
是想直接关机吗?,试试这个:<br>&nbsp; ExitWindowsEx(EWX_FORCE,0)<br>
 
你在什么系统下?<br>nt和2000需要有权限。
 
转载:<br>function GetWinVersion: String;<br>&nbsp; var<br>&nbsp; &nbsp; &nbsp;VersionInfo : TOSVersionInfo;<br>&nbsp; &nbsp; &nbsp;OSName &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;// set the size of the record<br>&nbsp; &nbsp; &nbsp;VersionInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo );<br>&nbsp; <br>&nbsp; &nbsp; &nbsp;if Windows.GetVersionEx( VersionInfo ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with VersionInfo do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case dwPlatformId of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32s &nbsp; : OSName := 'Win32s';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32_WINDOWS : OSName := 'Windows 95';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32_NT &nbsp; &nbsp; &nbsp;: OSName := 'Windows NT';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // case dwPlatformId<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := OSName + ' Version ' + IntToStr( dwMajorVersion ) + '.' + IntToStr( dwMinorVersion ) +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #13#10' (Build ' + IntToStr( dwBuildNumber ) + ': ' + szCSDVersion + ')';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; // with VersionInfo<br>&nbsp; &nbsp; &nbsp; &nbsp; end // if GetVersionEx<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := '';<br>&nbsp; end;<br>&nbsp; <br>&nbsp; procedure ShutDown;<br>&nbsp; const<br>&nbsp; &nbsp; SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; &nbsp; // Borland forgot this declaration<br>&nbsp; var<br>&nbsp; &nbsp; hToken &nbsp; &nbsp; &nbsp; : THandle;<br>&nbsp; &nbsp; tkp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TTokenPrivileges;<br>&nbsp; &nbsp; tkpo &nbsp; &nbsp; &nbsp; &nbsp; : TTokenPrivileges;<br>&nbsp; &nbsp; zero &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br>&nbsp; begin<br>&nbsp; &nbsp; if Pos( 'Windows NT', GetWinVersion) = 1 &nbsp;then // we've got to do a whole buch of things<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; zero := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br>&nbsp; <br>&nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // SE_SHUTDOWN_NAME<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'LookupPrivilegeValue() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; // if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[0].Luid )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tkp.PrivilegeCount := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br>&nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Boolean( GetLastError() ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'AdjustTokenPrivileges() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end // if Boolean( GetLastError() )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );<br>&nbsp; &nbsp; &nbsp; &nbsp; end // if OSVersion = 'Windows NT'<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; begin // just shut the machine down<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );<br>&nbsp; &nbsp; &nbsp; &nbsp; end; // else<br>&nbsp; end;<br>
 

Similar threads

D
回复
0
查看
785
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
I
回复
0
查看
746
import
I
后退
顶部