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
'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..?net use \\server\ips$ /user:me pass
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?
Title edit by tye
In reply to Remote Win32 User Authentication by AcidHawk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |