C#下怎么提升进程权限?
这是我的代码..
#region 权限处理
[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);
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";
const int PROCESS_ALL_ACCESS = 0x001F0FFF;
#endregion
public void test()
{
TokPriv1Luid tp;
//IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
bool ok = OpenProcessToken(GetCurrentProcess(), 0x001F0FFF, ref htok);
MessageBox.Show(ok.ToString());
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
LookupPrivilegeValue(null, "SeDebugPrivilege", ref tp.Luid);
AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
ok = ok;
}
要怎样改才能做到呢? --------------------编程问答-------------------- 专业打捞沉帖 --------------------编程问答-------------------- 严重支持
补充:.NET技术 , C#