C#中System.Diagnostics.Process.GetProcessesByName(String processName)時報錯的處理方法

來源:互聯網
上載者:User
有時候我們在用EXCEL處理資料時,在最後殺EXCEL進程時,使用System.Diagnostics.Process.GetProcessesByName(String processName)方法會報錯,

存取被拒。

描述: 在執行目前 Web 要求的過程中發生未處理的例外情形。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。

例外詳細資訊: System.ComponentModel.Win32Exception: 存取被拒。

原始程式錯誤:

在執行目前 Web 要求期間,產生無法處理的例外狀況。如需有關例外狀況來源與位置的資訊,可以使用下列的例外狀況堆疊追蹤取得。

堆疊追蹤:

[Win32Exception (0x80004005): 存取被拒。]            System.Diagnostics.PerformanceMonitor.GetData(String item) +485            System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item) +158            System.Diagnostics.PerformanceCounterLib.get_CategoryTable() +80            System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String[] categories, Int32[] categoryIndexes) +56            System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib library) +157            [InvalidOperationException: 無法從遠端電腦取得處理序資訊。]            System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib library) +258            System.Diagnostics.NtProcessManager.GetProcessInfos(String machineName, Boolean isRemoteMachine) +153            System.Diagnostics.ProcessManager.GetProcessInfos(String machineName) +37            System.Diagnostics.Process.GetProcessesByName(String processName, String machineName) +69            System.Diagnostics.Process.GetProcessesByName(String processName) +11            SchedulingWL.DPS.DataMaintainAV.showExcel1() in d:\web\wl_scheduling\dps\datamaintainav.aspx.cs:676            SchedulingWL.DPS.DataMaintainAV.btnExcel_Click(Object sender, ImageClickEventArgs e) in d:\web\wl_scheduling\dps\datamaintainav.aspx.cs:535            System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +109            System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +69            System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18            System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33            System.Web.UI.Page.ProcessRequestMain() +1292            

處理方法:
1.在WEBCONFIG中使用
<identity impersonate="true" userName="User" password="ABCDE"/>
放在<system.web>標籤中
2.或者將ASP.NET設為管理員權限(IIS5及以下),或者NETWORKSERVICE(IIS6)

版本資訊: Microsoft .NET Framework 版本:1.1.4322.2300; ASP.NET 版本:1.1.4322.2300

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.