Windows Perl Scripting Forums » Perl

help with Win32::TieRegistry permission

(9 posts)

  1. ifup
    Member

    I tried to do this


    BEGIN
    {
       use Win32::TieRegistry( Delimiter=>"\\", ArrayValues=>0 );
       $Registry = $Registry->Open('Â’, {Access => 0×2000000});
    }



    but perl complains

    this was from Dave's post in his blog
    Thanks
    Posted 6 years ago #
  2. Dave
    Perl guy

    What is the error perl complains with?
    Posted 6 years ago #
  3. ifup
    Member

    Dave,
    I copied and pasted directly from the blog and here is what I got

    D:\scripts>perl Perl-1.pl
    Can't find string terminator "'" anywhere before EOF at Perl-1.pl line 5.

    D:\scripts>
    so I changed the it to two single quotes


    #!/usr/bin/perl -w
    #BEGIN
    #{
    #   use Win32::TieRegistry( Delimiter=>"\\", ArrayValues=>0 );
    #   $Registry = $Registry->Open(', {Access => 0×2000000});
    #}

    BEGIN
    {
       use Win32::TieRegistry( Delimiter=>"\\", ArrayValues=>0 );
       $Registry = $Registry->Open('', {Access => 0×2000000});
    }



    and got this.
    D:\scripts>perl Perl-1.pl
    Unrecognized character \xD7 at Perl-1.pl line 11.

    D:\scripts>
    one thing to note on the pasted text from above there is a accent character missing?? from the paste I do not know where it went and don't know what ascii code it is to replace it with but I just copied and pasted from the blog entry.

    Thanks for the help.
    Adam
    Posted 6 years ago #
  4. Dave
    Perl guy

    Your code is correct, the code in the blog wasn't (past tense; I just changed it). The blogging software saw two ' characters and changed them. Sigh.
    Posted 6 years ago #
  5. ifup
    Member

    If you could show me how I can read this key in read only.
    I would appreciate it.


    sub sdat {
        $Registry->Delimiter("/");
        $sdat = $Registry->{"//$host/LMachine/SOFTWARE/Network Associates/TVD/Shared Components/VirusScan Engine/4.0.xx"}->{"szVirDefVer"};
            if ($sdat) {
                    print report "<td>SDAT Version: $sdat</td>\n";
                    return 1;    # returns 1 if true
                }
                else {
                    print report "<td>No SDAT</td>\n";
                    return 0;    # returns 0 if false
            }
    }


    on some machines the registry is not opening with read write access
    so I think that the read only ACCESS is the solution.
    Thanks
    Adam
    Posted 6 years ago #
  6. Dave
    Perl guy

    From the TieRegistry.pm file:


        # Open a Registry key:
        $subKey= $key->Open( "SubKey/SubSubKey/", { Access=>KEY_READ, Delimiter=>"/" } );



    So your code would look like:


    sub sdat {
        $myKey = $Registry->Open( $host, "LMachine/SOFTWARE/Network Associates/TVD/Shared Components/VirusScan Engine/4.0.xx", {Access=>KEY_READ, Delimiter=>"/"} ) || die;
        $sdat = myKey->{"szVirDefVer"};
            if ($sdat) {
                    print report "<td>SDAT Version: $sdat</td>\n";
                    return 1;    # returns 1 if true
                }
                else {
                    print report "<td>No SDAT</td>\n";
                    return 0;    # returns 0 if false
            }
    }

    Posted 6 years ago #
  7. ifup
    Member

    You got me I tried your code verbatim got this.

    Usage: $obj= Win32::TieRegistry->new( $subKey, { OPT=>VAL,... } );
    options: Access Delimiter
    Called at D:\scripts\activeDirectoryMaintenance.pl line 144
    is a $ not required here on myKey?


    $sdat = myKey->{"szVirDefVer"};


    Here is what version of perl and TieRegistry I have is.

    This is perl, v5.8.8 built for MSWin32-x86-multi-thread
    (with 50 registered patches, see perl -V for more detail)

    ### from cpan###
    Fetching with LWP:
    http://ppm.activestate.com/CPAN/modules/03modlist.data.gz
    Going to read C:\Perl\cpan\sources\modules\03modlist.data.gz
    Going to write C:\Perl\cpan\Metadata
    Distribution A/AD/ADAMK/Win32-TieRegistry-0.25.zip
    Distribution L/LG/LGODDARD/Win32-TieRegistry-Dump-0.031.tar.gz
    Distribution L/LG/LGODDARD/Win32-TieRegistry-PMVersionInfo-0.2.tar.gz
    Module Win32::TieRegistry (A/AD/ADAMK/Win32-TieRegistry-0.25.zip)
    Module Win32::TieRegistry::Dump (L/LG/LGODDARD/Win32-TieRegistry-Dump-0
    .031.tar.gz)
    Module Win32::TieRegistry::PMVersionInfo (L/LG/LGODDARD/Win32-TieRegist
    ry-PMVersionInfo-0.2.tar.gz)
    6 items found


    cpan> install Win32::TieRegistry
    Win32::TieRegistry is up to date.
    Posted 6 years ago #
  8. Dave
    Perl guy

    Doh! This is what happens when I try to go too quickly. :-//

    Yeah, it should be:


    sub sdat
    {
        my $myHive = $Registry->Connect( $host, "LMachine", {Access=>KEY_READ, Delimiter=>"/"} ) || die;
        my $myKey = $myHive->{"Software/Microsoft/Network Associates/TVD/Shared Components/VirusScan Engine/4.0.xx"}; 
        my $sdat = myKey->{"szVirDefVer"};
        if ($sdat)
        {
                print report "<td>SDAT Version: $sdat</td>\n";
                return 1;    # returns 1 if true
        }
        else
        {
            print report "<td>No SDAT</td>\n";
            return 0;    # returns 0 if false
        }
    }



    Note that this code first opens the remote connection to the LMachine hive on $host. Then it creates $myKey.
    Also note that I lexically scoped the new scalar variables using 'my' (as a good coder should). ;-)
    Posted 6 years ago #
  9. ifup
    Member

    Dave,
    Thanks!
    I only had to change one thing which was
    the line that read

    my $sdat = myKey->{"szVirDefVer"};


    to


    my $sdat = $myKey->{"szVirDefVer"};


    other than that it works now
    I guess we have to make the connect first with the KEY_READ
    then read the key afterward instead of doing it in one shot :(
    but alas it is working :D
    Thanks for the help on that!!

    ok ok I will start using (my) on MY scalars more X-D


    FINAL subroutine:



    sub sdat {
        my $myHive = $Registry->Connect( $host, "LMachine", {Access=>KEY_READ, Delimiter=>"/"} ) || die;
        my $myKey = $myHive->{"Software/Network Associates/TVD/Shared Components/VirusScan Engine/4.0.xx"}; 
        my $sdat = $myKey->{"szVirDefVer"};
        if ($sdat)
        {
            print REPORT "<td>SDAT Version: $sdat</td>\n";
            return 1;    # returns 1 if true
        }
        else
        {
            print REPORT "<td>No SDAT</td>\n";
            return 0;    # returns 0 if false
        }
    }

    Posted 6 years ago #

RSS feed for this topic

Reply

You must log in to post.