title: In WinDBG/SOS.DLL: How can I save all modules/assemblies listed by !DumpDomain to disk at once?
body: <p>I have an app that loads a bunch of <code>dlls</code> dynamically through a <code>memorystream</code> at runtime. Using WinDBG I can see the loaded modules when using the command !DumpDomain. Using other commands <code>(like ! lm)</code> does not show/list these hidden <code>dlls</code>. </p>
  
  <p>Now I want to save these <code>dlls</code> to disk by using the <code>!SaveModule</code> [ModuleNumber from !DumpDomain list] command. It works perfectly but the thing is I have to do it manually for each module. I want to <em>automate</em> this process and found the following code:</p>
  
  <pre><code>!for_each_module .if ($spat ("${@#ImageName}","*.exe")) { !SaveModule ${@#Base} c:\temp\${@#ModuleName}.exe } .else { !SaveModule ${@#Base} c:\temp\${@#ModuleName}.dll }
  </code></pre>
  
  <p>The problem with this code is that the code actually does not export the desired hidden <code>dlls</code>. I think it has something to do that "for_each_module" does not include modules from the !DumpDomain command.</p>
  
  <hr>
  
  <ul>
  <li><p>Does anybody have a solution for that? Or </p></li>
  <li><p>Is there a better way to save the <code>dlls</code> to disk? </p></li>
  </ul>
  
  <hr>
  
  <p>Any advice appreciated!</p>