91网首页-91网页版-91网在线观看-91网站免费观看-91网站永久视频-91网站在线播放

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

C#自動(dòng)配置Windows Server系統(tǒng)的IIS網(wǎng)站管理器啟用ASP腳本支持

admin
2025年6月17日 9:44 本文熱度 94

完整解決方案:

using System;

using System.Diagnostics;

using System.IO;

using System.Threading;


class IISASPInstaller

{

    static void Main()

    {

        try

        {

            Console.WriteLine("正在修復(fù)系統(tǒng)組件...");

            RepairSystemComponents();

            

            Console.WriteLine("再次嘗試安裝IIS-ASP...");

            InstallIISFeature("IIS-ASP");

            

            Console.WriteLine("正在配置IIS...");

            ConfigureIIS();

            

            Console.WriteLine("ASP支持已成功安裝并配置!");

        }

        catch (Exception ex)

        {

            Console.WriteLine($"操作失敗: {ex.Message}");

            Console.WriteLine("請(qǐng)嘗試手動(dòng)解決方案:");

            Console.WriteLine("1. 以管理員身份運(yùn)行CMD");

            Console.WriteLine("2. 執(zhí)行: DISM /Online /Cleanup-Image /RestoreHealth");

            Console.WriteLine("3. 執(zhí)行: sfc /scannow");

            Console.WriteLine("4. 重啟計(jì)算機(jī)后重試");

        }

    }


    // 修復(fù)系統(tǒng)組件

    static void RepairSystemComponents()

    {

        // 1. 修復(fù)Windows更新組件

        Console.WriteLine("修復(fù)Windows更新組件...");

        ExecuteCommand("net stop wuauserv");

        ExecuteCommand("net stop cryptSvc");

        ExecuteCommand("net stop bits");

        ExecuteCommand("net stop msiserver");

        

        // 重命名軟件分發(fā)文件夾

        string softwareDist = @"C:\Windows\SoftwareDistribution";

        if (Directory.Exists(softwareDist))

        {

            Directory.Move(softwareDist, softwareDist + ".old");

        }

        

        // 重命名Catroot2文件夾

        string catroot2 = @"C:\Windows\System32\catroot2";

        if (Directory.Exists(catroot2))

        {

            Directory.Move(catroot2, catroot2 + ".old");

        }

        

        // 重啟服務(wù)

        ExecuteCommand("net start wuauserv");

        ExecuteCommand("net start cryptSvc");

        ExecuteCommand("net start bits");

        ExecuteCommand("net start msiserver");

        

        // 2. 運(yùn)行SFC掃描

        Console.WriteLine("運(yùn)行系統(tǒng)文件檢查...");

        ExecuteCommand("sfc /scannow");

        

        // 3. 運(yùn)行DISM修復(fù)

        Console.WriteLine("運(yùn)行DISM修復(fù)...");

        ExecuteCommand("DISM /Online /Cleanup-Image /RestoreHealth");

        

        Thread.Sleep(3000); // 等待3秒

    }


    // 安裝IIS功能

    static void InstallIISFeature(string featureName)

    {

        // 先嘗試使用DISM安裝

        try

        {

            InstallWithDISM(featureName);

            return;

        }

        catch

        {

            Console.WriteLine($"DISM安裝失敗,嘗試PowerShell安裝 {featureName}...");

        }


        // 如果DISM失敗,嘗試使用PowerShell

        InstallWithPowerShell(featureName);

    }


    // 使用DISM安裝

    static void InstallWithDISM(string featureName)

    {

        ProcessStartInfo startInfo = new ProcessStartInfo

        {

            FileName = "dism.exe",

            Arguments = $"/Online /Enable-Feature /FeatureName:{featureName} /All /NoRestart",

            RedirectStandardOutput = true,

            RedirectStandardError = true,

            UseShellExecute = false,

            CreateNoWindow = true

        };


        using (Process process = new Process { StartInfo = startInfo })

        {

            Console.WriteLine($"正在安裝 {featureName}...");

            process.Start();

            string output = process.StandardOutput.ReadToEnd();

            string error = process.StandardError.ReadToEnd();

            process.WaitForExit();


            if (process.ExitCode != 0)

            {

                throw new Exception($"{featureName} 安裝失敗 (代碼 {process.ExitCode}): {error}");

            }

            

            Console.WriteLine($"{featureName} 安裝成功");

        }

    }


    // 使用PowerShell安裝

    static void InstallWithPowerShell(string featureName)

    {

        ProcessStartInfo psi = new ProcessStartInfo

        {

            FileName = "powershell.exe",

            Arguments = $"-Command \"Install-WindowsFeature -Name {featureName}\"",

            Verb = "runas", // 請(qǐng)求管理員權(quán)限

            RedirectStandardOutput = true,

            RedirectStandardError = true,

            UseShellExecute = false,

            CreateNoWindow = true

        };


        using (Process process = new Process { StartInfo = psi })

        {

            process.Start();

            string output = process.StandardOutput.ReadToEnd();

            string error = process.StandardError.ReadToEnd();

            process.WaitForExit();


            if (process.ExitCode != 0)

            {

                throw new Exception($"{featureName} PowerShell安裝失敗 (代碼 {process.ExitCode}): {error}");

            }

            

            Console.WriteLine($"{featureName} 通過PowerShell安裝成功");

        }

    }


    // 執(zhí)行命令

    static void ExecuteCommand(string command)

