Hello,
I've managed to reduce some code I have been using to an acceptable minimum that will allow duplication of the problem I'm seeing.
The code is only 40 lines. The code below has an array initialized with some windows machine names. The code attempts to attach to the registry of each machine. These machines are all active on the network. I have remote registry access to the first two machines in the array but not the rest. I'm hoping it should be fairly easy for someone to duplicate this situation.
Anyway, the actual problem I'm experiencing is that if I do not have permission to connect to a remote registry the code should - after about 35 seconds - print "unable to connect to registry!" and then move on to the next machine. It does this fine.
However if I uncomment the line that reads:
$text_sid = SID_bin2text($sid);
the code is then stuck when attempting to connect to the registry of a machine I do not have rights to. It sits there forever and I don't get the "unable to connect to registry!" message.
There's some sort of conflict going on here but I don't quite know where.
How can I fix this problem?
Thanks,
PJ

code is below
use Win32::TieRegistry( Delimiter=>"#" ); use Win32; $nodename = $ENV{COMPUTERNAME}; $domain = "dpcdom"; @node_list = ("adledsu11", "adldpca03","dpc011510141", dpc011510143", + "dpc011510157"); foreach $node (@node_list) { print "\n$node\n"; undef $hkey_connect; $Register = "SYSTEM#CurrentControlSet#Control#ProductOptions"; if ($nodename eq $node) { $hkey_connect = $Registry->{"LMachine#"}; } else { $hkey_connect = $Registry->Connect($node, "LMachine#", {Access=>KEY_READ}); } if ($hkey_connect) { print "successful connection to $node ...\n"; $server_role = $hkey_connect->{"$Register#ProductType"}; print " server_role is $server_role\n"; # # # Get Administrator account text SID if ($server_role eq "Primary Domain Controller" or $server_role eq "Domain Controller") { Win32::LookupAccountName("\\\\$node", $domain, $garbage, $sid, $sid_type); } else { Win32::LookupAccountName("\\\\$node", $node, $garbage, $sid, $sid_type); } my $text_sid = "default"; # $text_sid = SID_bin2text($sid); print " text_sid is $text_sid\n"; } else { print "unable to connect to registry!\n"; } } sub SID_bin2text { my($bin) = @_; my ($Revision, $SubAuthorityCount, @IdentifierAuthorities) = unpack("CCnnn", $bin); ($IdentifierAuthorities[0] || $IdentifierAuthorities[1]) and return; my($temp, $temp2, @SubAuthorities) = unpack("VVV$SubAuthorityCount",$bin); return "S-$Revision-$IdentifierAuthorities[2]-".join("-",@SubAuthorities); }

In reply to Win32 Tieregistry issue by vlaero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.