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

I've been scanning for a way to have a perl script that is running as a service (or running in any fashion) to log on to a windows server as either a local account or a domain account(local preferred).

All the functions I find around Win32:: seem to expect that you are already logged in as a user with the proper priveledges. I ran across Win32::AdminMisc which has a LogonAsUser() which doesn't seem to work but only returns false with no descriptive error.

My need is for perl, running as a service, to wake up periodically and check services running on other server and perhaps restart them if needed. Anyone have any advice on this?

Replies are listed 'Best First'.
Re: How to log on to windows server?
by pKai (Priest) on Feb 03, 2006 at 23:22 UTC

    Typically the remote server is attached (automatically) with the account the service is running on its own machine.

    Alternatively you can connect with a different account. A command line to do so would be

    net use \\remote /user:<user> <password>

    <user> is either a domain account (aka domain\account) or a local account (from the remote machine).

    <password> (for <user>) is optional, if it is identical to the pw of the current account, the process runs under.

    The issued "net use" must be the first command of your service that contacts the remote machine, because that first encounter fixes the credentials for the interaction.

      Yeah, I was trying to use a module function but I may be stuck with using the command line. I'll need to figure out if it's even possible from a service that runs as a local_system_account. I'll post back my results....
        For running under SYSTEM, you need null sessions to attach to network resources. For a nice introdution and discussion of null sessions see this paper, also naming this restriction on page 5.