RayRay459 has asked for the wisdom of the Perl Monks concerning the following question:

I'm getting this error after my program prompts for the hostname and reg key and value.: "Can't locate object methond "connect" via package Win32::TieRegistry" (perhaps you forgot to load "Win32::TieRegistry" at line 26, <STDIN> line 3. Here;s what i have
# This program will add a System Environment Variable. It will require + a reboot to take # effect. #!/usr/bin/perl -w use strict; my ($Reg, $Host, $Key, $Value); use Win32::TieRegistry ( TiedRef => \$Reg, ArrayValues => 1, Delimiter => '/', ':REG_' ); # Asking for machine name and info to be added to the sys env var print "What host would you like to connect to? "; chomp($Host = <STDIN>); print "What name would you like for the Sys Environment Variable? "; chomp($Key = <STDIN>); print "What value would you like to assign to this variable? "; chomp($Value = <STDIN>); # this is the system environment variable area my $SysEnv= $Reg->connect("$Host", "LMachine/System/CurrentControlSet/ +Control/" . "Session Manager/Environment/") or die "Can't connect to $Host 's registry or can't open Registry + key, Session Manager/Environment: $^E +\n"; # create a new value and set it's data $SysEnv->{"/$Key"} = "$Value";
Any help would be appreciated by my fellow monks. :o) ~Ray~

Replies are listed 'Best First'.
Re: getting errors using the TieRegistry module
by particle (Vicar) on Jul 09, 2001 at 21:30 UTC
    i think this statement is in error~
    my $SysEnv= $Reg->connect("$Host", "LMachine/System/CurrentControlSet/ +" . "Control/Session Manager/Environment/") or die "Can't connect to $Host 's registry or can't open Registry ke +y," . " Session Manager/Environment: $^E\n";
    and should be more like~
    my $SysEnv= $Reg->{"//$Host/LMachine/System/CurrentControlSet/" . "Control/Session Manager/Environment/"} # no connect, use {}, not () or die "Can't connect to $Host 's registry or can't open Registry ke +y," . " Session Manager/Environment: $^E\n";
    but i haven't tested it.

    ~Particle

      That, or capitalize the first "c" in "connect". I'm partial to your method, but there is also a Connect() method available in the module.

              - tye (but my friends call me "Tye")
        changing it to Connect from connect made it work. Thanks guys for all of your help. You guys rock!!! ~RAY~