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(好像可以指定进程的上下文环境)的更多相关文章

  1. Kubernetes容器上下文环境

    目录贴:Kubernetes学习系列 下面我们将主要介绍运行在Kubernetes集群中的容器所能够感知到的上下文环境,以及容器是如何获知这些信息的. 首先,Kubernetes提供了一个能够让容器感 ...

  2. tensorflow中有向图(计算图、Graph)、上下文环境(Session)和执行流程

    计算图(Graph) Tensorflow是基于图(Graph)的计算框架,图的节点由事先定义的运算(操作.Operation)构成,图的各个节点之间由张量(tensor)来链接,Tensorflow ...

  3. (转)iOS Wow体验 - 第四章 - 为应用的上下文环境而设计

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第四章译文精选,其余章节将陆续放出.上一篇:Wow ...

  4. Android应用程序窗口(Activity)的运行上下文环境(Context)的创建过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8201936 在前文中,我们简要介绍了Andro ...

  5. SEAndroid安全机制中的进程安全上下文关联分析

    前面一篇文章分析了文件安全上下文关联过程.可是在SEAndroid中,除了要给文件关联安全上下文外,还须要给进程关联安全上下文.由于仅仅有当进程和文件都关联安全上下文之后,SEAndroid安全策略才 ...

  6. Linux-进程描述(2)之进程标识符进程位置与环境变量

    在上一篇文章中详细介绍了task_struct结构体内的常见成员,然后我们就来看一下具体内容.每个进程都把它的信息放在 task_struct 这个数据结构中,task_struct 包含了这些内容: ...

  7. JavaScript 上下文环境和作用域,以及 call、apply 和 bind【转载+翻译+整理】

    --看到这篇文章,翻译国外的,虽说写得有点矫情,但总体来看,还是相当不错的- 本文内容 我在哪儿?你又是谁 ? this? 用 apply 和 call 掌控上下文环境 bind 之美 本文将说明上下 ...

  8. shell脚本杀掉指定进程下所有子进程(包括子进程的子进程)

    搜索了网上好像并没有杀掉指定进程下所有子进程(包括子进程的子进程)的脚本,自己琢磨写了一版,虽说比较简单,但希望分享大家,帮助需要的人 #!/bin/sh # 递归找到进程最底层子进程并杀除. mai ...

  9. 分享自己做的一个指定进程以及线程长时间cpu监控的工具

    前言: 前面给大家分享过一个工作中用到的编译拷贝脚本,其实工作中还有一些其他工具的使用,今天再来分享一个自己纯手工的CPU监控的脚本.大家可以结合上篇文章与本篇文章一起学习shell. 主要实现功能: ...

随机推荐

  1. List<T>分组一

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  2. Compiling JSPs Using the Command-Line Compiler---官方

    Web Server provides the following ways of compiling JSP 2.1-compliant source files into servlets: JS ...

  3. iOS--RunLoop原理介绍

    什么是RunLoop RunLoop从字面上看是运行循环的意思,这一点也不错,它确实就是一个循环的概念,或者准确的说是线程中的循环. 本文一开始就提到有些程序是一个圈,这个圈本质上就是这里的所谓的Ru ...

  4. ios的手势操作之UIGestureRecognizer浅析

    转载地址:http://blog.csdn.net/likendsl/article/details/7554150 每一个手势的实现例子,可参考下面网址:http://www.cnblogs.com ...

  5. 表达式:使用API创建表达式树(3)

    一.DebugInfoExpression:发出或清除调试信息的序列点. 这允许调试器在调试时突出显示正确的源代码. static void Main(string[] args) { var asm ...

  6. WPF TextElement内容模型简介(转)

    本内容模型概述描述了 TextElement 支持的内容. Paragraph 类是 TextElement 的类型. 内容模型描述哪些对象/元素可以包含在其他对象/元素中. 本概述汇总了派生自 Te ...

  7. 部分A+B_1

    正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6. 现给定A.DA.B.DB,请编 ...

  8. SQL SERVER 存储过程基础

    一.注释 -- 单行注释,从这到本行结束为注释,类似C++,c#中// /* … */ 多行注释,类似C++,C#中/* … */ 二.变量 (int, smallint, tinyint, deci ...

  9. Lua-C交互函数

    lua_gettable(lua_State * , tableIndex) //获取表的在key位置的值 过程:tableIndex为表在栈的位置,例:-2为第二个位置 , 此时会弹(出)栈作为参数 ...

  10. OPENGL 地形

    用OPNEGL弄了好久,终于有个地形的样子了! 看起来还是很糟糕....