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

Using ActivePerl 5.22, how would I get the machine name of the NT box it is running on? Depending on the machine name, I want the script to do different things. Thanks!

Replies are listed 'Best First'.
Re: Retrieving an NT machine name?
by gaggio (Friar) on Jul 18, 2000 at 01:05 UTC
    Use this:

    use Win32::AdminMisc; my $machinename = Win32::AdminMisc::GetComputerName();
      Where do I find that module? Nothing with "admin" or "misc" in the name can be found at http://www.activestate.com/PPMPackages/zips/6xx-builds-only/.

        The module, as well as very nice other Win32 modules, can be found at http://www.roth.net/perl/

        You just need to know how to use a search engine to find this link, by the way.

        On the Web, Google is your friend!
        It's true that win32::adminmisc doesn't show up in AS's PPM repository, but for some reason it's installed as a core module. I have it on my win9x and NT boxes, without ever installing it from PPM. Odd, eh?
Re: Retrieving an NT machine name?
by lhoward (Vicar) on Jul 18, 2000 at 00:34 UTC
    the Sys::Hostname module that comes with perl should return the hostname regardless of which OS you are running on.
      Or for strictly Windows machines (don't know of any other's that have this particular environment variable) you can use:
      $ENV{COMPUTERNAME}
      HTH...

      #!/home/bbq/bin/perl
      # Trust no1!