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:

相關問題