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

Wise monks, I would like to use the Win32 API, but execute a function on a local domain
(for which I have admin permissions).
For example:

print Win32::GetOSName()

Normally I get the name of my own OS.
How can I get the OS name of domain "foo"?

Replies are listed 'Best First'.
Re: Win32 functions on other domains
by meetraz (Hermit) on Mar 10, 2003 at 16:40 UTC
    Well, domains don't really have an OS name. You can have several different types of computers - with different OSes - running in the same domain.

    Each individual computer does have an OS name that you can retreive - and that's what Win32::GetOSName() does - it retreives the OS name of the local machine.

    To get the OS Name of a remote machine, there are several ways. One way is to use Win32::TieRegistry to query the registry of the remote machine. Another is to use Win32::OLE together with WMI. Here's an example:

    use strict; use Win32::OLE qw( in ); my $Computer = 'myworkstation'; my $WMIServices = Win32::OLE->GetObject( "winmgmts:{impersonationLevel=impersonate}//$Computer" ) || die ("Could not connect to $Computer"); my $OSCollection = $WMIServices->InstancesOf( "Win32_OperatingSystem" +); foreach my $OS (in $OSCollection ) { print "OS = $OS->{Caption}\n"; }
Re: Win32 functions on other domains
by jand (Friar) on Mar 10, 2003 at 16:42 UTC
Re: Win32 functions on other domains
by Marza (Vicar) on Mar 10, 2003 at 19:27 UTC

    As the others mention you have to write something to get a list of machines in the domain and then go about getting the OS

    Take a look at MachineInfo

    It will take care of NT and W2K. There are problems with XP and it does not do Win9x.

    One thing to keep in mind with the registry approach is the fact the OS is defined by a number. (IE 4.0, 5.0, 5.1) but that is easy to work around.

    If you want code for a domain machine list and loop, take a look at Domain Disk space check. It's a little script I wrote. You can get an idea from what I did to loop through the machines in the domain.