title: Creating a Mutex with CreateMutex(), and using SECURITY_ATTRIBUTES
body: <p>I'm coding with Visual Studio C++ 2010 and I am creating a <code>Global\</code> Mutex with <code>CreateMutex()</code>. You can use <code>CreateMutex()</code> like so:</p>
  
  <p><code>CreateMutex(NULL, FALSE, NULL);</code></p>
  
  <p>with the first argument being the security attributes. </p>
  
  <p>I know you can create your own security attributes as so:</p>
  
  <pre><code>SECURITY_DESCRIPTOR sDescriptor;
  InitializeSecurityDescriptor(...);
  SetSecurityDescriptorDacl(...);
  SECURITY_ATTRIBUTES sAttribute;
  // set sAttribute's fields
  ...
  ...
  ...
  
  CreateMutex(sAttribute, FALSE, NULL);
  </code></pre>
  
  <p>My problem is that I don't really UNDERSTAND why you need to make your own security descriptor and attributes when making the mutex. My question is:</p>
  
  <ul>
  <li>What are the real differences between the default security attribute (<code>NULL</code>) and creating your own as above?</li>
  <li>How does the security attribute created from one computer or process different from the that of another computer or process if the same exact code is ran?</li>
  </ul>
  
  <p>and for further discussion, when creating the mutex with the default security attribute like <code>CreateMutex(NULL, FALSE, NULL);</code> within a service and trying to open the same mutex with <code>OpenMutex(MUTEX_ALL_ACCESS, FALSE, NULL);</code> from a user-application outside of the service, you get an error 5 from <code>OpenMutex()</code> which is <code>ERROR_ACCESS_DENIED</code>. When you add the created security attribute, you can successfully open the mutex from the user-application. </p>
  
  <p>Why is this? My theory is because services are ran in session 0, and all other applications run in different sessions so the security attributes must be zero. But I don't truly understand what the difference between making a security attribute or using the default is. Am I thinking in the right direction?</p>