一个关机的问题?(API)(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>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>
 
win2000下是注销
 
win98下也是的。
 
zjxxln &nbsp;大哥<br><br>你搞API多久了呀?<br><br>以后能多教教我吗?<br><br>ahon_wu@hotmail.com]<br>qq:37793655
 
getwinversion()和getversionex()是属于同一类型吗?
 
//getwinversion()和getversionex()是属于同一类型吗?<br>getwinversion这个是自定义函数;<br>getversionex是系统调用<br>
 
上面的程序我也是抄别人的;)以后互相学习。qq:3473234
 
你是做什么的呀?
 
我一正有次问题:<br>&nbsp; try<br>&nbsp; &nbsp;ExitWindowsEx(EWX_FORCE OR EWX_LOGOFF,0);//强行结束当前登陆用户进程<br>&nbsp; &nbsp;ExitWindowsEx(EWX_FORCE OR EWX_POWEROFF,0);<br>&nbsp; except<br>&nbsp; end;<br>执行不能强制关机!<br>那位大虾能帮忙讲解一下WINDOWS的关机机制,如何才能顺利的关闭机器?
 
我写个关机程序,但只在98下正常,2000下,也出现了‘windows2000正在关机’字样,<br>但正当屏幕一黑,我以为大功告成了呢,又出来一个提示窗口,然后就此死机。不知是不是<br>我的系统有问题呢?<br><br>关注!
 
这个可以看看msdn里面关于关机的介绍,有一部分详细介绍了怎么关机。<br>好象叫ShutDown reference的~~
 
有一个很有趣的问题,如果在form中加入TNUMDP控件,然后然这个程序运行着,windows<br>就不能关闭了。但我却没有想到用有它时怎么关闭。
 
exitwindowsex(ewx_shutdown and ewx_poweroff,1);<br>肯定是注销<br>exitwindowsex(ewx_poweroff,1);<br>就可以了。具体原因不详!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
916
SUNSTONE的Delphi笔记
S
后退
顶部