title: Is there a way to programmatically activate Windows on Windows 7
body: <p>I am working on a project where I need to activate Windows on a Windows 7 PC.  I wrote the code below using the Windows Software Licensing API.  MSDN says that the three functions used below require Windows 8 or Windows Server 2012 which suggests that these functions aren't available on Windows 7.  But if I open slc.dll in depends.exe which is in C:\Windows\System32 on my Windows 7 machine, I do SLOpen and SLClose functions.  But not SLActivateProduct.</p>
  
  <p>When I build the program I get linker error:</p>
  
  <pre><code>1&gt;  main.cpp
  1&gt;main.obj : error LNK2019: unresolved external symbol _SLActivateProduct@28 referenced in function _main
  1&gt;activate_windows.exe : fatal error LNK1120: 1 unresolved externals
  </code></pre>
  
  <p>How does this work at link time?  I presume this means that slc.lib (see code  below) does not have the SLActivateProduct function?</p>
  
  <p>This program doesn't need to be written in C so I can call anything from a script.  Anyone know if there would be any way of doing this on Windows 7?  It has to be a programmatic way which can be started by running a script.</p>
  
  <p>code below:</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;Slpublic.h&gt;
  #include &lt;slerror.h&gt;
  
  #include &lt;stdio.h&gt;
  
  // lib to use
  #pragma comment(lib, "slc.lib")
  
  int main() {
  
    // slmgr.vbs has:
    // private const WindowsAppId = "55c92734-d682-4d71-983e-d6ec3f16059f"
      // Windows AppId for SLID:  {55c92734-d682-4d71-983e-d6ec3f16059f} - this is a GUID
      const SLID SLID_WINDOWS = {0x55c92734, 0xd682, 0x4d71, 0x98, 0x3e, 0xd6, 0xec, 0x3f, 0x16, 0x05, 0x9f};
  
      HSLC hslc;
      HRESULT hr = SLOpen(&amp;hslc);
      if (SUCCEEDED(hr))
      {
          // try to activate windows
          hr = SLActivateProduct(hslc, &amp;SLID_WINDOWS, 0, NULL, NULL, NULL, 0);
          switch(hr) {
          case E_INVALIDARG:
              printf("SLActivateProduct - one or more arguments are not valid\n");
              break;
          case SL_E_PUBLISHING_LICENSE_NOT_INSTALLED:
              printf("SLActivateProduct - The license is not installed\n");
              break;
          case SL_E_PKEY_NOT_INSTALLED:
              printf("SLActivateProduct - The product key is not available\n");
              break;
          case SL_E_PRODUCT_SKU_NOT_INSTALLED:
              printf("SLActivateProduct - The license is not installed\n");
              break;
  
          case S_OK:
              printf("SLActivateProduct - returned S_OK\n");
              break;
          default:
              printf("SLActivateProduct - unknown return code\n");
              break;
          }
          hr=SLClose(hslc);
      }
  }
  </code></pre>