Sunday, June 27, 2010

Registry update on Windows EC2 Instance

While auto-provisioning of a Window EC2 instance, which involves launching an instance, creating/attaching EBS volumes to the successfully launched instance, installing applications, configuring application settings etc., we at CSS Labs are unable to update the registry. The registry update helps the user to communicate with the application but Microsoft never loads the user profiles under the path HKEY_USERS by default, until the user login to the instance.

The auto-provisioning of the windows instances are facilitated by CloudSmart without human intervention while launching an instance. CloudSmart tool will be installed and bundled with necessary AMI’s. The tasks mapped to AMI’s are listed in XML format and stored in S3. While launching an instance for a client, using the bundled AMI’s, the CloudSmart script will be invoked and the matching XML file will be pulled from S3 to EC2 instances. On booting the instance, Java ANT script of CloudSmart will invoke and execute the planned tasks mapped to the AMI. Using CloudSmart, we accomplished most of EC2 provisions. Provisioning a Windows EC2 instances is challenging, since Microsoft is not as open as Linux and not allowing system level updates with too many restrictions at core level.

While provisioning Windows based EC2 instances for a leading CRM provider, we faced few problems. The architecture need to enable communication between 2 servers, an application server and a Web Server. The application server will have the CRM tool to be installed and configured. Also the application server needs to configure the SQL server and map EBS volumes to SQL data directories. All the above tasks are achieved using CloudSmart scripts. But for total completion of CRM setup, the registry need to be updated with the private IP of the application server, CRM database name and its ports under the key path HKEY_USERS. The specialty of this key path is to load the user profile under this column, only when the user logon to the machine. The problem here is to update the registry values under this key path for all users, when the EC2 instance comes up. Since we want to do setup completion during EC2 windows boot up, at first, we tried the following options.

  • By using the windows utility library(adbapi32.dll), we tried to logon to the machine through the C# code. Its able to logon, but not creating the user entry in the registry
  • Updating those registries using logon script. Which works, since Windows has the SID created/loaded into the registry editor.
  • Load the user profile reg file in the registry attempts to make no impact on it.
After an exhaustive research, we came to know that, it could be solvable using VB Script.

The steps that we performed in the VB script are.,
  • Load the file ntuser.dat into the registry.
  • Update the corresponding registry values.
  • Unload all the profiles from the registry.