我不想通过它的路径杀死一个进程。但是当我使用这段代码时,我得到了一个 win32Exception。
仅完成了 ReadProcessMemory 或 WriteProcessMemory 请求的一部分
我将目标构建更改为 x64,但仍然出现相同的错误。
Process[] Processes = Process.GetProcessesByName("iw4");
if (Processes.Length >= 1)
{
for (int i = 1; i < Processes.Length; i++)
{
Process Process = Processes[i];
string processPath = Process.MainModule.FileName;
if (processPath == s + "\\iw4.exe")
{
if (!File.Exists(s + "\\localization.txt"))
{
Log.Data("killed process!");
Process.Kill();
}
}
}
}
堆栈跟踪:
at System.Diagnostics.NtProcexssManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
at System.Diagnostics.Process.get_MainModule()
at LocalizationFix.Fix.checkLocalizationFile()
at LocalizationFix.Init.Main(String[] args)
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()