ASP.NET电脑自动关机代码 求一段ASP.NET技术设置一个按钮电脑就可以关机的代码,小生只会ASP.NET技术,VB什么都不会, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System; using System.Runtime.InteropServices; class shoutdown{ [StructLayout(LayoutKind.Sequential, Pack=1)] internal struct TokPriv1Luid { public int Count; public long Luid; public int Attr; } [DllImport("kernel32.dll", ExactSpelling=true) ] internal static extern IntPtr GetCurrentProcess(); [DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ] internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok ); [DllImport("advapi32.dll", SetLastError=true) ] internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid ); [DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ] internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen ); [DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ] internal static extern bool ExitWindowsEx( int flg, int rea ); internal const int SE_PRIVILEGE_ENABLED = 0x00000002; internal const int TOKEN_QUERY = 0x00000008; internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege"; internal const int EWX_LOGOFF = 0x00000000; internal const int EWX_SHUTDOWN = 0x00000001; internal const int EWX_REBOOT = 0x00000002; internal const int EWX_FORCE = 0x00000004; internal const int EWX_POWEROFF = 0x00000008; internal const int EWX_FORCEIFHUNG = 0x00000010; private static void DoExitWin(int flg) { bool ok; TokPriv1Luid tp; IntPtr hproc = GetCurrentProcess(); IntPtr htok = IntPtr.Zero; ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok ); tp.Count = 1; tp.Luid = 0; tp.Attr = SE_PRIVILEGE_ENABLED; ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid ); ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero ); ok = ExitWindowsEx( flg, 0 ); } public static void Main() { Console.WriteLine("正在关机……"); // 修改 EWX_SHUTDOWN 或者 EWX_LOGOFF, EWX_REBOOT等实现不同得功能。 // 在XP下可以看到帮助信息,以得到不同得参数 // SHUTDOWN /? DoExitWin(EWX_SHUTDOWN); } } 1楼的代码只能关服务器哦.如果要控制客户端,可以设计一个Activex,或下一下 运行shutdown -r -f -c "重新启动"shutdown -s -f -c "叫你关机" 应该做成activeX给客户端下载后,调用执行关机。但是一般会被用户的IE屏蔽掉,所以下载前要给用户提示。 一楼的api应该可以的另外用shutdown应该可以,你用代码执行cmd语句就可以了shutdown命令的语法格式如下: shutdown [-i -l -s -r -a] [-f] [-m [\\ComputerName]] [-t xx] [-c "message"] [-d[p]:xx:yy] 其中,各参数的含义为: -i 显示图形界面的对话框。 -l 注销当前用户,这是默认设置。-m ComputerName 优先。 -s 关闭计算机。 -r 关闭之后重新启动。 -a 中止关闭。除了 -l 和 ComputerName 外,系统将忽略其它参数。在超时期间,您只可以使用 -a。 -f 强制运行要关闭的应用程序。 -m [\\ComputerName] 指定要关闭的计算机。 -t xx 将用于系统关闭的定时器设置为 xx 秒。默认值是 20 秒。 -c "message" 指定将在“系统关闭”窗口中的“消息”区域显示的消息。最多可以使用 127 个字符。引号中必须包含消息。 -d [p]:xx:yy 列出系统关闭的原因代码。 如果不用activeX那,我想做的功能是,我在网页上有一个按钮,如果我点了这个按钮之后,电脑会关机,就是说,当用 游览器游览我的网页的时候,没有安全阻拦,也不用什么安装什么,不知道这样可行不可行 Winform修改APP.config数据库连接串的问题. 如何调用本地收藏夹收藏的网址前面的那个小图标? ?求助 js 获取多个dropdownlist值的和 求一条正则 从40个数字中随机抽取数 问个C#中的Math.Tan函数 请问ListItem类 在新建类中定义 public static bool 查询用户(string 取得用户名) ,无法调用~ 关于利用Crystal Report .net制作动态报表的问题? 高分求解,关于主从表的数据绑定问题,高手请进 ???? 关于app.config的疑问
using System.Runtime.InteropServices;
class shoutdown{
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
} [DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern IntPtr GetCurrentProcess(); [DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok ); [DllImport("advapi32.dll", SetLastError=true) ]
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid ); [DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen ); [DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flg, int rea ); internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010; private static void DoExitWin(int flg)
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
} public static void Main()
{
Console.WriteLine("正在关机……");
// 修改 EWX_SHUTDOWN 或者 EWX_LOGOFF, EWX_REBOOT等实现不同得功能。
// 在XP下可以看到帮助信息,以得到不同得参数
// SHUTDOWN /?
DoExitWin(EWX_SHUTDOWN);
}
}
shutdown命令的语法格式如下: shutdown [-i -l -s -r -a] [-f] [-m [\\ComputerName]] [-t xx] [-c "message"] [-d[p]:xx:yy] 其中,各参数的含义为: -i 显示图形界面的对话框。
-l 注销当前用户,这是默认设置。-m ComputerName 优先。
-s 关闭计算机。
-r 关闭之后重新启动。
-a 中止关闭。除了 -l 和 ComputerName 外,系统将忽略其它参数。在超时期间,您只可以使用 -a。
-f 强制运行要关闭的应用程序。
-m [\\ComputerName] 指定要关闭的计算机。
-t xx 将用于系统关闭的定时器设置为 xx 秒。默认值是 20 秒。
-c "message" 指定将在“系统关闭”窗口中的“消息”区域显示的消息。最多可以使用 127 个字符。引号中必须包含消息。 -d [p]:xx:yy 列出系统关闭的原因代码。
就是说,当用 游览器游览我的网页的时候,没有安全阻拦,也不用什么安装什么,不知道这样可行不可行