Jordi Kroon
Jordi Kroon

Reputation: 2597

Only part of a ReadProcessMemory or WriteProcessMemory request was completed

I wan't to kill a process by it's path. But when I use this code I get a win32Exception.

Only part of a ReadProcessMemory or WriteProcessMemory request was completed

My changed the target build to x64 but I still get the same error.

 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();
            }
        }
    }
 }

Stack trace:

   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()

Upvotes: 2

Views: 5897

Answers (1)

Richard Schneider
Richard Schneider

Reputation: 35477

The problem is not in the posted code. Its most likely in LocalizationFix.Fix.checkLocalizationFile().

The posted has an unrelated problem in that you are skipping the first entry in the process list. C# uses zero-relative indexing.

Maybe you want something like:

foreach (var Process in Process.GetProcessesByName("iw4");
{
   ...
}

Also, by convention local variable names are lower Pascal cased. So use:

foreach (var process in Process.GetProcessesByName("iw4");
{
   ...
}

Upvotes: 1

Related Questions