简体   繁体   English

在C#中安装Active Directory域服务

[英]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.

相关问题 如何在c#中查询Active Directory站点和服务? - How can I query Active Directory Sites and Services in c#? C#Active Directory调用“ChangePassword”无法联系域 - C# Active Directory Invoke “ChangePassword” cannot contact domain 检查 Active Directory 域控制器是否已启动并正在运行的 C# 方法 - C# Method to check if an Active Directory Domain Controller is up and running C#Active Directory:获取用户的域名? - C# Active Directory: Get domain name of user? 使用C#和Powershell从不属于域的计算机访问Active Directory - Accessing Active Directory From a Computer Not Part of the Domain With C# and Powershell C#通过Windows凭据获取域Active Directory信息 - C# Get Domain Active directory Information by Windows Credentials C#Active Directory:将用户添加到另一个域中的组 - C# Active Directory: Add user to group in another domain c#Active Directory身份验证用户(如果计算机不在域中) - c# Active Directory Authentication User if Computer not in domain C# 活动目录 - 如果域 controller 已关闭怎么办? - C# active directory-what if a domain controller is down? 如何使用目录服务(C#)在Active Directory中设置gecos属性 - How to set gecos attribute in Active Directory using directory services(C#)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM