Please excuse the long post but I thought that the code may help in making the question clear. Super Search did not turn up much to go on when I searched for "Win32 authentication". I have a W2k server that is NOT part of a domain. I can connect to it using

net use \\server\ips$ /user:me pass
'me' being a local user on the server and 'pass' being that users password. I am then able to control the services via Win32::Service. I came up with the following to connect and control the services but this that it is untidy... or is it..?
use strict; use warnings; use Win32::Service; my (%list, %status); my %STATE = ( 0 => 'unknown', 1 => 'stopped', 2 => 'starting', 3 => 'stopping', 4 => 'running', 5 => 'resuming', 6 => 'pausing', 7 => 'paused', ); my $display_name = shift @ARGV || die "usage: $0 ServiceName MachineNa +me\n"; my $machine = shift @ARGV || die "usage: $0 ServiceName MachineName\n" +; $machine = "\\\\$machine"; $machine =~ s/^\\{2}/\\\\/; print "Please enter the username to connect as:\n"; chomp (my $usr = <STDIN>); print "Please enter your Password:\n"; chomp (my $pwd = <STDIN>); my $cmd = "net use $machine\\ipc\$ /user:$usr $pwd"; print "$cmd\n"; system ("$cmd"); if (Win32::Service::GetServices($machine, \%list)) { if (defined $list{$display_name}) { if (Win32::Service::GetStatus($machine, $list{$display_name}, +\%status)) { print "=================================================== +==============================================\n"; print "The $display_name service on $machine is " . $STATE +{$status{CurrentState}} . "\n"; print "=================================================== +==============================================\n\n"; } else { print "Could not find the '$display_name' service.\n"; print "Names are case sensitive.\n"; } } } else { print "Could Not connect to $machine: "; print Win32::FormatMessage(Win32::GetLastError()), "\n"; } system ("net use $machine\\ipc\$ /d");

I have tried changing the authentication to use AdminMisc instead of the net use bit. like so...

use strict; use warnings; use Win32::AdminMisc; my $machine = shift @ARGV or die "Usage: $0 ServerName\n"; #$machine = Win32::NodeName() unless($machine = shift @ARGV); $machine = "\\\\$machine"; $machine =~ s/^\\{2}/\\\\/; print "Machine Name: $machine\n"; print "Please enter the username to connect as:\n"; chomp (my $usr = <STDIN>); print "Please enter your Password:\n"; chomp (my $pwd = <STDIN>); my $LogonUser = Win32::AdminMisc::GetLogonName(); print "Logon User: $LogonUser\n"; if (Win32::AdminMisc::UserCheckPassword($machine, $usr, $pwd)) { print "$pwd is correct password for $usr on $machine\n"; } else { print "Bad Username or Password\n"; } print "==============================================================\ +n\n"; if (Win32::AdminMisc::LogonAsUser("$machine", "$usr", "$pwd", LOGON32_ +LOGON_BATCH)){ print "Successfully logged on.\n"; } else { print "Failed to logon.\n\tError: ", Error(), "\n"; }

The UserCheckPassword works and I get "pwd is the correct password for me on \\server" and it fails if the pwd is incorrect. However the LogonAsUser always fails and the error that I get is "Error: The operation completed successfully." Is there a module that I can use to logon to another server without authenticating to a domain and instead use the remote servers local user account?


-----
Of all the things I've lost in my life, its my mind I miss the most.

Title edit by tye


In reply to Remote Win32 User Authentication by AcidHawk

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.