Applying Unique Windows Product Keys in GSS Clone Tasks

Applying Unique Windows Product Keys in GSS Clone Tasks
Krish_jayaratne's picture

You may want to use a unique Windows product key for each machine when deploying syspreped images using GSS. Following scripts demonstrate the process of updating the product key in sysprep file before booting to Windows.

These scripts are based on GSS 2 and XP under PCDOS PreOS, but the process is similar for other versions of GSS, Windows or PreOSs. If you use WinPE under 2.5(or higher), it is easier to use vbscript rather than awk.

This is only a sample set of scripts; you need to change and test for your environment.

Process

When running a Clone/Config task using Ghost Console to deploy a syspreped image, the sysprep file is updated with the new name of the computer during configuration phase. These scripts read the sysprep file, update the product key corresponds to the computer name based on the supplied text file. Please note that you should have a product key entry in sysprep file for these scripts to work. Scripts replace the key, but does not add.

If you use template configuration to name the computers, look at the task scenario to find the name assigned to each machine.

This process could be extended to change other parameters in the sysprep file too, for example the computer name.

Under PCDOS, this example uses awk scripts to update the sysprep file. Windows version and documentation for awk is available at http://gnuwin32.sourceforge.net/packages/gawk.htm

I could not find an official site for DOS awk, but it is available for download in many sites. (just search for DOS awk).

Updating the product key involves transferring several files to Ghost partition in clone/config task and execute scripts. To minimize the data transfer issues between scripts, these scripts use multiple arguments and take different actions based on the file name. I was trying to use env variables but there were two problems; env space run out and command line is longer than what is supported by PCDOS (128 char).

In the Clone task, following files should be transferred to Ghost partition using file transfer option.

  1. Text file containing Computer Name defined in Console and product key (pk.txt)
  2. Script to find the Windows volume using ghconfig.exe. Sysprep.inf file is in Windows system volume (cgetsp.awk)
  3. Script to update the product key in sysprep file(csysprep.awk)
  4. DOS batch file to run the scripts (updsn.bat)
  5. Omnifs.exe from ..\Ghost folder in Console
  6. AWK for DOS (awk.exe)

This script saves a copy of sysprep file in a folder called test in Windows volume. Once the process is tested, remove the lines that copy the sysprep file to test folder before using it in production systems since sysprep file may contain sensitive info such as credentials. Having a copy of the file is certainly helpful during development phase.

Scripts

PK.txt - Product key file

Product key file is a text file with computer names and the product key assigned to it.

 KR-Test-02	ABCDE-12345-ABCDE-12345-ABCDE
 KR-Test-03	ABCDE-ABCDE-12345-12345-12345
 KR-Test-04	12345-ABCDE-12345-ABCDE-12345
 

cgetsp.awk - script to find Windows location using the output of GHConfig

 BEGIN {count = 0; flag = 0};
 {
 if ( match($0,/Active/) != 0) flag = 1;
 if (flag) count++;
 if (count == 3){ 
   print "omnifs.exe copy "substr($0,1,3)":\\sysprep\\sysprep.inf sysprep.inf" > "getsys.bat";
   print "omnifs.exe copy sysprep.mod "substr($0,1,3)":\\sysprep\\sysprep.inf" > "putsys.bat";
   print "omnifs.exe mkdir "substr($0,1,3)":\\test" > "copysys.bat";
   print "omnifs.exe copy \\Ghost\\incoming "substr($0,1,3)":\\test" >> "copysys.bat";
   exit;
   }
 }

csysprep.awk - Script to update the ProductKey

function nextfile()  { _abandon_ = FILENAME; next }
_abandon_ == FILENAME {
  if (FNR == 1)
    _abandon_ = ""
  else
    next
  }

{
if (fileno == 1){
  if (match($0,/ComputerName/) !=0 ) {
    CN=$0
    gsub(" ","",CN);
    sub(/ComputerName=/,"",CN);
    fileno = 2
    nextfile()
  }
 }
 
 if (fileno == 2) {
  if ($1 == CN) {
    PK = $2;
    fileno = 3;
    nextfile()
  };
 }
 
 if (fileno == 3) {
  if (match($0,/ProductKey/) !=0 ){
    print "  ProductKey = "PK > "sysprep.mod";
  } 
  else{ 
    print $0 > "sysprep.mod";
  };
 }
}

updsn.bat - And finally, the batch file to run

 CD \Ghost\Incoming
 \Ghost\Ghconfig Windows > gh.txt
 awk -f cgetsp.awk gh.txt
 Call getsys.bat
 awk -f csysprep.awk -v fileno=1 sysprep.inf pk.txt sysprep.inf
 Call putsys.bat
 Call copysys.bat

Now, add a file transfer step in your clone/config task to transfer these files, omnifs.exe and awk.exe to Ghost partition. Then add step command execution in Ghost partition to execute incoming\updsn.bat

3.1
Average: 3.1 (20 votes)