title: Virtual Protect & PAGE_GUARD
body: <p>I relatively new to the win32 API, and I'm attempting to set the 'PAGE_GUARD' attribute on a processes' PE Header. However, this seems to fail every time that I try. I've looked into the documentation for 'VirtualProtectEx', and from what I see I have everything set up correctly. I have the first parameter(the HANDLE) set to the process I started's HANDLE, I have the lpAddress set the the process that I started's BaseAddress, I have the size set to 4096 which I am fairly sure is the header size for an x86 PE, I have the new protection set to '0x100' or '256u', which is PAGE_GUARD, and the old protection is 0. </p>
  
  <p>Why doesn't this work?</p>
  
  <pre><code>namespace VirtualProtectTest
  {
  class Program
  {
      [DllImport("kernel32.dll")]
      public static extern bool VirtualProtectEx( IntPtr hProcess, uint dwAddress, int nSize, uint flNewProtect, out uint lpflOldProtect);
  
  
      static void Main(string[] args)
      {
          Process p = Process.Start("app.exe");
          Thread.Sleep(1000);
          if (VirtualProtectEx(p.Handle, (uint)p.MainModule.BaseAddress, 4096, 0x100, out uint a))
          {
              Console.WriteLine("Success!");
          }
  
          else 
          {
              Console.WriteLine("Fail!");
              p.Kill();
          }
  
          Console.ReadKey();
      }
  }
  }
  </code></pre>