[英]Installing Active Directory Domain Services in C#
I need to install AD in a Windows Server 2012 machine. 我需要在Windows Server 2012计算机中安装AD。 Are there any .Net classes that allow to do it, without using Powershell? 是否有任何.Net类可以在不使用Powershell的情况下做到这一点?
If I use powershell in C#: 如果我在C#中使用powershell:
command = "powershell.exe -Command \"& {Install-windowsfeature -name AD-Domain-Services –IncludeManagementTools}\""
procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
result = proc.StandardOutput.ReadToEnd();
I have the error: 我有错误:
Install-windowsfeature : The term 'Install-windowsfeature' is not recognized \\nas the name of a cmdlet, function, script file, or operable program. Install-windowsfeature:无法识别术语“ Install-windowsfeature” \\ nas cmdlet,函数,脚本文件或可运行程序的名称。
That is very strange because Install-windowsfeature is recognized inside Powershell. 这很奇怪,因为Powershell内部可以识别Install-windowsfeature。
Thanks for any answer. 感谢您的任何答复。
It appears the Install-Windowsfeature cmdlet is only available in a 64-bit ps session. 看来Install-Windowsfeature cmdlet仅在64位ps会话中可用。 If you're launching from a 32-bit app or cmd window, launch powershell using the full path: 如果要从32位应用程序或cmd窗口启动,请使用完整路径启动powershell:
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
This should return 8 if you're in a 64-bit session: 如果您处于64位会话中,则应返回8:
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -command {[intptr]::size}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.