📄 program.cs
字号:
namespace Imps.Client.Pc
{
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
internal static class Program
{
private const int BUFSIZE = 0x3e8;
private const int TOKEN_ADJUST_PRIVILEGES = 0x20;
private const int TOKEN_QUERY = 8;
[DllImport("kernel32.dll", ExactSpelling=true)]
internal static extern IntPtr GetCurrentProcess();
[DllImport("advapi32", CharSet=CharSet.Auto)]
private static extern bool GetTokenInformation(IntPtr hToken, TOKEN_INFORMATION_CLASS tokenInfoClass, IntPtr TokenInformation, int tokeInfoLength, ref int reqLength);
[STAThread]
private static void Main(string[] args)
{
Thread.CurrentThread.Name = "Imps.Client.Pc MainThread";
Application.EnableVisualStyles();
ServicePointManager.MaxServicePointIdleTime = 0x7530;
try
{
IntPtr h = GetCurrentProcess();
IntPtr phtok = IntPtr.Zero;
if (!OpenProcessToken(h, 40, ref phtok))
{
goto Label_008C;
}
IntPtr tokenInformation = Marshal.AllocHGlobal(0x3e8);
int tokeInfoLength = 0x3e8;
GetTokenInformation(phtok, TOKEN_INFORMATION_CLASS.TokenPrivileges, tokenInformation, tokeInfoLength, ref tokeInfoLength);
TokPriv1Luid luid = (TokPriv1Luid) Marshal.PtrToStructure(tokenInformation, typeof(TokPriv1Luid));
if (luid.Count > 1)
{
goto Label_008C;
}
MessageBox.Show("运行此程序的权限不够!");
}
catch
{
}
return;
Label_008C:
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(args));
}
[DllImport("advapi32.dll", SetLastError=true, ExactSpelling=true)]
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
private enum TOKEN_INFORMATION_CLASS
{
TokenDefaultDacl = 6,
TokenGroups = 2,
TokenImpersonationLevel = 9,
TokenOwner = 4,
TokenPrimaryGroup = 5,
TokenPrivileges = 3,
TokenRestrictedSids = 11,
TokenSessionId = 12,
TokenSource = 7,
TokenStatistics = 10,
TokenType = 8,
TokenUser = 1
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -