问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Runtime.InteropServices;namespaceshoutdown{classProgram{[StructLayout(LayoutKind.Sequential,Pack=1)]internalstructTokPriv1Luid{publicintCount;publiclongLuid;publicintAttr;}[DllImport("kernel32.dll",ExactSpelling=true)]internalstaticexternIntPtrGetCurrentProcess();[DllImport("advapi32.dll",ExactSpelling=true,SetLastError=true)]internalstaticexternboolOpenProcessToken(IntPtrh,intacc,refIntPtrphtok);[DllImport("advapi32.dll",SetLastError=true)]internalstaticexternboolLookupPrivilegeValue(stringhost,stringname,reflongpluid);[DllImport("advapi32.dll",ExactSpelling=true,SetLastError=true)]internalstaticexternboolAdjustTokenPrivileges(IntPtrhtok,booldisall,refTokPriv1Luidnewst,intlen,IntPtrprev,IntPtrrelen);[DllImport("user32.dll",ExactSpelling=true,SetLastError=true)]internalstaticexternboolExitWindowsEx(intflg,intrea);internalconstintSE_PRIVILEGE_ENABLED=0x00000002;internalconstintTOKEN_QUERY=0x00000008;internalconstintTOKEN_ADJUST_PRIVILEGES=0x00000020;internalconststringSE_SHUTDOWN_NAME="SeShutdownPrivilege";internalconstintEWX_LOGOFF=0x00000000;internalconstintEWX_SHUTDOWN=0x00000001;internalconstintEWX_REBOOT=0x00000002;internalconstintEWX_FORCE=0x00000004;internalconstintEWX_POWEROFF=0x00000008;internalconstintEWX_FORCEIFHUNG=0x00000010;privatestaticvoidDoExitWin(intflg){TokPriv1Luidtp;IntPtrhproc=GetCurrentProcess();IntPtrhtok=IntPtr.Zero;OpenProcessToken(hproc,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,refhtok);tp.Count=1;tp.Luid=0;tp.Attr=SE_PRIVILEGE_ENABLED;LookupPrivilegeValue(null,SE_SHUTDOWN_NAME,reftp.Luid);AdjustTokenPrivileges(htok,false,reftp,0,IntPtr.Zero,IntPtr.Zero);ExitWindowsEx(flg,0);}publicstaticvoidMain(){Console.WriteLine("正在关机……");//修改EWX_SHUTDOWN或者EWX_LOGOFF,EWX_REBOOT等实现不同得功能。//在XP下可以看到帮助信息,以得到不同得参数//SHUTDOWN/?DoExitWin(EWX_SHUTDOWN);}}}这是一个windows关机程序,我想问:internalconstintSE_PRIVILEGE_ENABLED=0x00000002;internalconstintTOKEN_QUERY=0x00000008;internalconstintTOKEN_ADJUST_PRIVILEGES=0x00000020;internalconststringSE_SHUTDOWN_NAME="SeShutdownPrivilege";internalconstintEWX_LOGOFF=0x00000000;internalconstintEWX_SHUTDOWN=0x00000001;internalconstintEWX_REBOOT=0x00000002;internalconstintEWX_FORCE=0x00000004;internalconstintEWX_POWEROFF=0x00000008;internalconstintEWX_FORCEIFHUNG=0x00000010;这些"值",比喻:把"0x00000001"赋值给EWX_SHUTDOWN,这个值是怎么来的?自己可以糊乱加上去吗(当然是int类型)?
解决方案
解决方案二:
这些值应该是消息常量标识符,不是随便写的,你google以下window系统消息大全就能查到那些值都是什么意思了。
解决方案三:
在网上找不到啊,还有其它答案吗,就没有人知道吗,唉,我自己再顶下