    {

        ProcessStartInfo psi = new ProcessStartInfo

        {

            FileName = "cmd.exe",

            Arguments = $"/C {command}",

            RedirectStandardOutput = true,

            RedirectStandardError = true,

            UseShellExecute = false,

            CreateNoWindow = true

        };


        using (Process process = Process.Start(psi))

        {

            string output = process.StandardOutput.ReadToEnd();

            string error = process.StandardError.ReadToEnd();

            process.WaitForExit();

            

            if (process.ExitCode != 0)

            {

                Console.WriteLine($"命令執(zhí)行失敗: {command}");

                Console.WriteLine($"錯(cuò)誤: {error}");

            }

        }

    }


    // 配置IIS (示例)

    static void ConfigureIIS()

    {

        // 這里添加配置IIS的代碼

        Console.WriteLine("配置IIS設(shè)置...");

        // 實(shí)際配置代碼需要Microsoft.Web.Administration

        // 如果無法使用該庫,請(qǐng)使用appcmd.exe命令

        ExecuteCommand(@"%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/asp /enableParentPaths:true /commit:apphost");

    }

}

手動(dòng)解決方案步驟

如果代碼執(zhí)行后仍然失敗,請(qǐng)按以下步驟手動(dòng)操作:

1、以管理員身份打開CMD:

net stop wuauserv

net stop cryptSvc

net stop bits

net stop msiserver

ren C:\Windows\SoftwareDistribution SoftwareDistribution.old

ren C:\Windows\System32\catroot2 Catroot2.old

net start wuauserv

net start cryptSvc

net start bits

net start msiserver

2、運(yùn)行系統(tǒng)文件檢查:

sfc /scannow

3、運(yùn)行DISM修復(fù):

DISM /Online /Cleanup-Image /RestoreHealth

4、重啟計(jì)算機(jī):

shutdown /r /t 0

5、重啟后再次嘗試安裝:

DISM /Online /Enable-Feature /FeatureName:IIS-ASP /All

6、如果仍然失敗,使用PowerShell:

Install-WindowsFeature -Name Web-ASP

常見原因及解決方案

錯(cuò)誤原因解決方案
Windows更新組件損壞重命名SoftwareDistribution和Catroot2文件夾
系統(tǒng)文件損壞運(yùn)行sfc /scannowDISM /Online /Cleanup-Image /RestoreHealth
功能依賴問題先安裝依賴功能:
DISM /Online /Enable-Feature /FeatureName:IIS-WebServer
DISM /Online /Enable-Feature /FeatureName:IIS-ISAPIExtensions
磁盤空間不足清理磁盤空間(至少需要500MB)
Windows映像損壞使用安裝介質(zhì)修復(fù):
DISM /Online /Cleanup-Image /RestoreHealth /Source:F:\Sources\install.wim

備用安裝方法(100%有效)

如果所有方法都失敗,可以使用Windows安裝介質(zhì):

  1. 下載對(duì)應(yīng)系統(tǒng)的ISO文件

  2. 掛載ISO(右鍵點(diǎn)擊 > 掛載)

  3. 假設(shè)掛載到F盤,執(zhí)行:

DISM /Online /Enable-Feature /FeatureName:IIS-ASP /All /LimitAccess /Source:F:\sources\sxs

驗(yàn)證安裝成功

1、檢查功能是否安裝:

DISM /Online /Get-FeatureInfo /FeatureName:IIS-ASP

2、檢查IIS中是否存在ASP模塊:

%windir%\system32\inetsrv\appcmd.exe list modules

輸出中應(yīng)包含AspModule

3、創(chuàng)建測(cè)試ASP文件:

<%@ Language=VBScript %>

<% Response.Write("ASP Works! Time: " & Now()) %>

訪問http://localhost/test.asp查看結(jié)果。

此方案結(jié)合了自動(dòng)修復(fù)和手動(dòng)步驟,如果仍然無法解決,可能是系統(tǒng)核心損壞,建議考慮系統(tǒng)還原或重裝。


相關(guān)教程:

【C#】自動(dòng)檢測(cè)Windows Server服務(wù)器是否已經(jīng)安裝并配置IIS管理器的ASP和ASP.NET(.aspx)支持代碼[208]
  http://31557.oa22.cn


該文章在 2025/6/17 12:10:00 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲(chǔ)管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 日本va午 | 欧美亚洲图片日韩 | 国产成年码a| 日本亚洲精 | 91九色国 | 尤物视频| 国产欧美一区二区 | 人成视频在线视频 | 国产日韩欧美另类 | 福利导航成人 | www.色黄| 人人天天夜夜 | 国产精品福利社 | 成人国产精品日本在 | 午夜欧美 | 国内精品一区 | 欧美自拍偷拍一区 | 91.cn国产大片 | 国产免费观看视频 | 成人性生交大免费看 | 国产亚洲欧洲高清 | 欧美日韩在线视频 | 欧美日韩午夜专区 | 欧美三级a做| 中文字幕2025 | 国产性爱在线播放 | 国产又黄又| 日韩一级一欧美一 | 国产馆精品丝 | 91伊人国产| 国产日韩在 | 国产高清看片日韩 | 国产免费网站 | 最新热门大片抢先看 | 成人九九九 | 国产主播日韩欧美 | 日本乱子伦一 | 无码潮喷a片无码高潮快三 无码潮喷中文 | 欧美一区二区日韩 | 91中文字幕 | 日产国产欧洲系列 |