日期:2014-05-20  浏览次数:20985 次

远程关机过程中部分程序出现“是否立即结束”对话框而 中止,如何解决??
进行远程关机。但是在执行了关机命令后,或者调用Win32的API或者调用“cmd.exe”。不知道是我用的不对,还是其他原因。命令执行后,在关机过程中,部分程序,出现是否立即结束的对话框,如迅雷;部分程序可能出现是否保存的对话框,如office。这样,我的远程关机就夭折了。

不知是我代码写的有问题,还是操作系统需要设置什么,还是有更决的方法(我见有个程序,一点关机,什么也不问,1秒不到机器就关了)

现在
请问:各种关机方法。最好有源代码。各种远程强制终止不知名未结束进程的   方法。

过完年回来结贴。如果问题没解决。再开新贴,求教。

------解决方案--------------------
过完年才揭帖?那我仅up了
------解决方案--------------------
远程关机??最终应该还是调用本地的关机指令....
UP
------解决方案--------------------
关机 + 强制结束应用程序

------解决方案--------------------
up
------解决方案--------------------
直接调用shutdown.exe关机,参数可以选择强行关机。
------解决方案--------------------
shutdown -s -t 0
------解决方案--------------------
up
------解决方案--------------------
调用API强制关机
[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;

public void DoExitWin()
{
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( EWX_REBOOT+EWX_FORCE, 0 );
}
------解决方案--------------------
budong,帮顶