Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Desktop

Article Accessing the Windows Registry using Rapise

by Adam S on Tuesday, March 29, 2016

Sometimes when testing local/desktop applications you need to access the Windows registry to verify that keys exist or that keys have specific values. For example you may be testing that a DLL was successfully registered. This article provides information on the 'UsingRegistry' sample that comes with Rapise.
The following sample 'UsingRegistry' is shipped as part of the default installation, so the first thing to do is:
  • Go to the Rapise Start Page
  • Click on Fetch Samples to make sure that you have all the latest samples
  • Browse the samples to see the UsingRegistry sample.

The sample demonstrates the usage of the Windows Registry:

  • The sample gets the registry values to determine the OS type (Win7/8/10/2008/2012, etc)
  • The sample also gets the OS version and the Owner
  • The sample uses the standard object WScript.Shell and its method RegRead to access the Registry

   //Creates an WScript.Shell object.
   
var shl = new ActiveXObject("WScript.Shell");

    var osType = GetOsType();
   
Tester.Assert("The machins OS type", true, osType);

    var osVersion = GetOsVersion();
    Tester.Assert("The service pack version", true, osVersion);

    var osOwner = GetOsOwner();
   
Tester.Assert("The registered owner of OS", true, osOwner);

    /**
     * Reads OS type from registry.
     * @returns OS type.
     */

    function GetOsType()
    {
        
return shl.RegRead ("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName");
    }  

    /**
     * Reads OS service pack version from registry.
     * @returns Service pack version.
     */
   
function GetOsVersion()
    {
     
try
     
{
           
return shl.RegRead ("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\CSDVersion"); 
     
    }
        
catch(e)
          {
           
return "No service pack";
          }
    }
   

    /**
     *Reads OS registered owner from registry.
     *@returns OS registered owner.
     */
   
function GetOsOwner()
    {
        
return shl.RegRead ("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\RegisteredOwner");
    }  

Further Reading

For more information on the Windows API / Scripting Host methods being used, please refer to:

Attachments
Article Info
Last Updated: 3/29/2016
Article ID: KB203
# Views: 199
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.