本文整理汇总了C#中ProcessHandle.GetToken方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessHandle.GetToken方法的具体用法?C# ProcessHandle.GetToken怎么用?C# ProcessHandle.GetToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessHandle
的用法示例。
在下文中一共展示了ProcessHandle.GetToken方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshProcesses
private void RefreshProcesses()
{
var processes = Windows.GetProcesses();
listProcesses.BeginUpdate();
listProcesses.Items.Clear();
var generic_process = imageList.Images["generic_process"];
imageList.Images.Clear();
imageList.Images.Add("generic_process", generic_process);
foreach (var process in processes.Values)
{
string userName = "";
string fileName = null;
try
{
using (var phandle = new ProcessHandle(process.Process.ProcessId, OSVersion.MinProcessQueryInfoAccess))
{
using (var thandle = phandle.GetToken(TokenAccess.Query))
using (var sid = thandle.GetUser())
userName = sid.GetFullName(true);
fileName = FileUtils.GetFileName(phandle.GetImageFileName());
}
}
catch
{ }
ListViewItem item = new ListViewItem(
new string[]
{
process.Process.ProcessId == 0 ? "System Idle Process" : process.Name,
process.Process.ProcessId.ToString(),
userName
});
if (!string.IsNullOrEmpty(fileName))
{
Icon fileIcon = FileUtils.GetFileIcon(fileName);
if (fileIcon != null)
{
imageList.Images.Add(process.Process.ProcessId.ToString(), fileIcon);
item.ImageKey = process.Process.ProcessId.ToString();
}
}
if (string.IsNullOrEmpty(item.ImageKey))
item.ImageKey = "generic_process";
listProcesses.Items.Add(item);
}
listProcesses.EndUpdate();
}
示例2: virtualizationProcessMenuItem_Click
private void virtualizationProcessMenuItem_Click(object sender, EventArgs e)
{
if (!PhUtils.ShowConfirmMessage(
"set",
"virtualization for the process",
"Enabling or disabling virtualization for a process may " +
"alter its functionality and produce undesirable effects.",
false
))
return;
try
{
using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights))
{
using (var thandle = phandle.GetToken(TokenAccess.GenericWrite))
{
thandle.SetVirtualizationEnabled(!virtualizationProcessMenuItem.Checked);
}
}
}
catch (Exception ex)
{
PhUtils.ShowException("Unable to set process virtualization", ex);
}
}
示例3: menuProcess_Popup
private void menuProcess_Popup(object sender, EventArgs e)
{
virtualizationProcessMenuItem.Checked = false;
// Menu item fixup...
if (treeProcesses.SelectedTreeNodes.Count == 0)
{
// If nothing is selected, disable everything.
// The Select All menu item will be enabled later if
// we have at least one process in the tree.
menuProcess.DisableAll();
}
else if (treeProcesses.SelectedTreeNodes.Count == 1)
{
// All actions should work with one process selected.
menuProcess.EnableAll();
// Singular nouns.
priorityMenuItem.Text = "&Priority";
terminateMenuItem.Text = "&Terminate Process";
suspendMenuItem.Text = "&Suspend Process";
resumeMenuItem.Text = "&Resume Process";
// Check the appropriate priority level menu item.
realTimeMenuItem.Checked = false;
highMenuItem.Checked = false;
aboveNormalMenuItem.Checked = false;
normalMenuItem.Checked = false;
belowNormalMenuItem.Checked = false;
idleMenuItem.Checked = false;
try
{
using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights))
{
switch (phandle.GetPriorityClass())
{
case ProcessPriorityClass.RealTime:
realTimeMenuItem.Checked = true;
break;
case ProcessPriorityClass.High:
highMenuItem.Checked = true;
break;
case ProcessPriorityClass.AboveNormal:
aboveNormalMenuItem.Checked = true;
break;
case ProcessPriorityClass.Normal:
normalMenuItem.Checked = true;
break;
case ProcessPriorityClass.BelowNormal:
belowNormalMenuItem.Checked = true;
break;
case ProcessPriorityClass.Idle:
idleMenuItem.Checked = true;
break;
}
}
}
catch (Exception ex)
{
priorityMenuItem.Text = "(" + ex.Message + ")";
priorityMenuItem.Enabled = false;
}
// Check the virtualization menu item.
try
{
using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights))
{
try
{
using (var thandle = phandle.GetToken(TokenAccess.Query))
{
if (virtualizationProcessMenuItem.Enabled = thandle.IsVirtualizationAllowed())
virtualizationProcessMenuItem.Checked = thandle.IsVirtualizationEnabled();
}
}
catch
{ }
}
}
catch
{
virtualizationProcessMenuItem.Enabled = false;
}
// Enable/disable DLL injection based on the process' session ID. This only applies
// on XP and above.
try
{
if (
OSVersion.IsBelowOrEqual(WindowsVersion.XP) &&
processP.Dictionary[processSelectedPid].SessionId != Program.CurrentSessionId
)
injectDllProcessMenuItem.Enabled = false;
//.........这里部分代码省略.........
示例4: GetProcessDetailsText
//.........这里部分代码省略.........
sb.AppendLine(module.FileName);
sb.Append(" [0x" + module.BaseAddress.ToInt32().ToString("x") + ", ");
sb.AppendLine(Utils.FormatSize(module.Size) + "] ");
sb.AppendLine(" Flags: " + module.Flags.ToString());
try
{
var fileInfo = FileVersionInfo.GetVersionInfo(module.FileName);
sb.AppendLine(" Description: " + fileInfo.FileDescription);
sb.AppendLine(" Company: " + fileInfo.CompanyName);
sb.AppendLine(" Version: " + fileInfo.FileVersion);
}
catch (Exception ex2)
{
sb.AppendLine(" Version info failed! " + ex2.Message);
}
sb.AppendLine();
}
}
}
catch (Exception ex)
{
sb.AppendLine("Modules section failed! " + ex.Message);
}
sb.AppendLine("Token:");
sb.AppendLine();
try
{
using (var phandle = new ProcessHandle(pid, ProcessAccess.QueryLimitedInformation))
using (var thandle = phandle.GetToken(TokenAccess.Query))
{
sb.AppendLine("User: " + thandle.GetUser().GetFullName(true));
sb.AppendLine("Owner: " + thandle.GetOwner().GetFullName(true));
sb.AppendLine("Primary group: " + thandle.GetPrimaryGroup().GetFullName(true));
foreach (var group in thandle.GetGroups())
{
sb.AppendLine("Group " + group.GetFullName(true));
}
foreach (var privilege in thandle.GetPrivileges())
{
sb.AppendLine("Privilege " + privilege.Name + ": " + privilege.Attributes.ToString());
}
}
}
catch (Exception ex)
{
sb.AppendLine("Token section failed! " + ex.Message);
}
sb.AppendLine();
sb.AppendLine("Environment:");
sb.AppendLine();
try
{
using (var phandle = new ProcessHandle(pid, ProcessAccess.QueryInformation | ProcessAccess.VmRead))
{
var vars = phandle.GetEnvironmentVariables();
foreach (var kvp in vars)
示例5: GetProcessSessionId
public static int GetProcessSessionId(int ProcessId)
{
int sessionId;
try
{
if (!ProcessIdToSessionId(ProcessId, out sessionId))
ThrowLastError();
}
catch
{
using (ProcessHandle phandle = new ProcessHandle(ProcessId, OSVersion.MinProcessQueryInfoAccess))
{
return phandle.GetToken(TokenAccess.Query).GetSessionId();
}
}
return sessionId;
}
示例6: Main
//.........这里部分代码省略.........
username,
domain,
args.ContainsKey("-p") ? args["-p"] : "",
type,
LogonProvider.Default
);
}
catch (Exception ex)
{
Console.WriteLine("Error: Could not logon as user: " + ex.Message);
Exit(Marshal.GetLastWin32Error());
}
}
else
{
int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
try
{
if (args.ContainsKey("-P"))
pid = int.Parse(args["-P"]);
}
catch
{
Console.WriteLine("Error: Invalid PID.");
}
try
{
using (var phandle = new ProcessHandle(pid, OSVersion.MinProcessQueryInfoAccess))
{
try
{
token = phandle.GetToken(TokenAccess.All);
}
catch (Exception ex)
{
Console.WriteLine("Error: Could not open process token: " + ex.Message);
Exit(Marshal.GetLastWin32Error());
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: Could not open process: " + ex.Message);
Exit(Marshal.GetLastWin32Error());
}
// Need to duplicate the token if we're going to set the session ID.
if (args.ContainsKey("-s"))
{
try
{
TokenHandle dupToken;
dupToken = token.Duplicate(
TokenAccess.All,
SecurityImpersonationLevel.SecurityImpersonation,
TokenType.Primary
);
token.Dispose();
token = dupToken;
}
catch (Exception ex)
{
Console.WriteLine("Error: Could not duplicate own token: " + ex.Message);
示例7: menuProcess_Popup
private void menuProcess_Popup(object sender, EventArgs e)
{
virtualizationProcessMenuItem.Checked = false;
if (treeProcesses.SelectedTreeNodes.Count == 0)
{
menuProcess.DisableAll();
}
else if (treeProcesses.SelectedTreeNodes.Count == 1)
{
menuProcess.EnableAll();
priorityMenuItem.Text = "&Priority";
terminateMenuItem.Text = "&Terminate Process";
suspendMenuItem.Text = "&Suspend Process";
resumeMenuItem.Text = "&Resume Process";
realTimeMenuItem.Checked = false;
highMenuItem.Checked = false;
aboveNormalMenuItem.Checked = false;
normalMenuItem.Checked = false;
belowNormalMenuItem.Checked = false;
idleMenuItem.Checked = false;
try
{
using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights))
{
switch (phandle.GetPriorityClass())
{
case ProcessPriorityClass.RealTime:
realTimeMenuItem.Checked = true;
break;
case ProcessPriorityClass.High:
highMenuItem.Checked = true;
break;
case ProcessPriorityClass.AboveNormal:
aboveNormalMenuItem.Checked = true;
break;
case ProcessPriorityClass.Normal:
normalMenuItem.Checked = true;
break;
case ProcessPriorityClass.BelowNormal:
belowNormalMenuItem.Checked = true;
break;
case ProcessPriorityClass.Idle:
idleMenuItem.Checked = true;
break;
}
}
}
catch (Exception ex)
{
priorityMenuItem.Text = "(" + ex.Message + ")";
priorityMenuItem.Enabled = false;
}
try
{
using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights))
{
try
{
using (var thandle = phandle.GetToken(TokenAccess.Query))
{
if (virtualizationProcessMenuItem.Enabled = thandle.IsVirtualizationAllowed())
virtualizationProcessMenuItem.Checked = thandle.IsVirtualizationEnabled();
}
}
catch
{ }
}
}
catch
{
virtualizationProcessMenuItem.Enabled = false;
}
try
{
if (
OSVersion.IsBelowOrEqual(WindowsVersion.XP) &&
processP.Dictionary[processSelectedPid].SessionId != Program.CurrentSessionId
)
injectDllProcessMenuItem.Enabled = false;
else
injectDllProcessMenuItem.Enabled = true;
}
catch (Exception ex)
{
Logging.Log(ex);
}
try
{
if (treeProcesses.SelectedTreeNodes[0].IsLeaf &&
(treeProcesses.Tree.Model as ProcessTreeModel).GetSortColumn() == "")
terminateProcessTreeMenuItem.Visible = false;
else
terminateProcessTreeMenuItem.Visible = true;
}
catch (Exception ex)
{
Logging.Log(ex);
}
windowHandle = WindowHandle.Zero;
WindowHandle.Enumerate(
//.........这里部分代码省略.........
示例8: menuProcess_Popup
//.........这里部分代码省略.........
case 2:
ioPriority3ThreadMenuItem.Checked = true;
break;
case 3:
ioPriority3ThreadMenuItem.Checked = true;
break;
}
}
}
catch
{
iOPriorityToolStripMenuItem.Enabled = false;
}
}
}
catch
{
priorityToolStripMenuItem.Enabled = false;
iOPriorityToolStripMenuItem.Enabled = false;
}
// Check if we think the process exists. If we don't, disable all menu items
// to avoid random exceptions occurring when the user clicks on certain things.
if (!Program.ProcessProvider.Dictionary.ContainsKey(processSelectedPid))
{
//menuProcess.DisableAll();
}
else
{
// Check the virtualization menu item.
try
{
using (ProcessHandle phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights))
using (TokenHandle thandle = phandle.GetToken(TokenAccess.Query))
{
if (virtualizationToolStripMenuItem.Enabled = thandle.IsVirtualizationAllowed)
virtualizationToolStripMenuItem.Checked = thandle.IsVirtualizationEnabled;
}
}
catch
{
virtualizationToolStripMenuItem.Enabled = false;
}
// Enable/disable DLL injection based on the process' session ID. This only applies
// on XP and above.
try
{
if (
OSVersion.IsBelowOrEqual(WindowsVersion.XP) &&
Program.ProcessProvider.Dictionary[processSelectedPid].SessionId != Program.CurrentSessionId
)
injectDLLToolStripMenuItem.Enabled = false;
else
injectDLLToolStripMenuItem.Enabled = true;
}
catch (Exception ex)
{
Logging.Log(ex);
}
// Disable Terminate Process Tree if the selected process doesn't
// have any children. Note that this may also happen if the user
// is sorting the list (!).
try
{