希望这是要求新来这个网站:)的Visual Studio 2017年C#推出PowerShell脚本
我对新用户创建Visual Studio创建一个GUI正确的地方。部分代码然后调用我用于创建用户的Powershell脚本。
因此,GUI的所有作品,我可以将用户添加到它创建的CSV文件,然后启动Powershell脚本。
我得到的问题是Powershell脚本的一部分加载交换2007管理单元。出于某种原因,通过GUI运行脚本时,我创建了它,总是出现错误,说它无法找到插件。
所以基本上启动Powershell的代码如下。现在,我不是一个编码器都这样我就可以去了解它的错误的方式,它可能是一个有点乱嘿嘿:)
Process p = new Process();
p.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
// Redirect the output stream of the child process.
p.StartInfo.CreateNoWindow = false; (false for testing)
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = false; //(false for testing)
p.StartInfo.RedirectStandardOutput = false; //(false for testing)
p.StartInfo.RedirectStandardError = false; //(false for testing)
p.StartInfo.LoadUserProfile = true;
p.StartInfo.FileName = "This points to a file on a network share" @"\\server\folder\file";
p.Start();
p.BeginOutputReadLine();
点击一个按钮后,上述情况发生,将被输出到的一旦我有它的所有工作,在GUI中的文本框。但是现在我已经禁用了那些东西,所以我可以看到Powershell中的错误。
所以在PowerShell中的错误信息如下
“Microsoft.exchange.management.powershell.admin”如果我手动运行该脚本没有在此计算机上安装
但同样没有GUI它工作正常。它像GUI一样在一个封闭的环境中启动它,它无法访问它运行的计算机。我很可能错过了一些简单的东西,因为我真的不知道如何创建c#应用程序。
PowerShell脚本位于网络共享,所以我尝试将其移动到本地计算机上的测试,但得到了同样的问题,因此不看起来像我制作的小GUI程序在它自己的实例中运行,并且无法访问允许它加载交换管理单元的本地用户注册表设置。 – MichaelS