title: Hard Drive Serial Number Is Different When NSIS Calls Script
body: <p>I have a very weird error occurring. I have a Python script that prints out the user's Hard Drive serial number.</p>
  
  <p>If I run this script in idle (or simply double click the script) it prints out my Hard Drive serial number as: <code>09sd01u4ctzn</code>.</p>
  
  <p><strong>BUT If</strong> my NSIS installer runs that same Python script it prints out my Hard Drive serial number as: <code>90ds104utcnz</code>. Ie, each 2 characters are reversed (instead of <code>09</code>, its <code>90</code> and so on).</p>
  
  <p><strong>Do you know why this is happening?</strong></p>
  
  <p>Some important information:  </p>
  
  <ul>
  <li>The NSIS installer runs with elevated privileges (Admin)</li>
  <li>My laptop is 64 bit  </li>
  <li>I am using Python 2.7  </li>
  <li>If I run the Python script (through Idle) with elevated privileges it still prints out the same serial no. (<code>09sd01u4ctzn</code>) so I dont think elevated privileges is the cause.   </li>
  <li>Maybe the cause is that WPython.exe is run as UTF-8 (or non-ascii)?  </li>
  <li>Maybe the NSIS installer is 64 bit which affects the interpretation of the serial no.? </li>
  </ul>
  
  <p>Heres my simple python script:  </p>
  
  <pre><code>import wmi
  def get_hard_drive_serial():
      c = wmi.WMI()
      for item in c.Win32_PhysicalMedia():
          if "PHYSICALDRIVE" in str(item.Tag).upper():
              return str(item.SerialNumber)
  
      return None
  
  
  print "HD Serial as Regular User: " + get_hard_drive_serial()
  </code></pre>
  
  <p><em>Note:</em> Obviously I am not exporting a NSIS installer that calls a python script (because not all windows users have python installed). So I am creating an .exe from that python script and having the NSIS installer call that. I need an external .exe because NSIS has no easy way to determine the users Hard Drive serial no.</p>
  
  <p><strong>-------------------------------------------------</strong><br>
  Edit:</p>
  
  <p>So I've tested a simple NSIS script and python script. The NSIS script calls the python script using <code>EXECWAIT</code>. As you can see the serial no. is different when the script is called by NSIS than if it is called by itself OR though a C# program (I've tested that also).</p>
  
  <p>Any ideas what on earth is going on?</p>
  
  <pre><code>InstallDir  "abc"
  Name        "def"        
  OutFile     "def.exe"
  
  Section
      DetailPrint "Hello World"
  
      ExecWait '"cmd.exe" /k' # Then type GetMACAddress.py in cmd (make sure python script is in same dir as the installer)
  
  SectionEnd
  </code></pre>
  
  <p>GetMACAddress.py</p>
  
  <pre><code>import wmi
  c = wmi.WMI()
  for item in c.Win32_PhysicalMedia():
      if "PHYSICALDRIVE" in str(item.Tag).upper():
          print item.Tag + ", " + item.SerialNumber
  
  raw_input("Pause")
  </code></pre>