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

Hi, I am trying to use the following code to query open files on a remote w2k server. The server is in a domain that requires me to authenticate. I could use runas.exe but would rather code it into the script to be able to pass my ID/Password as arguments or be prompted for them. Has anyone done anything like this before? As always any help is greatly appreciated.
use Win32::Lanman; $server = "$ARGV[0]"; if(!Win32::Lanman::NetFileEnum($server, '', '', \@infos)) { print "Sorry, something went wrong; error: "; # get the error code print Win32::Lanman::GetLastError(); exit 1; } foreach (@infos){ if(($${_}{permissions} == "1") || ($${_}{permissions} == "9")){$ac +cess = "Read";} elsif($${_}{permissions} == "35"){$access = "Read Write";} else{$access = "Unknown";} print "[" . $${_}{id} . "] " . $${_}{pathname} . "\n\tUser:\t" . $ +${_}{username} . "\n\tLocks:\t" . $${_}{num_locks} . "\n\tAccess:\t" +. $access . "\n"; }

Replies are listed 'Best First'.
Re: perl version of runas
by NetWallah (Canon) on Jan 05, 2005 at 20:45 UTC
    You seem to be looking for one of the Win32 "impersonate" API's who's exact name escapes me at the moment.

    I wanted to offer a few suggestions:

    • You could use "runas.exe", and pass parameters to it that you get via the command line, or via perl prompts. This would be easier to debug, and would avoid the confusion inherent in the impersonate API.
    • Use a Hash to store the access permission names:
      my %permname = qw(1 Read g Read 35 Write); $access = $permname{ $${_}{permissions} } || "unknown" ;

        ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld