title: C# GetDiskFreeSpaceEx shows different result in debug and run executable
body: <p>I want to get the available disk free space when the disk quota is set. I have limited my D disk to 500Gb with disk quota, <a href="https://i.stack.imgur.com/DnyOC.png" rel="nofollow noreferrer">D disk is limited to 500Gb</a>. Without the setup of disk quota, the free space of D is 803Gb <a href="https://i.stack.imgur.com/8nzp0.png" rel="nofollow noreferrer">D disk without disk quota</a></p>
  <p>And from this question <a href="https://stackoverflow.com/questions/1393711/get-free-disk-space">Get free disk space</a>, I got the code from sasha_gud, and adapt it into a console application.</p>
  <pre><code>class Program
  {
      // Pinvoke for API function
      [DllImport(&quot;kernel32.dll&quot;, SetLastError = true, CharSet = CharSet.Auto)]
      [return: MarshalAs(UnmanagedType.Bool)]
      public static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
      out ulong lpFreeBytesAvailable,
      out ulong lpTotalNumberOfBytes,
      out ulong lpTotalNumberOfFreeBytes);
  
      static void Main(string[] args)
      {
          var lFolderPath = @&quot;D:\Imagepools12&quot;;
          ulong lAvailableBytes, lTotalFree, dummy1;
          if (GetDiskFreeSpaceEx(lFolderPath, out lAvailableBytes, out dummy1, out lTotalFree))
          {
              Console.WriteLine($&quot;The available free space of {lFolderPath} is {lAvailableBytes} and total free is {lTotalFree}&quot;);
          }
          Console.ReadKey();
      }
  }
  </code></pre>
  <p>When I debug it in the Visual Studio 2019, I got the result of the lAvailableBytes and lTotalFree, both equal to 862827331584.
  <a href="https://i.stack.imgur.com/nNvc6.png" rel="nofollow noreferrer">Debug in VS get wrong lAvailableBytes</a></p>
  <p>When I directly go the Debug folder and double click the executable, then I get the correct lAvailableBytes
  <a href="https://i.stack.imgur.com/RkJ76.png" rel="nofollow noreferrer">Run exe get correct lAvailableBytes</a></p>
  <p>Could you please help me to figure out why debug in VS cannot get correct lAvailabelBytes? And how to fix it? Thank you!</p>
  <p>Update:
  Thank you @Ben Voigt for figuring out that I have run my VS as administrator and by directly run exe as my own user account, this is why I got different result. Then how could I as administrator get disk information for certain user, instead of current user?</p>