4

3.5框架,我想打一个bat文件,在Windows Server上安装.NET Framework 3.5 2012年 我想这样的,但没有成功:bat文件来安装.NET为Win Server 2012的

cd /D %userprofile% 
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
Import-Module ServerManager 
powershell -ImportSystemModules Add-WindowsFeature NET-Framework-Features 

似乎进入PowerShell控制台后,最后2个命令不执行。

有没有人有想法为什么会卡住?

还有没有人有其他bat文件如何自动安装.net 3.5在Windows Server 2012中?

经过更多的尝试,我做了蝙蝠工作时手动运行下面的命令。

call C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ImportSystemModules Add-WindowsFeature NET-Framework-Features 

但是当我尝试从dotnetInstaller蝙蝠一样运行它不工作了

<component command="CMD.EXE /K &quot;#APPPATH\Install.net3.5.bat&quot;" command_silent="" command_basic="" uninstall_command="" uninstall_command_silent="" uninstall_command_basic="" returncodes_success="" returncodes_reboot="" disable_wow64_fs_redirection="False" id=".Net 3.5 SP1 Win8Server" display_name=".Net 3.5 SP1" uninstall_display_name="" os_filter="" os_filter_min="winServer2008R2" os_filter_max="" os_filter_lcid="" type="cmd" installcompletemessage="" uninstallcompletemessage="" mustreboot="False" reboot_required="" must_reboot_required="False" failed_exec_command_continue="" allow_continue_on_error="True" default_continue_on_error="False" required_install="True" required_uninstall="True" selected_install="True" selected_uninstall="True" note="" processor_architecture_filter="" status_installed="" status_notinstalled="" supports_install="True" supports_uninstall="False" show_progress_dialog="True" show_cab_dialog="True"> 
<installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="Install" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" /> 
     <installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="SP" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" /> 
    </component> 

我得到这个错误任何想法,为什么?

术语'Add-WindowsFeature'不被识别为cmdlet的名称,脚本文件或可操作程序。检查名称的拼写,或者如果包含,请验证路径是否正确,然后重试。 在行:1字符:19 +添加-WindowsFeature < < < < -name净框架的功能 + CategoryInfo:ObjectNotFound:(添加-WindowsFeature:字符串)[], CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException

回答

1

我做了这个蝙蝠工作:

call C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ImportSystemModules Add-WindowsFeature NET-Framework-Features 

而且在dotnetInstaller引导程序:

<component command="Install.net3.5.bat" command_silent="" command_basic="" uninstall_command="" uninstall_command_silent="" uninstall_command_basic="" returncodes_success="" returncodes_reboot="" disable_wow64_fs_redirection="True" id=".Net 3.5 SP1 Win8Server" display_name=".Net 3.5 SP1" uninstall_display_name="" os_filter="" os_filter_min="winServer2008R2" os_filter_max="" os_filter_lcid="" type="cmd" installcompletemessage="" uninstallcompletemessage="" mustreboot="False" reboot_required="" must_reboot_required="False" failed_exec_command_continue="" allow_continue_on_error="True" default_continue_on_error="False" required_install="True" required_uninstall="True" selected_install="True" selected_uninstall="True" note="" processor_architecture_filter="" status_installed="" status_notinstalled="" supports_install="True" supports_uninstall="False" show_progress_dialog="True" show_cab_dialog="True"> 
<installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="Install" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" /> 
     <installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="SP" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" /> 
    </component> 

似乎是因为引导程序被启动蝙蝠过程为32位并没有工作之前哪些PS不喜欢。所以我把disable_wow64_fs_redirection =“True”现在它运行蝙蝠作为64位过程,它的工作原理:)

谢谢大家的答复。 我张贴的答案也许会帮助别人:)

0

这种工作方式如下:

cd /D %userprofile% 
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "Import-Module ServerManager; ImportSystemModules Add-WindowsFeature NET-Framework-Features" 
pause 
0

运行使用PowerShell命令使用-Co​​mmand参数,像这样:

powershell.exe -command "&{Import-Module ServerManager; ImportSystemModules Add-WindowsFeature NET-Framework-Features}" 
4

两个选项:

1)使用脚本文件和文件参数。

############# 
## script.ps1 
Import-Module ServerManager 
Add-WindowsFeature NET-Framework-Features 

然后执行:

powershell -File c:\script.ps1 

2)使用命令参数:

powershell -Command "Import-Module ServerManager; Add-WindowsFeature NET-Framework-Features" 

在任何情况下,尽量避免-ImportSystemModules开关(在v3中不建议使用),它只是过度杀伤。当你需要的只是ServerManager模块时,它会加载所有的系统模块。如果你在v3中工作,导入模块命令也是多余的。请参阅模块autp-loading feature

0

进入命令提示符,输入:

DISM /在线/使能功能/ featurename:NetFX3 /所有/来源:d:\ sources \ sxs/LimitAccess

注意:Source应该是Windows 2012安装光盘。在我的情况下,这是位于D:

相关问题