关于强制关机(50分)

  • 主题发起人 主题发起人 fire.bruin
  • 开始时间 开始时间
F

fire.bruin

Unregistered / Unconfirmed
GUEST, unregistred user!
程序如何做到强制关机呀?我做的关机程序,当有共享时会弹出提示,必须关闭提示后才能关机。
 
ExitWindowsEx(EWX_FORCE or EWX_FORCEIFHUNG or EWX_SHUTDOWN, 0);
 
用ExitWindowsEx(EWX_FORCE or EWX_FORCEIFHUNG or EWX_SHUTDOWN, 0);  这个是没有的,会要求对提示做出选择。
 
用ExitWindowEx是没错,提示不提示是参数设置的问题,有些软件检测到被修改后,直接调用这个东西给你关机
 
luoxipo, 没明白你的意思!
 
我意思就是:用这个api,可以不出提示,直接关机
 
好象不行!如果有共享,别的机器使用了你的共享文件就关不了,一定要把提示关了。当然也有可能是我的参数不对。有QQ吗?我的QQ:40761486
 
用InitiateSystemShutdownEx或InitiateSystemShutdown试试
 
最强悍的强制关机方法<br>切断电源
 
TO 上一位,<br>直接把电厂炸了算了
 
楼上两位都他妈的有病,要么就是恐怖份子!
 
//单击按扭关闭计算机<br>procedure TForm_button1Click(Sender: TObject);<br> &nbsp;var<br> &nbsp; &nbsp;st:SYSTEMTIME;<br> &nbsp; &nbsp;hToken:THANDLE;<br> &nbsp; &nbsp;tkp:TOKEN_PRIVILEGES;<br> &nbsp; &nbsp;rr:Dword;<br>begin<br> &nbsp;if application.MessageBox('真的关闭计算机吗?','提示',mb_yesno)=idyes then<br> &nbsp;begin<br> &nbsp; &nbsp;openProcessToken(GetcurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);<br> &nbsp; &nbsp;LookupPrivilegeValue(nil,'seshutdownPrivilege',tkp.privileges[0].luid);<br> &nbsp; &nbsp;tkp.Privilegecount:=1;<br> &nbsp; &nbsp;tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;<br> &nbsp; &nbsp;AdjustTokenPrivileges(hToken,FALSE,tkp,0,nil,rr);<br> &nbsp; &nbsp;exitwindowsEx(EWX_POWEROFF,0);<br> &nbsp;end;<br>end;
 
在win2000/xp等非98系统上,可能要求先获取系统权限级别再调用关机的那个api才不会提示信息
 
有没有高人知道怎么禁止别的程序强制关机吗?<br>就是别的程序执行ExitWindowsEx(EWX_FORCE or EWX_FORCEIFHUNG or EWX_SHUTDOWN, 0);也不会关机。
 
procedure AdjustToken; //获取2000下的关机权限<br>var<br> &nbsp;hdlProcessHandle: Cardinal;<br> &nbsp;hdlTokenHandle: Cardinal;<br> &nbsp;tmpLuid: Int64;<br> &nbsp;tkp: TOKEN_PRIVILEGES;<br> &nbsp;tkpNewButIgnored: TOKEN_PRIVILEGES;<br> &nbsp;lBufferNeeded: Cardinal;<br> &nbsp;Privilege: array[0..0] of _LUID_AND_ATTRIBUTES;<br>begin<br> &nbsp;hdlProcessHandle := GetCurrentProcess;<br> &nbsp;OpenProcessToken(hdlProcessHandle,<br> &nbsp; &nbsp;(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY), hdlTokenHandle);<br> &nbsp;LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);<br> &nbsp;Privilege[0].Luid := tmpLuid;<br> &nbsp;Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;<br> &nbsp;tkp.PrivilegeCount := 1;<br> &nbsp;tkp.Privileges[0] := Privilege[0];<br> &nbsp;AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Sizeof(tkpNewButIgnored),<br> &nbsp; &nbsp;tkpNewButIgnored, lBufferNeeded);<br>end;<br><br>procedure &nbsp;TForm1.Button1Click(Sender: TObject);<br>begin<br>AdjustToken;<br>ExitWindowsEx(EWX_POWEROFF, 0)<br>end;<br><br>试一下这个行不?
 
关机不一定要提高权限,禁止别的程序关机可以hook掉ExitWindow这个api
 
var<br> &nbsp;OS: TOSVersionInfo;<br> &nbsp;OSName: String;<br> &nbsp;hToken:THandle;<br> &nbsp;tkp:TTokenPrivileges;<br> &nbsp;tkpo:TTokenPrivileges;<br> &nbsp;zero:DWORD;<br>begin<br> &nbsp;OS.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);<br> &nbsp;if GetVersionEx(OS) = True then<br> &nbsp;begin<br> &nbsp; &nbsp;case OS.dwPlatformId of<br> &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32s : OSName := 'Windows 3.1/Win32s';<br> &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32_WINDOWS : OSName := 'Windows';<br> &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32_NT : OSName := 'Windows NT';<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp; if timetostr(timep.Time)=timetostr(time) then begin<br> &nbsp; &nbsp; if OSName= 'Windows' then &nbsp;exitwindowsex(EWX_POWEROFF,0);<br> &nbsp; &nbsp; if OSName = 'Windows NT' &nbsp;then begin<br> &nbsp; &nbsp; &nbsp; zero:=0;<br> &nbsp; &nbsp; &nbsp; OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);<br> &nbsp; &nbsp; &nbsp; LookupPrivilegeValue(nil,SE_SHUTDOWN_NAME,tkp.Privileges[0].Luid);<br> &nbsp; &nbsp; &nbsp; tkp.PrivilegeCount:=1;<br> &nbsp; &nbsp; &nbsp; tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;<br> &nbsp; &nbsp; &nbsp; AdjustTokenPrivileges(hToken,False,tkp,SizeOf(TTokenPrivileges),tkpo,zero);<br> &nbsp; &nbsp; &nbsp; //以上代码获取权限<br> &nbsp; &nbsp; &nbsp; ExitWindowsEx(EWX_POWEROFF,0);<br> &nbsp; &nbsp; end;<br> &nbsp; end;<br>end;
 
还是没人解出来,针对本问题强调一点:系统关机权限已提升!
 
winexec('shutdown.exe -s -f -t 00',SW_HIDE);<br>这个与权限无关.
 
多人接受答案了。
 
后退
顶部