【问题标题】:bat file to install .net 3.5 framework for win server 2012bat 文件为 win server 2012 安装 .net 3.5 框架
【发布时间】:2023-03-06 00:13:02
【问题描述】:

我想制作一个 bat 文件以在 Windows Server 2012 上安装 .net Framework 3.5。 我试过这样但没有成功:

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

好像进入powershell控制台后最后2个命令都没有执行。

有人知道为什么会卡住吗?

或者是否有人有其他 bat 文件如何在 windows server 2012 中自动安装 .net 3.5?

经过更多尝试,当手动运行时,我使 bat 使用以下命令工作。

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

但是当我尝试从 dotnetInstaller 运行它时,相同的 bat 不再工作了

 <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 的名称,functi on、脚本文件或可运行的程序。检查名称的拼写,或者如果 p ath 已包含在内,请验证路径是否正确,然后重试。 在行:1 字符:19 + 添加-WindowsFeature

【问题讨论】:

    标签: powershell batch-file .net-3.5 windows-server-2012 dotnetinstaller


    【解决方案1】:

    你也可以使用chocolatey:

    choco install dotnet3.5
    

    【讨论】:

      【解决方案2】:

      转到命令提示符并输入:

      dism /online /enable-feature /featurename:NetFX3 /all /Source:d:\sources\sxs /LimitAccess

      注意:来源应为 Windows 2012 安装光盘。就我而言,它位于 D:

      【讨论】:

        【解决方案3】:

        我让它和这个蝙蝠一起工作:

        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>  
        

        似乎它以前不起作用,因为引导程序以 PS 不喜欢的 32 位启动 bat 进程。所以我把 disable_wow64_fs_redirection="True" 现在它作为 64 位进程运行 bat 并且它可以工作:)

        谢谢大家的回复。 我发布了答案可能会对其他人有所帮助:)

        【讨论】:

          【解决方案4】:

          两种选择:

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

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

          然后执行:

          powershell -File c:\script.ps1
          

          2) 使用Command参数:

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

          在任何情况下,尽量避免使用 -ImportSystemModules 开关(在 v3 中已弃用),这只是矫枉过正。当您只需要 ServerManager 模块时,它将加载所有系统模块。如果您使用的是 v3,则 Import-Module 命令也是多余的。请参阅模块autp-loading feature

          【讨论】:

            【解决方案5】:

            要使用 powershell 运行命令,请使用 -Command 参数,如下所示:

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

            【讨论】:

              【解决方案6】:

              它的工作方式如下:

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

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2014-10-10
                • 2012-07-26
                • 1970-01-01
                • 1970-01-01
                • 2014-07-01
                • 2011-06-21
                • 2011-03-23
                • 1970-01-01
                相关资源
                最近更新 更多