Determine version of Microsoft Windows using perl?

纵饮孤独 提交于 2019-12-25 07:38:03

问题


I am creating a small perl script on Windows. I want to determine the version of Windows i.e. XP, Vista, 7, 8, etc. How can I get this information? Thank You.

UPDATE: I want to know the Version of Windows on which the script is running! Please add some code on how to use the API's as I am a beginner & dont know much about perl.


回答1:


Try Win32:

#!/usr/bin/env perl

use 5.014;
use strict;
use warnings;

use Win32;

say Win32::GetOSDisplayName();
say for Win32::GetOSName();
say for Win32::GetOSVersion();

If that is not sufficient, you can call GetVersionEx via Win32::API.




回答2:


From http://perldoc.perl.org/perlvar.html

$^O

The name of the operating system under which this copy of Perl was built, as determined during the configuration process. For examples see PLATFORMS in perlport.

The value is identical to $Config{'osname'} . See also Config and the -V command-line switch documented in perlrun.

In Windows platforms, $^O is not very helpful: since it is always MSWin32 , it doesn't tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see Win32 and perlport) to distinguish between the variants.



来源:https://stackoverflow.com/questions/16189216/determine-version-of-microsoft-windows-using-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!