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

Greetings O’Holy Ones

What is the one and most accurate why to determine the Operating System of a remote M$Windows based server. The reason is; I will be removing or adding Permissions to shared drives resident on remote servers. Depending on the type of OS will determine whether or not to invoke a folder/sub folder recursion routine. Therefore I need to absolutely make sure the type of the OS.
Commands that approximate the OS will not help me -like referring to all Windows flavours as mswin32 – I need to know explicitly and exactly if its Windows NT 4, where Win32::Perms->Recurs(1) will not work then folder/sub folder recursion is required, or if its a Windows2000 based then Win32::Perms will do the recursion for me. I have tried printing $^O and %ENV on my local Windows XP machine, the values MSWin32 and Windows_NT inaccurately were returned respectively

Thanking You

edited by ybiC: retitle from "Determining the exact type of OS of a remote server." for searchability

  • Comment on Determine exact OS of remote win32 server

Replies are listed 'Best First'.
Re: Determine exact OS of remote win32 server
by Kanji (Parson) on Aug 18, 2003 at 19:40 UTC
Re: Determine exact OS of remote win32 server
by Mr. Muskrat (Canon) on Aug 18, 2003 at 20:17 UTC

    I'd use Win32::TieRegistry.

    #!/perl/bin/perl use strict; use warnings; use Win32::TieRegistry; my $host = shift || ''; my $hklm = $Registry->Connect($host, "HKEY_LOCAL_MACHINE", { Access => + 'KEY_READ' } ) or die $^E; my $info = $hklm->{"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"}; my $ver = $info->{"CurrentVersion"}; my $sp = $info->{"CSDVersion"}; my $os = $hklm->{"SYSTEM\\CurrentControlSet\\Control\\ProductOptions\\ +ProductType"}; print "Remote OS: $os, Version: $ver, $sp\n";

    NOTE: This will not work for Win9x or WinME.

    Update: You could also use Win32::MachineInfo.

      Thanks for this,....I ran this bit of code on my test pc which is an XP and I got this in return
      Remote OS: WinNT, Version: 5.1, Service Pack 1
      So I take it that version:5.1 means Windows XP!. Athough I won't be interested in XP once I run the script on the LAN. But I thought that the output be more specific than this...Anyway, I will only find out tomorrow.....Good night and God bless...
      Win32::MachineInfo....Now thats a baby. Thanks a lot for this one.

      Cheers.
Determine exact OS of remote win32 server
by Anonymous Monk on Aug 18, 2003 at 19:32 UTC
    How many "flavors" of Windows are there now?
  • Windows 95
  • Window 3.1
  • Windows NT
  • Windows XP
  • Windows 2000
    I am sure I left a couple out. You have my I sympathies.
      Apologies ...I haven't been clear....And many thanks for your sympathy, believe me I deserve it.

      I am, only interested in Windows NT version 4 server and Windows 2000 server. It’s never likely to be a workstation, and all the remaining flavours can be eliminated. This will help me to determine whether I should recurs into folders and sub folder while removing permission (ACL), or whether I should just instruct Perl (...Win32::Perms) to recurs while modifying the ACLs, that's basically it. It is just my way of enforcing inheretance of permission on folders and sub folders. I have no problems with modifying the ACLs regardless of the OS, I basically instruct the script to recurs in any case. But knowing exactly (beyond any doubt) the type of the OS will make things easier and the code more elegant....

      Thanks for listening again.