CreateProcessWithLogonW(好像可以指定进程的上下文环境)
Creates a new process and its primary thread. Then the new process runs the specified executable file in the security context of the specified credentials (user, domain, and password). It can optionally load the user profile for a specified user.
The CreateProcessWithLogonW and CreateProcessWithTokenW functions are similar to the CreateProcessAsUser function, except that the caller does not need to call the LogonUser function to authenticate the user and get a token.
--------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace MainTest
{
class ProcessUserLogonHelper
{
/// <summary>
/// 在Main函数中调用该方法的的示例代码
/// </summary>
private void InvokeExample()
{
ProcessUserLogonHelper phelper = new ProcessUserLogonHelper();
Process pro = phelper.CreateProcessWithUserToken(@"C:\Program Files\Internet Explorer\iexplore.exe", "bestreme.com", "chdwu", "************");
pro.Start();
}
/// <summary>
/// 使用指定帐户绑定进程
/// </summary>
/// <param name="appPath">进程的宿主程序</param>
/// <param name="domain">指定帐户的域名</param>
/// <param name="userName">指定帐户的用户名</param>
/// <param name="password">指定帐户的密码</param>
/// <returns>绑定了特定帐户的进程</returns>
public Process CreateProcessWithUserToken(string appPath,string domain, string userName, string password)
{
Process pro = new Process();
ProcessStartInfo processInfo = new ProcessStartInfo(appPath);
processInfo.UseShellExecute = false;
processInfo.UserName = userName;
processInfo.Domain = domain;
System.Security.SecureString psw = new System.Security.SecureString();
foreach (char c in password.ToCharArray())
{
psw.AppendChar(c);
}
processInfo.Password = psw;
processInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(appPath);
pro.StartInfo = processInfo;
return pro;
}
/// <summary>
/// 使用指定帐户绑定进程
/// </summary>
/// <param name="appPath">进程的宿主程序</param>
/// <param name="userName">指定本地帐户的用户名</param>
/// <param name="password">指定帐户的密码</param>
/// <returns>绑定了特定帐户的进程</returns>
public Process CreateProcessWithUserToken(string appPath, string userName, string password)
{
return CreateProcessWithUserToken(appPath, "", userName, password);
}
}
}
---------------
MainTest.ProcessUserLogonHelper cmd = new MainTest.ProcessUserLogonHelper();
Process p = cmd.CreateProcessWithUserToken("C:\\Program Files\\Internet Explorer\\iexplore.exe",
"administrator", "clq1111");
p.Start();
if (p==null)
{
MessageBox.Show("error");
}
http://www.cnblogs.com/-clq/archive/2012/01/19/2327333.html
CreateProcessWithLogonW(好像可以指定进程的上下文环境)的更多相关文章
- Kubernetes容器上下文环境
目录贴:Kubernetes学习系列 下面我们将主要介绍运行在Kubernetes集群中的容器所能够感知到的上下文环境,以及容器是如何获知这些信息的. 首先,Kubernetes提供了一个能够让容器感 ...
- tensorflow中有向图(计算图、Graph)、上下文环境(Session)和执行流程
计算图(Graph) Tensorflow是基于图(Graph)的计算框架,图的节点由事先定义的运算(操作.Operation)构成,图的各个节点之间由张量(tensor)来链接,Tensorflow ...
- (转)iOS Wow体验 - 第四章 - 为应用的上下文环境而设计
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第四章译文精选,其余章节将陆续放出.上一篇:Wow ...
- Android应用程序窗口(Activity)的运行上下文环境(Context)的创建过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8201936 在前文中,我们简要介绍了Andro ...
- SEAndroid安全机制中的进程安全上下文关联分析
前面一篇文章分析了文件安全上下文关联过程.可是在SEAndroid中,除了要给文件关联安全上下文外,还须要给进程关联安全上下文.由于仅仅有当进程和文件都关联安全上下文之后,SEAndroid安全策略才 ...
- Linux-进程描述(2)之进程标识符进程位置与环境变量
在上一篇文章中详细介绍了task_struct结构体内的常见成员,然后我们就来看一下具体内容.每个进程都把它的信息放在 task_struct 这个数据结构中,task_struct 包含了这些内容: ...
- JavaScript 上下文环境和作用域,以及 call、apply 和 bind【转载+翻译+整理】
--看到这篇文章,翻译国外的,虽说写得有点矫情,但总体来看,还是相当不错的- 本文内容 我在哪儿?你又是谁 ? this? 用 apply 和 call 掌控上下文环境 bind 之美 本文将说明上下 ...
- shell脚本杀掉指定进程下所有子进程(包括子进程的子进程)
搜索了网上好像并没有杀掉指定进程下所有子进程(包括子进程的子进程)的脚本,自己琢磨写了一版,虽说比较简单,但希望分享大家,帮助需要的人 #!/bin/sh # 递归找到进程最底层子进程并杀除. mai ...
- 分享自己做的一个指定进程以及线程长时间cpu监控的工具
前言: 前面给大家分享过一个工作中用到的编译拷贝脚本,其实工作中还有一些其他工具的使用,今天再来分享一个自己纯手工的CPU监控的脚本.大家可以结合上篇文章与本篇文章一起学习shell. 主要实现功能: ...
随机推荐
- php判断http头还是https头
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HT ...
- [转] What is the point of redux when using react?
As I am sure you have heard a bunch of times, by now, React is the V in MVC. I think you can think o ...
- java文件处理工具类
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedRead ...
- 关于echarts的使用----模块化单文件引入(推荐) 与标签式单文件引入
官网:http://echarts.baidu.com/echarts2/doc/doc.html#引入ECharts3 关于模块化单文件引入(推荐) 与标签式单文件引入
- tj
--统计set @collSql='select sum(case Ca_IssueType when 0 then 1 else 0 end) as IssueCount,sum(case when ...
- 很好用的Tab标签切换功能,延迟Tab切换。
一个网页,Tab标签的切换是常见的功能,但我发现很少有前端工程师在做该功能的时候,会为用户多想想,如果你觉得鼠标hover到标签上,然后切换到相应的内容,就那么简单的话,你将是一个不合格的前端工程师啊 ...
- 数据的动态合并和导出至EXCEL
最近一段时间都在处理数据的动态合并和导出EXCEL的问题,写个demo记录下,希望和我碰到同样问题的博友可以顺利解决:后面会提供demo下载链接. (VS2012,ASP.NET) 一.主要解决以下问 ...
- C#中的Dictionary简介
简介在C#中,Dictionary提供快速的基于兼职的元素查找.当你有很多元素的时候可以使用它.它包含在System.Collections.Generic名空间中. 在使用前,你必须声明它的键类型和 ...
- iOS里面如何同时使用开启ARC的库 和 没有开启 ARC的库,ARC 与非 ARC同时存在的问题
旧工程配置arc方案: 1,直接在targets->build phases中修改compiler Flags,是否支持arc.添加:-fobjc-arc,就可以让旧项目支持arc. 新工程配置 ...
- Strut2 采用token机制防御CSRF同时也可以防止表单重复提交
一 未配置Struts2 token的情况下测试 1.从表单提交数据,可以从下图看出,快速点击保存按钮,请求提交了两次 2.检查post提交的数据中未含有token参数 3.查看数据列表,有重复数据 ...