use Win32::API; ############################################################## # Add cleanup before using this in production Win32::API->Import('advapi32', 'int LogonUser( LPTSTR lpszUsername, LPTSTR lpszDomain, LPTSTR, lpszPassword, DWORD dwLogon, DWORD dwLogonProvider, PHANDLE phToken )' ) or die "Win32::API->import for LogonUser failed: $^E"; my $ph = ' ' x 4; # Required, but we do not use it ############################################################# #### if ( $linkList->[$x] =~ [pattern of the server that needs authentication] ) { print("You're in the LogonUser block!"); LogonUser( '[username goes here]', '', '', 0x000003, 0x000000, $ph ) or die $^E; # ImpersonateLoggedOnUser($ph); }