Code: Select all
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
listBox1.Items.Add(theprocess.ProcessName);
icons.Add(Icon.ExtractAssociatedIcon(theprocess.MainModule.FileName));
}
Aber mir wird der Ausnahmezugriff verweigert (ich habe Administratorrechte und habe das Visual Studio als Administrator ausgeführt) in der Zeile:
Code: Select all
icons.Add(Icon.ExtractAssociatedIcon(theprocess.MainModule.FileName));
Code: Select all
System.ComponentModel.Win32Exception was unhandled
HResult=-2147467259
Message=Access is denied
Source=System
ErrorCode=-2147467259
NativeErrorCode=5
StackTrace:
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)
at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
at System.Diagnostics.Process.get_MainModule()
at HardwareMonitoring.Form1..ctor() in d:\C-Sharp\HardwareMonitoring\HardwareMonitoring\Hardwaremonitoring\Form1.cs:line 124
at HardwareMonitoring.Program.Main() in d:\C-Sharp\HardwareMonitoring\HardwareMonitoring\Hardwaremonitoring\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Mobile version