0

下面是场景。

  1. 使用用户名“JOHN”登录到 Windows
  2. 在 c# 中运行 Windows 应用程序编写器。此工具名称为 BootStrapper.exe。但是我使用名为“ALEX”的不同用户使用运行方式功能执行了这个工具。
  3. 引导程序将显示一些名为“启动应用程序”的按钮。单击启动时,使用 c# 的 Process 类执行 Application.exe。请注意,我没有传递任何用户名和密码。所以 Application.exe 也在“ALEX”用户下运行。

即使它是由“ALEX”启动的,如何从 Bootstrapper.exe 在“JOHN”下运行 Application.exe。请注意,Application.exe 将不知道“JOHN”的密码来模拟 JOHN 用户。

4

2 回答 2

1

在由 JOHN 启动的进程中托管 WCF 服务(可能通过将其放在启动文件夹中)。

使用指示启动哪个进程的命令从 ALEX 进程调用 WCF 服务。
从 WCF 服务启动进程,它将作为 JOHN 运行。

于 2012-10-01T11:38:00.337 回答
0

我为我糟糕的英语道歉。也许我理解错了...编译它,并将结果复制到“C:\ test”目录。现在运行它。

using System;
using System.Text;
using System.Diagnostics;
using System.Security;
using System.Reflection;
using System.IO;

namespace ConsoleApplication6 {
    class Program {

        unsafe static void Main(string[] args) {

            Process process = new Process();
            String dir = Path.GetDirectoryName(typeof(Program).Assembly.Location);

            String txtFile = Path.Combine(dir, "example.txt");
            if (!File.Exists(txtFile)) {
                StreamWriter sw = File.CreateText(txtFile);
                sw.Close();
                sw.Dispose();
            }

            ProcessStartInfo info = new ProcessStartInfo();

            info.Domain = "myDomainName";
            info.UserName = "userName";
            String pass = "userPassword";

            fixed (char* password = pass) {
                info.Password = new SecureString(password, pass.Length);
            }

            // Will be run notepad.exe
            info.FileName = Environment.ExpandEnvironmentVariables(@"%winDir%\NOTEPAD.EXE");
            // in notepad.exe will be open example.txt file.
            info.Arguments = txtFile;
            info.LoadUserProfile = false;
            info.UseShellExecute = false;
            info.WorkingDirectory = dir;

            process.StartInfo = info;
            process.Start();
        }
    }
}

问候

于 2012-10-01T12:10:00.480 回答