use Win32::TieRegistry(Delimiter=>"/",ArrayValues=>0);
%osname=("1381","Windows NT 4.0", "2195","Windows 2000", "3790","Windows 2003", "6002","Windows 2008", "9999","Server Unreachable");
open SERVERS,"servers.txt"; open OUT,">osversions.txt";
while(<SERVERS>){ chomp($server=$_); $server=~s/\s+//g; if(!($buildnum = $Registry->{"//$server/LMachine/Software/microsoft/Windows NT/CurrentVersion//CurrentBuildNumber"})){ $buildnum="9999"; } if(!($sp = $Registry->{"//$server/LMachine/Software/microsoft/Windows NT/CurrentVersion//CSDVersion"})){ $sp="Service Pack 0"; } print"$server \t$osname{$buildnum}\t$sp\n"; print OUT "$server\t$osname{$buildnum}\t$sp\n"; } close OUT;
By the way, the current build number is just that, a number. So the script maps these numbers to friendly OS version names (2195 = Windows 2000, 3790=Windows 2003, etc). As new versions of Windows come out, launch regedit, look at the build number, and add it to the list.
There's a lot more to accessing the registry than this script demonstrates. For one thing, we're reading string values. There's other registry data types like dwords, multi's and binaries that require some further demonstration, but I'll get to that in another post.
No comments:
Post a Comment