⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c#关机.htm

📁 C#关机.rar
💻 HTM
📖 第 1 页 / 共 4 页
字号:
                          <P>[DllImport("advapi32.dll", ExactSpelling=<FONT 
                          color=#0000ff>true</FONT>, SetLastError=<FONT 
                          color=#0000ff>true</FONT>) ]</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>static</FONT> <FONT 
                          color=#0000ff>extern</FONT> <FONT 
                          color=#0000ff>bool</FONT> AdjustTokenPrivileges( 
                          IntPtr htok, <FONT color=#0000ff>bool</FONT> 
                          disall,</P>
                          <P><FONT color=#0000ff>ref</FONT> TokPriv1Luid newst, 
                          <FONT color=#0000ff>int</FONT> len, IntPtr prev, 
                          IntPtr relen );</P>
                          <P>[DllImport("user32.dll", ExactSpelling=<FONT 
                          color=#0000ff>true</FONT>, SetLastError=<FONT 
                          color=#0000ff>true</FONT>) ]</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>static</FONT> <FONT 
                          color=#0000ff>extern</FONT> <FONT 
                          color=#0000ff>bool</FONT> ExitWindowsEx( <FONT 
                          color=#0000ff>int</FONT> flg, <FONT 
                          color=#0000ff>int</FONT> rea );</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> SE_PRIVILEGE_ENABLED = 
                          0x00000002;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> TOKEN_QUERY = 0x00000008;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> TOKEN_ADJUST_PRIVILEGES = 
                          0x00000020;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>string</FONT> SE_SHUTDOWN_NAME = 
                          "SeShutdownPrivilege";</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> EWX_LOGOFF = 0x00000000;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> EWX_SHUTDOWN = 
0x00000001;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> EWX_REBOOT = 0x00000002;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> EWX_FORCE = 0x00000004;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> EWX_POWEROFF = 
0x00000008;</P>
                          <P><FONT color=#0000ff>internal</FONT> <FONT 
                          color=#0000ff>const</FONT> <FONT 
                          color=#0000ff>int</FONT> EWX_FORCEIFHUNG = 
                          0x00000010;</P><FONT size=1>
                          <P> </P>
                          <P></FONT><FONT color=#0000ff>private</FONT> <FONT 
                          color=#0000ff>void</FONT> DoExitWin( <FONT 
                          color=#0000ff>int</FONT> flg )</P>
                          <P>{</P>
                          <P><FONT color=#0000ff>bool</FONT> ok;</P>
                          <P>TokPriv1Luid tp;</P>
                          <P>IntPtr hproc = GetCurrentProcess();</P>
                          <P>IntPtr htok = IntPtr.Zero;</P>
                          <P>ok = OpenProcessToken( hproc, 
                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, <FONT 
                          color=#0000ff>ref</FONT> htok );</P>
                          <P>tp.Count = 1;</P>
                          <P>tp.Luid = 0;</P>
                          <P>tp.Attr = SE_PRIVILEGE_ENABLED;</P>
                          <P>ok = LookupPrivilegeValue( <FONT 
                          color=#0000ff>null</FONT>, SE_SHUTDOWN_NAME, <FONT 
                          color=#0000ff>ref</FONT> tp.Luid );</P>
                          <P>ok = AdjustTokenPrivileges( htok, <FONT 
                          color=#0000ff>false</FONT>, <FONT 
                          color=#0000ff>ref</FONT> tp, 0, IntPtr.Zero, 
                          IntPtr.Zero );</P>
                          <P>ok = ExitWindowsEx( flg, 0 );</P>
                          <P>}</P></BLOCKQUOTE></TD></TR>
                    <TR>
                      <TD 
                      style="PADDING-RIGHT: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; WIDTH: 99.38%; PADDING-TOP: 0.75pt" 
                      width="99%"> </TD></TR></TBODY></TABLE>
                  <P>如果您想实现关机,重启等操作,只需拷贝上面的代码,并调用DoExitWin函数就行了。重启就使用DoExitWin(EWX_REBOOT),关机就使用DoExitWin(EWX_SHUTDOWN)等</P>
                  <P> </P></SPAN></TD></TR>
              <TR>
                <TD width="50%"></TD>
                <TD width="50%"><BR></TD></TR>
              <TR>
                <TD align=right colSpan=2><IMG src="C#关机.files/bbstitle.gif" 
                  border=0><A id=hlkAddRMsg style="COLOR: red" 
                  href="http://www.aspcn.com/News/AddMsg.aspx?id=479">发表您的意见</A> 
                  <IMG src="C#关机.files/mail.gif" border=0><A id=hlkMailTo 
                  href="http://www.aspcn.com/News/MailTo.aspx?id=479">邮寄本页</A> 
                  <IMG src="C#关机.files/print.gif" border=0><A 
                  href="javascript:window.print()">打印本页</A> <IMG 
                  src="C#关机.files/profile.gif" border=0><A 
                  onclick="if(!document.execCommand('SaveAs','show.aspx',1)) return false;" 
                  href="javascript:void(null)">保存本页</A> <IMG 
                  src="C#关机.files/ask.gif" border=0><A 
                  href="http://www.aspcn.com/News/bbs/index.asp">您有疑问</A> </TD></TR>
              <TR bgColor=#97b9ff>
                <TD width="50%"><B><FONT color=#ffffff>相关文章</FONT></B></TD>
                <TD width="50%"><B><FONT color=#ffffff>相关评论</FONT></B></TD></TR>
              <TR>
                <TD vAlign=top width="50%"></TD>
                <TD vAlign=top width="50%"></TD></TR>
              <TR>
                <TD width="50%"></TD>
                <TD align=right width="50%"><IMG src="C#关机.files/more.gif" 
                  border=0></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM></TD></TR></TBODY></TABLE></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -