Support Forums

Welcome to Support Forums Sign in | Join | Help
in
Home Forums

ProScript to get TimeZoneInformation

Last post 09-25-2006, 4:56 AM by keydet89. 0 replies.
Sort Posts: Previous
  • ProScript to get TimeZoneInformation

     09-25-2006, 4:56 AM

    • Joined on 04-20-2006
    • Northern VA
    • Posts 35
    • Top 10 Contributor
    I've created a small ProScript to get values/data from the TimeZoneInformation key (posted below).  The script returns the data for the ActiveTimeBias value.

    Here's the issue.  Right now, the $key->{strValueData} returns the data in a string, regardless of the data type.  If the data is a DWORD (4-byte binary value) of "00 01 00 00" (as normally seen), the ProScript API will return "1 (0x000000001)".  So, at this point, the API requires some RegEx work in order to get a usable value. 

    The ProScript first locates the ControlSet that was designated as "current", locates that TimeZoneInformation key, and extracts the ActiveTimeBias value.  This value can then be used by other scripts when translating time settings retrieved, particularly when the system was in another time zone.

    Thanks,

    Harlan

    -------------------------------------------------------------------------------------------------
    #! c:\perl\bin\perl.exe
    #-------------------------------------------------------------
    # TimeZone.pl, version 0.1
    # Copyright 2006 H. Carvey, keydet89@yahoo.com
    #-------------------------------------------------------------
    use ProScript;
    #PSDisplayText("TimeZone.pl v. 0.1");
    #PSDisplayText("ProScript to get the ActiveTimeBias Time Zone info from the Registry");
    #PSDisplayText("\n");
    #-------------------------------------------------------------
    # Get the ControlSet value
    my %selectinfo = ();
    my $current;
    $numRegs = PSGetNumRegistries();
    if ($numRegs == 0) {
        PSDisplayText("No registries to process");
        return;
    }

    $regName = PSGetRegistryAt(0);
    PSRefreshRegistry($regName);
    my $keyName = "HKEY_LOCAL_MACHINE\\System\\Select";
    my $rHandle = PSOpenRegistry($regName, $keyName);

    if ($rHandle == 0) {
        PSDisplayText("Unable to locate registry key");
        return;
    }
    else {
    #    PSDisplayText("Registry opened succesfully.");
    }

    while (1) {
        $RegKeyInfo  = &ProScript::PSReadRegistry($rHandle);
      last if ($RegKeyInfo->{nType} == -1);
      next if ($RegKeyInfo->{nType} == PS_TYPE_KEY);
      my $value = $RegKeyInfo->{strRegName};
      my $data  = $RegKeyInfo->{strValueData};
    #  PSDisplayText($value." --> ".$data);
     
      $selectinfo{$value} = $data;
    }
    PSCloseHandle($rHandle);
    #-------------------------------------------------------------
    #

    foreach my $s (keys %selectinfo) {
        if ($s eq "Current") {
            $temp = (split(/\s/,$selectinfo{$s},2))[0];
            $current = (split(//,$temp,10))[9];
        }
    }

    my %tz = ();
    my $keyName = "HKEY_LOCAL_MACHINE\\System\\ControlSet00".$current."\\Control\\TimeZoneInformation";
    my $rHandle = PSOpenRegistry($regName, $keyName);

    if ($rHandle == 0) {
        PSDisplayText("Unable to locate registry key");
        return;
    }
    else {
    #    PSDisplayText("Registry opened succesfully.");
    }

    while (1) {
        $RegKeyInfo  = &ProScript::PSReadRegistry($rHandle);
        my $type = $RegKeyInfo->{nType};
      last if ($type == -1);
      next if ($type == PS_TYPE_KEY);
      my $value = $RegKeyInfo->{strRegName};
      my $data  = $RegKeyInfo->{strValueData};
    #  PSDisplayText($value." --> ".$data." $type ");
     
      $tz{$value} = $data;
    }
    PSCloseHandle($rHandle);

    my $temp = $tz{"ActiveTimeBias"};
    my $t2 = (split(/\s/,$temp,2))[1];
    $t2 =~ s/\(//;
    $t2 =~ s/\)//;
    PSDisplayText("ActiveTimeBias = ".$t2);
View as RSS news feed in XML