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. 主要实现功能: ...
随机推荐
- 为Android GridView 设置行背景
经常有这样的需求,你的功能图标要像一个个物品,摆放在书架上,像这样: 我的思路比较简单,重载GridView,在他绘制子视图前,先把背景绘制完成 1 2 3 4 5 6 7 8 9 10 11 12 ...
- java EE 学习
http://blog.csdn.net/liushuijinger/article/category/1342030/1
- Tomcat7.0.40 基于DataSourceRealm的和JDBCRealm的资源用户访问控制
软件版本: Tomcat 7.0.40 Mysql: 5.1 Host: CentOS 6.3 64bit 使用JDBCRealm (Tomcat 会使用所给的JDBC Connecter 自己去连M ...
- java Permissions and Security Policy--官方文档
3 Permissions and Security Policy 3.1 The Permission Classes The permission classes represent access ...
- 一次优化web项目的经历记录(二)
一次优化web项目的经历记录 这段时间以来的总结与反思 前言:最近很长一段时间没有更新博客了,忙于一堆子项目的开发,严重拖慢了学习与思考的进程. 开水倒满了需要提早放下杯子,晚了就会烫手,这段时间以来 ...
- CentOS修改主机名hostname
方法一:即时生效,重启后失效 hostname 新主机名 方法二:永久生效 1.修改/etc/hosts vim /etc/hosts 127.0.0.1 localhost 新主机名 2.修改/et ...
- Bash远程文件传输命令scp
备份远程文件(远程——>本地) scp -r 远程用户名@ip:文件绝对路径 本地绝对路径 还原远程文件(本地——>远程) scp -r 本地路径 远程用户名@ip:远程绝对路径 如果SS ...
- Socket.IO 概述
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3826251.html ...
- 10.25 noip模拟试题
今天题目略水2333 依旧不粘题目了23333 T1 /*数学题 给定n个斜率 求有多少个三元组 保证两两斜率不同 ans=C(n,3)-ΣC(len[i],2)*(n-len[i])-ΣC(len[ ...
- 【POJ1417】【带标记并查集+DP】True Liars
Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was ...