Windows 7 Activation Proposal

  • Senior Developer

    I’d like to suggest that FOG auto-activate computers after imaging. In my current environment there are many different models each with a unique product key, meaning each computer must be activated manually. This automation would be accomplished with the hostname changer used in the FOG Client. Below is the current code that I have been using.

    [B]Edit 1[/B] – List all changes made and switch to hosts table instead of inventory
    – Made this proposal similair to a guide, but it is still a feature request


    [B]…\FOG Service\src\FOG_HostNameChanger\MOD_HostNameChanger.cs[/B] (if you have not made any other changes to this file, you may download a compiled version of it in the attachments)

    Once this change is completed you must compile the dll (or use the attached one) and give it to every instance of the client, or use the Client updater in FOG.

    ~line 362
    if (arData.Length == 7)
    strHostName = strHostResults.Remove(0, 5);
    String strUseAD = arData[1];
    String strD = arData[2];
    String strOU = arData[3];
    String strU = arData[4];
    String strP = arData[5];
    String strKey = arData[6];

                                    if (strKey != null)
                                            strKey = strKey.Trim();
                                            if (strKey.StartsWith("#Key=")) {
                                            strKey = strKey.Replace("#Key=", "");
                                            Process scriptProc = new Process();
                                            scriptProc.StartInfo.FileName = @"cscript";
                                            scriptProc.StartInfo.Arguments =@"//B //Nologo c:\windows\system32\slmgr.vbs /ipk " + strKey;
                                            scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                                            scriptProc.StartInfo.Arguments =@"//B //Nologo c:\windows\system32\slmgr.vbs /ato";


    [SIZE=4][B]SQL Database[/B][/SIZE]
    Using phpmyadmin or the terminal, add a column to the hosts table with the following attributes:
    Column: hostProductKey
    Type: varchar(50)
    Collation: latin1_swedish_ci
    Null: No
    Default: None

    [SIZE=4][B]FOG Web Server[/B][/SIZE]

    print ‘#ADPass=’.$Host->get(‘ADPass’)."\n";
    print ‘#Key=’.$Host->get(‘productKey’);


    line ~#9
    public $databaseFields = array(
    ‘id’=> ‘hostID’,
    ‘name’=> ‘hostName’,
    'productKey => ‘hostProductKey’,


    line ~#177 AND ~#373
    _(‘Host Description’) => ‘<textarea name=“description” rows=“5” cols=“40”>${host_desc}</textarea>’,
    _(‘Product Key’) => ‘<input type=“text” name=“key” value="${host_key}" />’,

    line ~#206
    ‘host_devs’ => $_REQUEST[‘dev’],
    ‘host_key’ => $_REQUEST[‘key’],

    line ~#277
    ‘host_devs’ => $_REQUEST[‘dev’],
    ‘host_key’ => $_REQUEST[‘key’],

    line ~#401
    ‘host_devs’ => $Host->get(‘kernelDevice’),
    ‘host_key’ => $Host->get(‘productKey’),

    /[B]var/www/fog/service/key.register.php[/B] (Optional if you want to be able to update a host’s product key at boot after being registered)
    –See Attachments

    [SIZE=4][B]Host Registration[/B][/SIZE]

    See [url][/url]
    Note that the wiki’s instructions are not up to date below are the changes, in the format old_command => new_command
    You may also have authentication issues if you try and unzip the init.xz file where it resides, if so move it to another folder and move it back when finished)
    gunzip init.gz => xz --decompress init.xz
    gzip init => xz -z -9 -C crc32 init

    [B]…/bin/fog.key.reg[/B] (Optional if you want to be able to update a host’s product key at boot after being registered)
    –See Attachments, remove the .txt ending on it. I am unable to upload files that end in .reg


    line ~#76

    line ~#231
    echo -n " Enter the product key for this computer: ";
    read productKey;
    productKey=echo $productKey | base64;

    line ~#302
    while [ “${res}” = “” ]
    res=wget -O - --post-data="mac=$mac&advanced=1&host=$host&imageid=$imageid&productKey=$productKey&primaryuser=$primaryuser&other1=$other1&other2=$other2&doimage=$realdoimage&doad=$blDoAD&location=$locationid&username=$user64&groupid=$group64" "http://${web}service/auto.register.php" 2>/dev/null
    echo “${res}”;
    sleep 2;

    [B]…/etc/init.d/S99fog[/B] (Optional if you want to be able to update a host’s product key at boot after being registered)

    line ~#56
    elif [ “$mode” == “manreg” ]; then
    elif [ “$mode” == “keyreg” ]; then

    [SIZE=4][B]Boot Menu[/B][/SIZE] (Optional if you want to be able to update a host’s product key at boot after being registered)


    line ~#79
    ‘fog.reginput’ => ‘Perform Full Host Registration and Inventory’,
    ‘fog.keyreg’ => ‘Update Product Key’,

    line ~#529
    if (!$this->Host || !$this->Host->isValid())
    if ($option != ‘fog.quickdel’ && $option != ‘fog.keyreg’ &&$option != ‘fog.quickimage’ && ( $showDebug || $option != ‘fog.debug’ ) )
    $this->menuItem($option, $desc);

    line ~#560

    if ($option == ‘fog.sysinfo’)
    $this->menuOpt($option, “mode=sysinfo”);
    else if ($option == ‘fog.keyreg’)
    $this->menuOpt($option, “mode=keyreg”);


  • Senior Developer

    The key should be base64 encoded. Let me see if it’s being decoded in the GUI

  • @Tom:

    I tried to copy my windows 7 keys from a another db to the new column in the host table.
    The result looks like this:


    Then i inserted the key directly in the webgui and the key looks like this in phpmyadmin:


    It looks like the key will be saved in a crypted way? Is that correct ?

  • [quote=“Tom Elliott, post: 35481, member: 7271”]Pretty much, yes.[/quote]

    Ok i will give it a try.


    Added the WIn7 Key to the Host details and removed the serial from the client.
    Replaced HostnameChange.dll and rebooted client.
    After reboot the client was activated again. Perfect !!

    Big Thanks to Jbob and Tom.

    I hava only one suggestion:

    Is it possible to write some informations about the activationprocess to the fog logfile ?
    e.g. if the activations fails and why? Or it was succesfull.

  • Senior Developer

    Pretty much, yes.

  • @Tom: so if i’m using fog 1.2 i only need to replace the “HostnameChange.dll” created by Jbob to run the win7 activation during the hostchanger task ?

  • Moderator

    This is a great feature, thanks jbob!

  • Senior Developer

    SVN 2056 should have these code revisions now.

    The MOD_HostnameChanger.cs script has been updated as well, but it HAS NOT BEEN COMPILED in fog client.

  • Senior Developer

    @Tom Elliott, that is great, it is one less thing I have to implement each time I upgrade!

  • Senior Developer


    I hope you don’t mind, but I’m using this code and adding it. I’m going to ask if the user wants to add the product key on registration. The key changer/updater function is now embedded in ipxe, meaning no need for the key.register.php or the fog.key.reg files.

  • Senior Developer

    @Ivanov Alexandru I believe it should work with no changes but currently where I work we are still running 1.1.0. My guess is that some of the line numbers may be off. However, if you would like help implementing it into 1.1.2 I would be more than willing to assist you. You can PM me if you wish me to help.

  • Hello Jbob , if i make these changes to the last [FONT=Ubuntu][COLOR=#555555]Version: 1.1.2 , it should work ?[/COLOR][/FONT]


  • Senior Developer

    @axel12: I may not be understanding you, but at the institution I work at we do not have the luxury of volume licensing, each computer has its own unique product key.

    @jayphizzle We just upgraded to 1.1 and implemented it, but we were using this modification on 0.32 and 1.0.1. There are additional changes I have implemented. However, I am going to re-code them to be cleaner. Once I do that I’ll post all of my changes.

    [B]Edit[/B] All changes I have made for v1.1 are now in the original post in case this feature is not put into FOG but people, like jayphizzle wish to implement it.

  • @JBob: very nice customization. We have the same activation ‘problem’, but using a autoit script which runs after each deployment.
    I would be great if this can be handeld by fog as well.

    Which version are you using? Are this the only changes which are needed?

  • bro, Microsoft has got you covered …


    We use VAMT at my school. You can have the choice of using MAK activation (not KMS) if your school does purchase keys in volumes. OR you can activate with no key - which will use the native key already built into the windows box.

    Also note this will work for Office too … and work through a proxy as well.

    The only requirement is that the windows box MUST be on the domain - so you don’t even need any AD usernames / passwords - since the authentication is done locally from the credentials you are already using.

Log in to reply