xref: /openbsd/gnu/usr.bin/perl/cpan/Win32/Win32.pm (revision d89ec533)
1package Win32;
2
3# BEGIN {
4    use strict;
5    use vars qw|$VERSION $XS_VERSION @ISA @EXPORT @EXPORT_OK|;
6
7    require Exporter;
8    require DynaLoader;
9
10    @ISA = qw|Exporter DynaLoader|;
11    $VERSION = '0.53';
12    $XS_VERSION = $VERSION;
13    $VERSION = eval $VERSION;
14
15    @EXPORT = qw(
16	NULL
17	WIN31_CLASS
18	OWNER_SECURITY_INFORMATION
19	GROUP_SECURITY_INFORMATION
20	DACL_SECURITY_INFORMATION
21	SACL_SECURITY_INFORMATION
22	MB_ICONHAND
23	MB_ICONQUESTION
24	MB_ICONEXCLAMATION
25	MB_ICONASTERISK
26	MB_ICONWARNING
27	MB_ICONERROR
28	MB_ICONINFORMATION
29	MB_ICONSTOP
30    );
31    @EXPORT_OK = qw(
32        GetOSName
33        SW_HIDE
34        SW_SHOWNORMAL
35        SW_SHOWMINIMIZED
36        SW_SHOWMAXIMIZED
37        SW_SHOWNOACTIVATE
38
39        CSIDL_DESKTOP
40        CSIDL_PROGRAMS
41        CSIDL_PERSONAL
42        CSIDL_FAVORITES
43        CSIDL_STARTUP
44        CSIDL_RECENT
45        CSIDL_SENDTO
46        CSIDL_STARTMENU
47        CSIDL_MYMUSIC
48        CSIDL_MYVIDEO
49        CSIDL_DESKTOPDIRECTORY
50        CSIDL_NETHOOD
51        CSIDL_FONTS
52        CSIDL_TEMPLATES
53        CSIDL_COMMON_STARTMENU
54        CSIDL_COMMON_PROGRAMS
55        CSIDL_COMMON_STARTUP
56        CSIDL_COMMON_DESKTOPDIRECTORY
57        CSIDL_APPDATA
58        CSIDL_PRINTHOOD
59        CSIDL_LOCAL_APPDATA
60        CSIDL_COMMON_FAVORITES
61        CSIDL_INTERNET_CACHE
62        CSIDL_COOKIES
63        CSIDL_HISTORY
64        CSIDL_COMMON_APPDATA
65        CSIDL_WINDOWS
66        CSIDL_SYSTEM
67        CSIDL_PROGRAM_FILES
68        CSIDL_MYPICTURES
69        CSIDL_PROFILE
70        CSIDL_PROGRAM_FILES_COMMON
71        CSIDL_COMMON_TEMPLATES
72        CSIDL_COMMON_DOCUMENTS
73        CSIDL_COMMON_ADMINTOOLS
74        CSIDL_ADMINTOOLS
75        CSIDL_COMMON_MUSIC
76        CSIDL_COMMON_PICTURES
77        CSIDL_COMMON_VIDEO
78        CSIDL_RESOURCES
79        CSIDL_RESOURCES_LOCALIZED
80        CSIDL_CDBURN_AREA
81    );
82# }
83
84# We won't bother with the constant stuff, too much of a hassle.  Just hard
85# code it here.
86
87sub NULL 				{ 0 }
88sub WIN31_CLASS 			{ &NULL }
89
90sub OWNER_SECURITY_INFORMATION		{ 0x00000001 }
91sub GROUP_SECURITY_INFORMATION		{ 0x00000002 }
92sub DACL_SECURITY_INFORMATION		{ 0x00000004 }
93sub SACL_SECURITY_INFORMATION		{ 0x00000008 }
94
95sub MB_ICONHAND				{ 0x00000010 }
96sub MB_ICONQUESTION			{ 0x00000020 }
97sub MB_ICONEXCLAMATION			{ 0x00000030 }
98sub MB_ICONASTERISK			{ 0x00000040 }
99sub MB_ICONWARNING			{ 0x00000030 }
100sub MB_ICONERROR			{ 0x00000010 }
101sub MB_ICONINFORMATION			{ 0x00000040 }
102sub MB_ICONSTOP				{ 0x00000010 }
103
104#
105# Newly added constants.  These have an empty prototype, unlike the
106# the ones above, which aren't prototyped for compatibility reasons.
107#
108sub SW_HIDE           ()		{ 0 }
109sub SW_SHOWNORMAL     ()		{ 1 }
110sub SW_SHOWMINIMIZED  ()		{ 2 }
111sub SW_SHOWMAXIMIZED  ()		{ 3 }
112sub SW_SHOWNOACTIVATE ()		{ 4 }
113
114sub CSIDL_DESKTOP              ()       { 0x0000 }     # <desktop>
115sub CSIDL_PROGRAMS             ()       { 0x0002 }     # Start Menu\Programs
116sub CSIDL_PERSONAL             ()       { 0x0005 }     # "My Documents" folder
117sub CSIDL_FAVORITES            ()       { 0x0006 }     # <user name>\Favorites
118sub CSIDL_STARTUP              ()       { 0x0007 }     # Start Menu\Programs\Startup
119sub CSIDL_RECENT               ()       { 0x0008 }     # <user name>\Recent
120sub CSIDL_SENDTO               ()       { 0x0009 }     # <user name>\SendTo
121sub CSIDL_STARTMENU            ()       { 0x000B }     # <user name>\Start Menu
122sub CSIDL_MYMUSIC              ()       { 0x000D }     # "My Music" folder
123sub CSIDL_MYVIDEO              ()       { 0x000E }     # "My Videos" folder
124sub CSIDL_DESKTOPDIRECTORY     ()       { 0x0010 }     # <user name>\Desktop
125sub CSIDL_NETHOOD              ()       { 0x0013 }     # <user name>\nethood
126sub CSIDL_FONTS                ()       { 0x0014 }     # windows\fonts
127sub CSIDL_TEMPLATES            ()       { 0x0015 }
128sub CSIDL_COMMON_STARTMENU     ()       { 0x0016 }     # All Users\Start Menu
129sub CSIDL_COMMON_PROGRAMS      ()       { 0x0017 }     # All Users\Start Menu\Programs
130sub CSIDL_COMMON_STARTUP       ()       { 0x0018 }     # All Users\Startup
131sub CSIDL_COMMON_DESKTOPDIRECTORY ()    { 0x0019 }     # All Users\Desktop
132sub CSIDL_APPDATA              ()       { 0x001A }     # Application Data, new for NT4
133sub CSIDL_PRINTHOOD            ()       { 0x001B }     # <user name>\PrintHood
134sub CSIDL_LOCAL_APPDATA        ()       { 0x001C }     # non roaming, user\Local Settings\Application Data
135sub CSIDL_COMMON_FAVORITES     ()       { 0x001F }
136sub CSIDL_INTERNET_CACHE       ()       { 0x0020 }
137sub CSIDL_COOKIES              ()       { 0x0021 }
138sub CSIDL_HISTORY              ()       { 0x0022 }
139sub CSIDL_COMMON_APPDATA       ()       { 0x0023 }     # All Users\Application Data
140sub CSIDL_WINDOWS              ()       { 0x0024 }     # GetWindowsDirectory()
141sub CSIDL_SYSTEM               ()       { 0x0025 }     # GetSystemDirectory()
142sub CSIDL_PROGRAM_FILES        ()       { 0x0026 }     # C:\Program Files
143sub CSIDL_MYPICTURES           ()       { 0x0027 }     # "My Pictures", new for Win2K
144sub CSIDL_PROFILE              ()       { 0x0028 }     # USERPROFILE
145sub CSIDL_PROGRAM_FILES_COMMON ()       { 0x002B }     # C:\Program Files\Common
146sub CSIDL_COMMON_TEMPLATES     ()       { 0x002D }     # All Users\Templates
147sub CSIDL_COMMON_DOCUMENTS     ()       { 0x002E }     # All Users\Documents
148sub CSIDL_COMMON_ADMINTOOLS    ()       { 0x002F }     # All Users\Start Menu\Programs\Administrative Tools
149sub CSIDL_ADMINTOOLS           ()       { 0x0030 }     # <user name>\Start Menu\Programs\Administrative Tools
150sub CSIDL_COMMON_MUSIC         ()       { 0x0035 }     # All Users\My Music
151sub CSIDL_COMMON_PICTURES      ()       { 0x0036 }     # All Users\My Pictures
152sub CSIDL_COMMON_VIDEO         ()       { 0x0037 }     # All Users\My Video
153sub CSIDL_RESOURCES            ()       { 0x0038 }     # %windir%\Resources\, For theme and other windows resources.
154sub CSIDL_RESOURCES_LOCALIZED  ()       { 0x0039 }     # %windir%\Resources\<LangID>, for theme and other windows specific resources.
155sub CSIDL_CDBURN_AREA          ()       { 0x003B }     # <user name>\Local Settings\Application Data\Microsoft\CD Burning
156
157sub VER_NT_DOMAIN_CONTROLLER () { 0x0000002 } # The system is a domain controller and the operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
158sub VER_NT_SERVER () { 0x0000003 } # The operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
159# Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.
160sub VER_NT_WORKSTATION () { 0x0000001 } # The operating system is Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
161
162
163sub VER_SUITE_BACKOFFICE               () { 0x00000004 } # Microsoft BackOffice components are installed.
164sub VER_SUITE_BLADE                    () { 0x00000400 } # Windows Server 2003, Web Edition is installed.
165sub VER_SUITE_COMPUTE_SERVER           () { 0x00004000 } # Windows Server 2003, Compute Cluster Edition is installed.
166sub VER_SUITE_DATACENTER               () { 0x00000080 } # Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed.
167sub VER_SUITE_ENTERPRISE               () { 0x00000002 } # Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed. Refer to the Remarks section for more information about this bit flag.
168sub VER_SUITE_EMBEDDEDNT               () { 0x00000040 } # Windows XP Embedded is installed.
169sub VER_SUITE_PERSONAL                 () { 0x00000200 } # Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed.
170sub VER_SUITE_SINGLEUSERTS             () { 0x00000100 } # Remote Desktop is supported, but only one interactive session is supported. This value is set unless the system is running in application server mode.
171sub VER_SUITE_SMALLBUSINESS            () { 0x00000001 } # Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. Refer to the Remarks section for more information about this bit flag.
172sub VER_SUITE_SMALLBUSINESS_RESTRICTED () { 0x00000020 } # Microsoft Small Business Server is installed with the restrictive client license in force. Refer to the Remarks section for more information about this bit flag.
173sub VER_SUITE_STORAGE_SERVER           () { 0x00002000 } # Windows Storage Server 2003 R2 or Windows Storage Server 2003 is installed.
174sub VER_SUITE_TERMINAL                 () { 0x00000010 } # Terminal Services is installed. This value is always set.
175# If VER_SUITE_TERMINAL is set but VER_SUITE_SINGLEUSERTS is not set, the system is running in application server mode.
176sub VER_SUITE_WH_SERVER                () { 0x00008000 } # Windows Home Server is installed.
177
178
179sub SM_TABLETPC                ()       { 86 }
180sub SM_MEDIACENTER             ()       { 87 }
181sub SM_STARTER                 ()       { 88 }
182sub SM_SERVERR2                ()       { 89 }
183
184sub PRODUCT_UNDEFINED                        () { 0x000 } # An unknown product
185sub PRODUCT_ULTIMATE                         () { 0x001 } # Ultimate
186sub PRODUCT_HOME_BASIC                       () { 0x002 } # Home Basic
187sub PRODUCT_HOME_PREMIUM                     () { 0x003 } # Home Premium
188sub PRODUCT_ENTERPRISE                       () { 0x004 } # Enterprise
189sub PRODUCT_HOME_BASIC_N                     () { 0x005 } # Home Basic N
190sub PRODUCT_BUSINESS                         () { 0x006 } # Business
191sub PRODUCT_STANDARD_SERVER                  () { 0x007 } # Server Standard (full installation)
192sub PRODUCT_DATACENTER_SERVER                () { 0x008 } # Server Datacenter (full installation)
193sub PRODUCT_SMALLBUSINESS_SERVER             () { 0x009 } # Windows Small Business Server
194sub PRODUCT_ENTERPRISE_SERVER                () { 0x00A } # Server Enterprise (full installation)
195sub PRODUCT_STARTER                          () { 0x00B } # Starter
196sub PRODUCT_DATACENTER_SERVER_CORE           () { 0x00C } # Server Datacenter (core installation)
197sub PRODUCT_STANDARD_SERVER_CORE             () { 0x00D } # Server Standard (core installation)
198sub PRODUCT_ENTERPRISE_SERVER_CORE           () { 0x00E } # Server Enterprise (core installation)
199sub PRODUCT_ENTERPRISE_SERVER_IA64           () { 0x00F } # Server Enterprise for Itanium-based Systems
200sub PRODUCT_BUSINESS_N                       () { 0x010 } # Business N
201sub PRODUCT_WEB_SERVER                       () { 0x011 } # Web Server (full installation)
202sub PRODUCT_CLUSTER_SERVER                   () { 0x012 } # HPC Edition
203sub PRODUCT_HOME_SERVER                      () { 0x013 } # Home Server Edition
204sub PRODUCT_STORAGE_EXPRESS_SERVER           () { 0x014 } # Storage Server Express
205sub PRODUCT_STORAGE_STANDARD_SERVER          () { 0x015 } # Storage Server Standard
206sub PRODUCT_STORAGE_WORKGROUP_SERVER         () { 0x016 } # Storage Server Workgroup
207sub PRODUCT_STORAGE_ENTERPRISE_SERVER        () { 0x017 } # Storage Server Enterprise
208sub PRODUCT_SERVER_FOR_SMALLBUSINESS         () { 0x018 } # Windows Server 2008 for Windows Essential Server Solutions
209sub PRODUCT_SMALLBUSINESS_SERVER_PREMIUM     () { 0x019 } # Windows Small Business Server Premium
210sub PRODUCT_HOME_PREMIUM_N                   () { 0x01A } # Home Premium N
211sub PRODUCT_ENTERPRISE_N                     () { 0x01B } # Enterprise N
212sub PRODUCT_ULTIMATE_N                       () { 0x01C } # Ultimate N
213sub PRODUCT_WEB_SERVER_CORE                  () { 0x01D } # Web Server (core installation)
214sub PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT () { 0x01E } # Windows Essential Business Server Management Server
215sub PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY   () { 0x01F } # Windows Essential Business Server Security Server
216sub PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING  () { 0x020 } # Windows Essential Business Server Messaging Server
217sub PRODUCT_SERVER_FOUNDATION                () { 0x021 } # Server Foundation
218#define PRODUCT_HOME_PREMIUM_SERVER                 0x00000022
219sub PRODUCT_SERVER_FOR_SMALLBUSINESS_V       () { 0x023 } # Windows Server 2008 without Hyper-V for Windows Essential Server Solutions
220sub PRODUCT_STANDARD_SERVER_V                () { 0x024 } # Server Standard without Hyper-V (full installation)
221sub PRODUCT_DATACENTER_SERVER_V              () { 0x025 } # Server Datacenter without Hyper-V (full installation)
222sub PRODUCT_ENTERPRISE_SERVER_V              () { 0x026 } # Server Enterprise without Hyper-V (full installation)
223sub PRODUCT_DATACENTER_SERVER_CORE_V         () { 0x027 } # Server Datacenter without Hyper-V (core installation)
224sub PRODUCT_STANDARD_SERVER_CORE_V           () { 0x028 } # Server Standard without Hyper-V (core installation)
225sub PRODUCT_ENTERPRISE_SERVER_CORE_V         () { 0x029 } # Server Enterprise without Hyper-V (core installation)
226sub PRODUCT_HYPERV                           () { 0x02A } # Microsoft Hyper-V Server
227#define PRODUCT_STORAGE_EXPRESS_SERVER_CORE         0x0000002B
228#define PRODUCT_STORAGE_STANDARD_SERVER_CORE        0x0000002C
229#define PRODUCT_STORAGE_WORKGROUP_SERVER_CORE       0x0000002D
230#define PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE      0x0000002E
231sub PRODUCT_STARTER_N                        () { 0x02F } # Starter N
232sub PRODUCT_PROFESSIONAL                     () { 0x030 } # Professional
233sub PRODUCT_PROFESSIONAL_N                   () { 0x031 } # Professional N
234#define PRODUCT_SB_SOLUTION_SERVER                  0x00000032
235#define PRODUCT_SERVER_FOR_SB_SOLUTIONS             0x00000033
236#define PRODUCT_STANDARD_SERVER_SOLUTIONS           0x00000034
237#define PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE      0x00000035
238#define PRODUCT_SB_SOLUTION_SERVER_EM               0x00000036
239#define PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM          0x00000037
240#define PRODUCT_SOLUTION_EMBEDDEDSERVER             0x00000038
241#define PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE        0x00000039
242#define PRODUCT_PROFESSIONAL_EMBEDDED               0x0000003A
243#define PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT       0x0000003B
244#define PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL       0x0000003C
245#define PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC    0x0000003D
246#define PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC    0x0000003E
247#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE   0x0000003F
248#define PRODUCT_CLUSTER_SERVER_V                    0x00000040
249#define PRODUCT_EMBEDDED                            0x00000041
250sub PRODUCT_STARTER_E                        () { 0x042 } # Starter E
251sub PRODUCT_HOME_BASIC_E                     () { 0x043 } # Home Basic E
252sub PRODUCT_HOME_PREMIUM_E                   () { 0x044 } # Home Premium E
253sub PRODUCT_PROFESSIONAL_E                   () { 0x045 } # Professional E
254sub PRODUCT_ENTERPRISE_E                     () { 0x046 } # Enterprise E
255sub PRODUCT_ULTIMATE_E                       () { 0x047 } # Ultimate E
256#define PRODUCT_ENTERPRISE_EVALUATION               0x00000048
257#define PRODUCT_MULTIPOINT_STANDARD_SERVER          0x0000004C
258#define PRODUCT_MULTIPOINT_PREMIUM_SERVER           0x0000004D
259#define PRODUCT_STANDARD_EVALUATION_SERVER          0x0000004F
260#define PRODUCT_DATACENTER_EVALUATION_SERVER        0x00000050
261#define PRODUCT_ENTERPRISE_N_EVALUATION             0x00000054
262#define PRODUCT_EMBEDDED_AUTOMOTIVE                 0x00000055
263#define PRODUCT_EMBEDDED_INDUSTRY_A                 0x00000056
264#define PRODUCT_THINPC                              0x00000057
265#define PRODUCT_EMBEDDED_A                          0x00000058
266#define PRODUCT_EMBEDDED_INDUSTRY                   0x00000059
267#define PRODUCT_EMBEDDED_E                          0x0000005A
268#define PRODUCT_EMBEDDED_INDUSTRY_E                 0x0000005B
269#define PRODUCT_EMBEDDED_INDUSTRY_A_E               0x0000005C
270#define PRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER 0x0000005F
271#define PRODUCT_STORAGE_STANDARD_EVALUATION_SERVER  0x00000060
272#define PRODUCT_CORE_ARM                            0x00000061
273sub PRODUCT_CORE_N                           () { 0x62 } # Windows 10 Home N
274sub PRODUCT_CORE_COUNTRYSPECIFIC             () { 0x63 } # Windows 10 Home China
275sub PRODUCT_CORE_SINGLELANGUAGE              () { 0x64 } # Windows 10 Home Single Language
276sub PRODUCT_CORE                             () { 0x65 } # Windows 10 Home
277#define PRODUCT_PROFESSIONAL_WMC                    0x00000067
278#define PRODUCT_MOBILE_CORE                         0x00000068
279#define PRODUCT_EMBEDDED_INDUSTRY_EVAL              0x00000069
280#define PRODUCT_EMBEDDED_INDUSTRY_E_EVAL            0x0000006A
281#define PRODUCT_EMBEDDED_EVAL                       0x0000006B
282#define PRODUCT_EMBEDDED_E_EVAL                     0x0000006C
283#define PRODUCT_NANO_SERVER                         0x0000006D
284#define PRODUCT_CLOUD_STORAGE_SERVER                0x0000006E
285#define PRODUCT_CORE_CONNECTED                      0x0000006F
286#define PRODUCT_PROFESSIONAL_STUDENT                0x00000070
287#define PRODUCT_CORE_CONNECTED_N                    0x00000071
288#define PRODUCT_PROFESSIONAL_STUDENT_N              0x00000072
289#define PRODUCT_CORE_CONNECTED_SINGLELANGUAGE       0x00000073
290#define PRODUCT_CORE_CONNECTED_COUNTRYSPECIFIC      0x00000074
291#define PRODUCT_CONNECTED_CAR                       0x00000075
292#define PRODUCT_INDUSTRY_HANDHELD                   0x00000076
293#define PRODUCT_PPI_PRO                             0x00000077
294#define PRODUCT_ARM64_SERVER                        0x00000078
295sub PRODUCT_EDUCATION                        () { 0x79 } # Windows 10 Education
296sub PRODUCT_EDUCATION_N                      () { 0x7A } # Windows 10 Education N
297#define PRODUCT_IOTUAP                              0x0000007B
298#define PRODUCT_CLOUD_HOST_INFRASTRUCTURE_SERVER    0x0000007C
299#define PRODUCT_ENTERPRISE_S                        0x0000007D
300#define PRODUCT_ENTERPRISE_S_N                      0x0000007E
301#define PRODUCT_PROFESSIONAL_S                      0x0000007F
302#define PRODUCT_PROFESSIONAL_S_N                    0x00000080
303#define PRODUCT_ENTERPRISE_S_EVALUATION             0x00000081
304#define PRODUCT_ENTERPRISE_S_N_EVALUATION           0x00000082
305
306sub PRODUCT_UNLICENSED                       () { 0xABCDABCD } # product has not been activated and is no longer in the grace period
307
308sub PROCESSOR_ARCHITECTURE_AMD64   ()   { 9 }      # x64 (AMD or Intel)
309sub PROCESSOR_ARCHITECTURE_IA64    ()   { 6 }      # Intel Itanium Processor Family (IPF)
310sub PROCESSOR_ARCHITECTURE_INTEL   ()   { 0 }      # x86
311sub PROCESSOR_ARCHITECTURE_UNKNOWN ()   { 0xffff } # Unknown architecture.
312
313sub _GetProcessorArchitecture {
314    my $arch = {
315	 386 => PROCESSOR_ARCHITECTURE_INTEL,
316	 486 => PROCESSOR_ARCHITECTURE_INTEL,
317	 586 => PROCESSOR_ARCHITECTURE_INTEL,
318	2200 => PROCESSOR_ARCHITECTURE_IA64,
319	8664 => PROCESSOR_ARCHITECTURE_AMD64,
320    }->{Win32::GetChipName()};
321    return defined($arch) ? $arch : PROCESSOR_ARCHITECTURE_UNKNOWN;
322}
323
324### This method is just a simple interface into GetOSVersion().  More
325### specific or demanding situations should use that instead.
326
327my ($cached_os, $cached_desc);
328
329sub GetOSName {
330    unless (defined $cached_os) {
331	my($desc, $major, $minor, $build, $id, undef, undef, $suitemask, $producttype)
332	    = Win32::GetOSVersion();
333	my $arch = _GetProcessorArchitecture();
334	my $productinfo = Win32::GetProductInfo(6, 0, 0, 0);
335	($cached_os, $cached_desc) = _GetOSName($desc, $major, $minor, $build, $id,
336						$suitemask, $producttype, $productinfo, $arch);
337    }
338    return wantarray ? ($cached_os, $cached_desc) : $cached_os;
339}
340
341sub GetOSDisplayName {
342    # Calling GetOSDisplayName() with arguments is for the test suite only!
343    my($name,$desc) = @_ ? @_ : GetOSName();
344    $name =~ s/^Win//;
345    if ($desc =~ /^Windows Home Server\b/ || $desc =~ /^Windows XP Professional x64 Edition\b/) {
346	($name, $desc) = ($desc, "");
347    }
348    elsif ($desc =~ s/\s*(Windows (.*) Server( \d+)?)//) {
349	$name = "$1 $name";
350	$desc =~ s/^\s+//;
351    }
352    else {
353	for ($name) {
354	    s/^/Windows / unless /^Win32s$/;
355	    s/\/.Net//;
356	    s/NT(\d)/NT $1/;
357	    if ($desc =~ s/\s*(HPC|Small Business|Web) Server//) {
358		my $name = $1;
359		$desc =~ s/^\s*//;
360		s/(200.)/$name Server $1/;
361	    }
362	    s/^Windows (20(03|08|12))/Windows Server $1/;
363	}
364    }
365    $name .= " $desc" if length $desc;
366    return $name;
367}
368
369sub _GetSystemMetrics {
370    my($index,$metrics) = @_;
371    return Win32::GetSystemMetrics($index) unless ref $metrics;
372    return $metrics->{$index} if ref $metrics eq "HASH" && defined $metrics->{$index};
373    return 1 if ref $metrics eq "ARRAY" && grep $_ == $index, @$metrics;
374    return 0;
375}
376
377sub _GetOSName {
378    # The $metrics argument only exists for the benefit of t/GetOSName.t
379    my($csd, $major, $minor, $build, $id, $suitemask, $producttype, $productinfo, $arch, $metrics) = @_;
380
381    my($os,@tags);
382    my $desc = "";
383    if ($id == 0) {
384	$os = "Win32s";
385    }
386    elsif ($id == 1) {
387	if ($minor == 0) {
388	    $os = "95";
389	}
390	elsif ($minor == 10) {
391	    $os = "98";
392	}
393	elsif ($minor == 90) {
394	    $os = "Me";
395	}
396    }
397    elsif ($id == 2) {
398	if ($major == 3) {
399	    $os = "NT3.51";
400	}
401	elsif ($major == 4) {
402	    $os = "NT4";
403	}
404	elsif ($major == 5) {
405	    if ($minor == 0) {
406		$os = "2000";
407		if ($producttype == VER_NT_WORKSTATION) {
408		    $desc = "Professional";
409		}
410		else {
411		    if ($suitemask & VER_SUITE_DATACENTER) {
412			$desc = "Datacenter Server";
413		    }
414		    elsif ($suitemask & VER_SUITE_ENTERPRISE) {
415			$desc = "Advanced Server";
416		    }
417		    elsif ($suitemask & VER_SUITE_SMALLBUSINESS_RESTRICTED) {
418			$desc = "Small Business Server";
419		    }
420		    else {
421			$desc = "Server";
422		    }
423		}
424		# XXX ignoring "Windows 2000 Advanced Server Limited Edition" for Itanium
425		# XXX and "Windows 2000 Datacenter Server Limited Edition" for Itanium
426	    }
427	    elsif ($minor == 1) {
428		$os = "XP/.Net";
429		if (_GetSystemMetrics(SM_MEDIACENTER, $metrics)) {
430		    $desc = "Media Center Edition";
431		}
432		elsif (_GetSystemMetrics(SM_TABLETPC, $metrics)) {
433		    # Tablet PC Edition is based on XP Pro
434		    $desc = "Tablet PC Edition";
435		}
436		elsif (_GetSystemMetrics(SM_STARTER, $metrics)) {
437		    $desc = "Starter Edition";
438		}
439		elsif ($suitemask & VER_SUITE_PERSONAL) {
440		    $desc = "Home Edition";
441		}
442		else {
443		    $desc = "Professional";
444		}
445		# XXX ignoring all Windows XP Embedded and Fundamentals versions
446	    }
447	    elsif ($minor == 2) {
448		$os = "2003";
449
450		if (_GetSystemMetrics(SM_SERVERR2, $metrics)) {
451		    # XXX R2 was released for all x86 and x64 versions,
452		    # XXX but only Enterprise Edition for Itanium.
453		    $desc = "R2";
454		}
455
456		if ($suitemask == VER_SUITE_STORAGE_SERVER) {
457		    $desc .= " Windows Storage Server";
458		}
459		elsif ($suitemask == VER_SUITE_WH_SERVER) {
460		    $desc .= " Windows Home Server";
461		}
462		elsif ($producttype == VER_NT_WORKSTATION && $arch == PROCESSOR_ARCHITECTURE_AMD64) {
463		    $desc .= " Windows XP Professional x64 Edition";
464		}
465
466		# Test for the server type.
467		if ($producttype != VER_NT_WORKSTATION) {
468		    if ($arch == PROCESSOR_ARCHITECTURE_IA64) {
469			if ($suitemask & VER_SUITE_DATACENTER) {
470			    $desc .= " Datacenter Edition for Itanium-based Systems";
471			}
472			elsif ($suitemask & VER_SUITE_ENTERPRISE) {
473			    $desc .= " Enterprise Edition for Itanium-based Systems";
474			}
475		    }
476		    elsif ($arch == PROCESSOR_ARCHITECTURE_AMD64) {
477			if ($suitemask & VER_SUITE_DATACENTER) {
478			    $desc .= " Datacenter x64 Edition";
479			}
480			elsif ($suitemask & VER_SUITE_ENTERPRISE) {
481			    $desc .= " Enterprise x64 Edition";
482			}
483			else {
484			    $desc .= " Standard x64 Edition";
485			}
486		    }
487		    else {
488			if ($suitemask & VER_SUITE_COMPUTE_SERVER) {
489			    $desc .= " Windows Compute Cluster Server";
490			}
491			elsif ($suitemask & VER_SUITE_DATACENTER) {
492			    $desc .= " Datacenter Edition";
493			}
494			elsif ($suitemask & VER_SUITE_ENTERPRISE) {
495			    $desc .= " Enterprise Edition";
496			}
497			elsif ($suitemask & VER_SUITE_BLADE) {
498			    $desc .= " Web Edition";
499			}
500			elsif ($suitemask & VER_SUITE_SMALLBUSINESS_RESTRICTED) {
501			    $desc .= " Small Business Server";
502			}
503			else {
504			    if ($desc !~ /Windows (Home|Storage) Server/) {
505				$desc .= " Standard Edition";
506			    }
507			}
508		    }
509		}
510	    }
511	}
512	elsif ($major == 6) {
513	    if ($minor == 0) {
514		if ($producttype == VER_NT_WORKSTATION) {
515		    $os = "Vista";
516		}
517		else {
518		    $os = "2008";
519		}
520	    }
521	    elsif ($minor == 1) {
522		if ($producttype == VER_NT_WORKSTATION) {
523		    $os = "7";
524		}
525		else {
526		    $os = "2008";
527		    $desc = "R2";
528		}
529	    }
530	    elsif ($minor == 2) {
531	    if ($producttype == VER_NT_WORKSTATION) {
532	        $os = "8";
533	    }
534	    else {
535	        $os = "2012";
536	    }
537	    }
538	    elsif ($minor == 3) {
539		if ($producttype == VER_NT_WORKSTATION) {
540		    $os = "8.1";
541		}
542		else {
543		    $os = "2012";
544		    $desc = "R2";
545		}
546	    }
547        }
548	elsif ($major == 10) {
549            $os = '10';
550        }
551
552        if ($major >= 6) {
553            if ($productinfo == PRODUCT_ULTIMATE) {
554		$desc .= " Ultimate";
555	    }
556            elsif ($productinfo == PRODUCT_HOME_PREMIUM) {
557               $desc .= " Home Premium";
558            }
559            elsif ($productinfo == PRODUCT_HOME_BASIC) {
560               $desc .= " Home Basic";
561            }
562            elsif ($productinfo == PRODUCT_ENTERPRISE) {
563               $desc .= " Enterprise";
564            }
565            elsif ($productinfo == PRODUCT_BUSINESS) {
566	       # "Windows 7 Business" had a name change to "Windows 7 Professional"
567               $desc .= $minor == 0 ? " Business" : " Professional";
568            }
569            elsif ($productinfo == PRODUCT_STARTER) {
570               $desc .= " Starter";
571            }
572            elsif ($productinfo == PRODUCT_CLUSTER_SERVER) {
573               $desc .= " HPC Server";
574            }
575            elsif ($productinfo == PRODUCT_DATACENTER_SERVER) {
576               $desc .= " Datacenter";
577            }
578            elsif ($productinfo == PRODUCT_DATACENTER_SERVER_CORE) {
579               $desc .= " Datacenter Edition (core installation)";
580            }
581            elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER) {
582               $desc .= " Enterprise";
583            }
584            elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_CORE) {
585               $desc .= " Enterprise Edition (core installation)";
586            }
587            elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_IA64) {
588               $desc .= " Enterprise Edition for Itanium-based Systems";
589            }
590            elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER) {
591               $desc .= " Small Business Server";
592            }
593            elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER_PREMIUM) {
594               $desc .= " Small Business Server Premium Edition";
595            }
596            elsif ($productinfo == PRODUCT_STANDARD_SERVER) {
597               $desc .= " Standard";
598            }
599            elsif ($productinfo == PRODUCT_STANDARD_SERVER_CORE) {
600               $desc .= " Standard Edition (core installation)";
601            }
602            elsif ($productinfo == PRODUCT_WEB_SERVER) {
603               $desc .= " Web Server";
604            }
605            elsif ($productinfo == PRODUCT_PROFESSIONAL) {
606               $desc .= " Professional";
607            }
608
609	    if ($arch == PROCESSOR_ARCHITECTURE_INTEL) {
610		$desc .= " (32-bit)";
611	    }
612	    elsif ($arch == PROCESSOR_ARCHITECTURE_AMD64) {
613		$desc .= " (64-bit)";
614	    }
615	}
616    }
617
618    unless (defined $os) {
619	warn "Unknown Windows version [$id:$major:$minor]";
620	return;
621    }
622
623    for ($desc) {
624	s/\s\s+/ /g;
625	s/^\s//;
626	s/\s$//;
627    }
628
629    # XXX What about "Small Business Server"? NT, 200, 2003, 2008 editions...
630
631    if ($major >= 5) {
632	# XXX XP, Vista, 7 all have starter editions
633	#push(@tags, "Starter Edition") if _GetSystemMetrics(SM_STARTER, $metrics);
634    }
635
636    if (@tags) {
637	unshift(@tags, $desc) if length $desc;
638	$desc = join(" ", @tags);
639    }
640
641    if (length $csd) {
642	$desc .= " " if length $desc;
643	$desc .= $csd;
644    }
645    return ("Win$os", $desc);
646}
647
648# "no warnings 'redefine';" doesn't work for 5.8.7 and earlier
649local $^W = 0;
650bootstrap Win32;
651
6521;
653
654__END__
655
656=head1 NAME
657
658Win32 - Interfaces to some Win32 API Functions
659
660=head1 DESCRIPTION
661
662The Win32 module contains functions to access Win32 APIs.
663
664=head2 Alphabetical Listing of Win32 Functions
665
666It is recommended to C<use Win32;> before any of these functions;
667however, for backwards compatibility, those marked as [CORE] will
668automatically do this for you.
669
670In the function descriptions below the term I<Unicode string> is used
671to indicate that the string may contain characters outside the system
672codepage.  The caveat I<If supported by the core Perl version>
673generally means Perl 5.8.9 and later, though some Unicode pathname
674functionality may work on earlier versions.
675
676=over
677
678=item Win32::AbortSystemShutdown(MACHINE)
679
680Aborts a system shutdown (started by the
681InitiateSystemShutdown function) on the specified MACHINE.
682
683=item Win32::BuildNumber()
684
685[CORE] Returns the ActivePerl build number.  This function is
686only available in the ActivePerl binary distribution.
687
688=item Win32::CopyFile(FROM, TO, OVERWRITE)
689
690[CORE] The Win32::CopyFile() function copies an existing file to a new
691file.  All file information like creation time and file attributes will
692be copied to the new file.  However it will B<not> copy the security
693information.  If the destination file already exists it will only be
694overwritten when the OVERWRITE parameter is true.  But even this will
695not overwrite a read-only file; you have to unlink() it first
696yourself.
697
698=item Win32::CreateDirectory(DIRECTORY)
699
700Creates the DIRECTORY and returns a true value on success.  Check $^E
701on failure for extended error information.
702
703DIRECTORY may contain Unicode characters outside the system codepage.
704Once the directory has been created you can use
705Win32::GetANSIPathName() to get a name that can be passed to system
706calls and external programs.
707
708=item Win32::CreateFile(FILE)
709
710Creates the FILE and returns a true value on success.  Check $^E on
711failure for extended error information.
712
713FILE may contain Unicode characters outside the system codepage.  Once
714the file has been created you can use Win32::GetANSIPathName() to get
715a name that can be passed to system calls and external programs.
716
717=item Win32::DomainName()
718
719[CORE] Returns the name of the Microsoft Network domain or workgroup
720that the owner of the current perl process is logged into.  The
721"Workstation" service must be running to determine this
722information.  This function does B<not> work on Windows 9x.
723
724=item Win32::ExpandEnvironmentStrings(STRING)
725
726Takes STRING and replaces all referenced environment variable
727names with their defined values.  References to environment variables
728take the form C<%VariableName%>.  Case is ignored when looking up the
729VariableName in the environment.  If the variable is not found then the
730original C<%VariableName%> text is retained.  Has the same effect
731as the following:
732
733	$string =~ s/%([^%]*)%/$ENV{$1} || "%$1%"/eg
734
735However, this function may return a Unicode string if the environment
736variable being expanded hasn't been assigned to via %ENV.  Access
737to %ENV is currently always using byte semantics.
738
739=item Win32::FormatMessage(ERRORCODE)
740
741[CORE] Converts the supplied Win32 error number (e.g. returned by
742Win32::GetLastError()) to a descriptive string.  Analogous to the
743perror() standard-C library function.  Note that C<$^E> used
744in a string context has much the same effect.
745
746	C:\> perl -e "$^E = 26; print $^E;"
747	The specified disk or diskette cannot be accessed
748
749=item Win32::FsType()
750
751[CORE] Returns the name of the filesystem of the currently active
752drive (like 'FAT' or 'NTFS').  In list context it returns three values:
753(FSTYPE, FLAGS, MAXCOMPLEN).  FSTYPE is the filesystem type as
754before.  FLAGS is a combination of values of the following table:
755
756	0x00000001  supports case-sensitive filenames
757	0x00000002  preserves the case of filenames
758	0x00000004  supports Unicode in filenames
759	0x00000008  preserves and enforces ACLs
760	0x00000010  supports file-based compression
761	0x00000020  supports disk quotas
762	0x00000040  supports sparse files
763	0x00000080  supports reparse points
764	0x00000100  supports remote storage
765	0x00008000  is a compressed volume (e.g. DoubleSpace)
766	0x00010000  supports object identifiers
767	0x00020000  supports the Encrypted File System (EFS)
768
769MAXCOMPLEN is the maximum length of a filename component (the part
770between two backslashes) on this file system.
771
772=item Win32::FreeLibrary(HANDLE)
773
774Unloads a previously loaded dynamic-link library.  The HANDLE is
775no longer valid after this call.  See L<LoadLibrary|Win32::LoadLibrary(LIBNAME)>
776for information on dynamically loading a library.
777
778=item Win32::GetACP()
779
780Returns the current Windows ANSI code page identifier for the operating
781system.  See also GetOEMCP(), GetConsoleCP() and GetConsoleOutputCP().
782
783=item Win32::GetANSIPathName(FILENAME)
784
785Returns an ANSI version of FILENAME.  This may be the short name
786if the long name cannot be represented in the system codepage.
787
788While not currently implemented, it is possible that in the future
789this function will convert only parts of the path to FILENAME to a
790short form.
791
792If FILENAME doesn't exist on the filesystem, or if the filesystem
793doesn't support short ANSI filenames, then this function will
794translate the Unicode name into the system codepage using replacement
795characters.
796
797=item Win32::GetArchName()
798
799Use of this function is deprecated.  It is equivalent with
800$ENV{PROCESSOR_ARCHITECTURE}.  This might not work on Win9X.
801
802=item Win32::GetChipName()
803
804Returns the processor type: 386, 486 or 586 for x86 processors, 8664
805for the x64 processor and 2200 for the Itanium.  Since it returns the
806native processor type it will return a 64-bit processor type even when
807called from a 32-bit Perl running on 64-bit Windows.
808
809=item Win32::GetConsoleCP()
810
811Returns the input code page used by the console associated with the
812calling process.  To set the console's input code page, see
813SetConsoleCP().  See also GetConsoleOutputCP(), GetACP() and
814GetOEMCP().
815
816=item Win32::GetConsoleOutputCP()
817
818Returns the output code page used by the console associated with the
819calling process.  To set the console's output code page, see
820SetConsoleOutputCP().  See also GetConsoleCP(), GetACP(), and
821GetOEMCP().
822
823=item Win32::GetCwd()
824
825[CORE] Returns the current active drive and directory.  This function
826does not return a UNC path, since the functionality required for such
827a feature is not available under Windows 95.
828
829If supported by the core Perl version, this function will return an
830ANSI path name for the current directory if the long pathname cannot
831be represented in the system codepage.
832
833=item Win32::GetCurrentProcessId()
834
835Returns the process identifier of the current process.  Until the
836process terminates, the process identifier uniquely identifies the
837process throughout the system.
838
839The current process identifier is normally also available via the
840predefined $$ variable.  Under fork() emulation however $$ may contain
841a pseudo-process identifier that is only meaningful to the Perl
842kill(), wait() and waitpid() functions.  The
843Win32::GetCurrentProcessId() function will always return the regular
844Windows process id, even when called from inside a pseudo-process.
845
846=item Win32::GetCurrentThreadId()
847
848Returns the thread identifier of the calling thread.  Until the thread
849terminates, the thread identifier uniquely identifies the thread
850throughout the system.
851
852=item Win32::GetFileVersion(FILENAME)
853
854Returns the file version number from the VERSIONINFO resource of
855the executable file or DLL.  This is a tuple of four 16 bit numbers.
856In list context these four numbers will be returned.  In scalar context
857they are concatenated into a string, separated by dots.
858
859=item Win32::GetFolderPath(FOLDER [, CREATE])
860
861Returns the full pathname of one of the Windows special folders.
862The folder will be created if it doesn't exist and the optional CREATE
863argument is true.  The following FOLDER constants are defined by the
864Win32 module, but only exported on demand:
865
866        CSIDL_ADMINTOOLS
867        CSIDL_APPDATA
868        CSIDL_CDBURN_AREA
869        CSIDL_COMMON_ADMINTOOLS
870        CSIDL_COMMON_APPDATA
871        CSIDL_COMMON_DESKTOPDIRECTORY
872        CSIDL_COMMON_DOCUMENTS
873        CSIDL_COMMON_FAVORITES
874        CSIDL_COMMON_MUSIC
875        CSIDL_COMMON_PICTURES
876        CSIDL_COMMON_PROGRAMS
877        CSIDL_COMMON_STARTMENU
878        CSIDL_COMMON_STARTUP
879        CSIDL_COMMON_TEMPLATES
880        CSIDL_COMMON_VIDEO
881        CSIDL_COOKIES
882        CSIDL_DESKTOP
883        CSIDL_DESKTOPDIRECTORY
884        CSIDL_FAVORITES
885        CSIDL_FONTS
886        CSIDL_HISTORY
887        CSIDL_INTERNET_CACHE
888        CSIDL_LOCAL_APPDATA
889        CSIDL_MYMUSIC
890        CSIDL_MYPICTURES
891        CSIDL_MYVIDEO
892        CSIDL_NETHOOD
893        CSIDL_PERSONAL
894        CSIDL_PRINTHOOD
895        CSIDL_PROFILE
896        CSIDL_PROGRAMS
897        CSIDL_PROGRAM_FILES
898        CSIDL_PROGRAM_FILES_COMMON
899        CSIDL_RECENT
900        CSIDL_RESOURCES
901        CSIDL_RESOURCES_LOCALIZED
902        CSIDL_SENDTO
903        CSIDL_STARTMENU
904        CSIDL_STARTUP
905        CSIDL_SYSTEM
906        CSIDL_TEMPLATES
907        CSIDL_WINDOWS
908
909Note that not all folders are defined on all versions of Windows.
910
911Please refer to the MSDN documentation of the CSIDL constants,
912currently available at:
913
914http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
915
916This function will return an ANSI folder path if the long name cannot
917be represented in the system codepage.  Use Win32::GetLongPathName()
918on the result of Win32::GetFolderPath() if you want the Unicode
919version of the folder name.
920
921=item Win32::GetFullPathName(FILENAME)
922
923[CORE] GetFullPathName combines the FILENAME with the current drive
924and directory name and returns a fully qualified (aka, absolute)
925path name.  In list context it returns two elements: (PATH, FILE) where
926PATH is the complete pathname component (including trailing backslash)
927and FILE is just the filename part.  Note that no attempt is made to
928convert 8.3 components in the supplied FILENAME to longnames or
929vice-versa.  Compare with Win32::GetShortPathName() and
930Win32::GetLongPathName().
931
932If supported by the core Perl version, this function will return an
933ANSI path name if the full pathname cannot be represented in the
934system codepage.
935
936=item Win32::GetLastError()
937
938[CORE] Returns the last error value generated by a call to a Win32 API
939function.  Note that C<$^E> used in a numeric context amounts to the
940same value.
941
942=item Win32::GetLongPathName(PATHNAME)
943
944[CORE] Returns a representation of PATHNAME composed of longname
945components (if any).  The result may not necessarily be longer
946than PATHNAME.  No attempt is made to convert PATHNAME to the
947absolute path.  Compare with Win32::GetShortPathName() and
948Win32::GetFullPathName().
949
950This function may return the pathname in Unicode if it cannot be
951represented in the system codepage.  Use Win32::GetANSIPathName()
952before passing the path to a system call or another program.
953
954=item Win32::GetNextAvailDrive()
955
956[CORE] Returns a string in the form of "<d>:" where <d> is the first
957available drive letter.
958
959=item Win32::GetOEMCP()
960
961Returns the current original equipment manufacturer (OEM) code page
962identifier for the operating system.  See also GetACP(), GetConsoleCP()
963and GetConsoleOutputCP().
964
965=item Win32::GetOSDisplayName()
966
967Returns the "marketing" name of the Windows operating system version
968being used.  It returns names like these (random samples):
969
970   Windows 2000 Datacenter Server
971   Windows XP Professional
972   Windows XP Tablet PC Edition
973   Windows Home Server
974   Windows Server 2003 Enterprise Edition for Itanium-based Systems
975   Windows Vista Ultimate (32-bit)
976   Windows Small Business Server 2008 R2 (64-bit)
977
978The display name describes the native Windows version, so even on a
97932-bit Perl this function may return a "Windows ... (64-bit)" name
980when running on a 64-bit Windows.
981
982This function should only be used to display the actual OS name to the
983user; it should not be used to determine the class of operating systems
984this system belongs to.  The Win32::GetOSName(), Win32::GetOSVersion,
985Win32::GetProductInfo() and Win32::GetSystemMetrics() functions provide
986the base information to check for certain capabilities, or for families
987of OS releases.
988
989=item Win32::GetOSName()
990
991In scalar context returns the name of the Win32 operating system
992being used.  In list context returns a two element list of the OS name
993and whatever edition information is known about the particular build
994(for Win9X boxes) and whatever service packs have been installed.
995The latter is roughly equivalent to the first item returned by
996GetOSVersion() in list context.
997
998The description will also include tags for other special editions,
999like "R2", "Media Center", "Tablet PC", or "Starter Edition".
1000
1001Currently the possible values for the OS name are
1002
1003    WinWin32s
1004    Win95
1005    Win98
1006    WinMe
1007    WinNT3.51
1008    WinNT4
1009    Win2000
1010    WinXP/.Net
1011    Win2003
1012    WinHomeSvr
1013    WinVista
1014    Win2008
1015    Win7
1016
1017This routine is just a simple interface into GetOSVersion().  More
1018specific or demanding situations should use that instead.  Another
1019option would be to use POSIX::uname(), however the latter appears to
1020report only the OS family name and not the specific OS.  In scalar
1021context it returns just the ID.
1022
1023The name "WinXP/.Net" is used for historical reasons only, to maintain
1024backwards compatibility of the Win32 module.  Windows .NET Server has
1025been renamed as Windows 2003 Server before final release and uses a
1026different major/minor version number than Windows XP.
1027
1028Similarly the name "WinWin32s" should have been "Win32s" but has been
1029kept as-is for backwards compatibility reasons too.
1030
1031=item Win32::GetOSVersion()
1032
1033[CORE] Returns the list (STRING, MAJOR, MINOR, BUILD, ID), where the
1034elements are, respectively: An arbitrary descriptive string, the major
1035version number of the operating system, the minor version number, the
1036build number, and a digit indicating the actual operating system.
1037For the ID, the values are 0 for Win32s, 1 for Windows 9X/Me and 2 for
1038Windows NT/2000/XP/2003/Vista/2008/7.  In scalar context it returns just
1039the ID.
1040
1041Currently known values for ID MAJOR and MINOR are as follows:
1042
1043    OS                      ID    MAJOR   MINOR
1044    Win32s                   0      -       -
1045    Windows 95               1      4       0
1046    Windows 98               1      4      10
1047    Windows Me               1      4      90
1048
1049    Windows NT 3.51          2      3      51
1050    Windows NT 4             2      4       0
1051
1052    Windows 2000             2      5       0
1053    Windows XP               2      5       1
1054    Windows Server 2003      2      5       2
1055    Windows Server 2003 R2   2      5       2
1056    Windows Home Server      2      5       2
1057
1058    Windows Vista            2      6       0
1059    Windows Server 2008      2      6       0
1060    Windows 7                2      6       1
1061    Windows Server 2008 R2   2      6       1
1062    Windows 8                2      6       2
1063    Windows Server 2012      2      6       2
1064
1065On Windows NT 4 SP6 and later this function returns the following
1066additional values: SPMAJOR, SPMINOR, SUITEMASK, PRODUCTTYPE.
1067
1068The version numbers for Windows 2003 and Windows Home Server are
1069identical; the SUITEMASK field must be used to differentiate between
1070them.
1071
1072The version numbers for Windows Vista and Windows Server 2008 are
1073identical; the PRODUCTTYPE field must be used to differentiate between
1074them.
1075
1076The version numbers for Windows 7 and Windows Server 2008 R2 are
1077identical; the PRODUCTTYPE field must be used to differentiate between
1078them.
1079
1080The version numbers for Windows 8 and Windows Server 2012 are
1081identical; the PRODUCTTYPE field must be used to differentiate between
1082them.
1083
1084SPMAJOR and SPMINOR are the version numbers of the latest
1085installed service pack.
1086
1087SUITEMASK is a bitfield identifying the product suites available on
1088the system.  Known bits are:
1089
1090    VER_SUITE_SMALLBUSINESS             0x00000001
1091    VER_SUITE_ENTERPRISE                0x00000002
1092    VER_SUITE_BACKOFFICE                0x00000004
1093    VER_SUITE_COMMUNICATIONS            0x00000008
1094    VER_SUITE_TERMINAL                  0x00000010
1095    VER_SUITE_SMALLBUSINESS_RESTRICTED  0x00000020
1096    VER_SUITE_EMBEDDEDNT                0x00000040
1097    VER_SUITE_DATACENTER                0x00000080
1098    VER_SUITE_SINGLEUSERTS              0x00000100
1099    VER_SUITE_PERSONAL                  0x00000200
1100    VER_SUITE_BLADE                     0x00000400
1101    VER_SUITE_EMBEDDED_RESTRICTED       0x00000800
1102    VER_SUITE_SECURITY_APPLIANCE        0x00001000
1103    VER_SUITE_STORAGE_SERVER            0x00002000
1104    VER_SUITE_COMPUTE_SERVER            0x00004000
1105    VER_SUITE_WH_SERVER                 0x00008000
1106
1107The VER_SUITE_xxx names are listed here to cross reference the Microsoft
1108documentation.  The Win32 module does not provide symbolic names for these
1109constants.
1110
1111PRODUCTTYPE provides additional information about the system.  It should
1112be one of the following integer values:
1113
1114    1 - Workstation (NT 4, 2000 Pro, XP Home, XP Pro, Vista, etc)
1115    2 - Domaincontroller
1116    3 - Server (2000 Server, Server 2003, Server 2008, etc)
1117
1118Note that a server that is also a domain controller is reported as
1119PRODUCTTYPE 2 (Domaincontroller) and not PRODUCTTYPE 3 (Server).
1120
1121=item Win32::GetShortPathName(PATHNAME)
1122
1123[CORE] Returns a representation of PATHNAME that is composed of short
1124(8.3) path components where available.  For path components where the
1125file system has not generated the short form the returned path will
1126use the long form, so this function might still for instance return a
1127path containing spaces.  Returns C<undef> when the PATHNAME does not
1128exist. Compare with Win32::GetFullPathName() and
1129Win32::GetLongPathName().
1130
1131=item Win32::GetSystemMetrics(INDEX)
1132
1133Retrieves the specified system metric or system configuration setting.
1134Please refer to the Microsoft documentation of the GetSystemMetrics()
1135function for a reference of available INDEX values.  All system
1136metrics return integer values.
1137
1138=item Win32::GetProcAddress(INSTANCE, PROCNAME)
1139
1140Returns the address of a function inside a loaded library.  The
1141information about what you can do with this address has been lost in
1142the mist of time.  Use the Win32::API module instead of this deprecated
1143function.
1144
1145=item Win32::GetProductInfo(OSMAJOR, OSMINOR, SPMAJOR, SPMINOR)
1146
1147Retrieves the product type for the operating system on the local
1148computer, and maps the type to the product types supported by the
1149specified operating system.  Please refer to the Microsoft
1150documentation of the GetProductInfo() function for more information
1151about the parameters and return value.  This function requires Windows
1152Vista or later.
1153
1154See also the Win32::GetOSName() and Win32::GetOSDisplayName()
1155functions which provide a higher level abstraction of the data
1156returned by this function.
1157
1158=item Win32::GetTickCount()
1159
1160[CORE] Returns the number of milliseconds elapsed since the last
1161system boot.  Resolution is limited to system timer ticks (about 10ms
1162on WinNT and 55ms on Win9X).
1163
1164=item Win32::GuidGen()
1165
1166Creates a globally unique 128 bit integer that can be used as a
1167persistent identifier in a distributed setting. To a very high degree
1168of certainty this function returns a unique value. No other
1169invocation, on the same or any other system (networked or not), should
1170return the same value.
1171
1172The return value is formatted according to OLE conventions, as groups
1173of hex digits with surrounding braces.  For example:
1174
1175    {09531CF1-D0C7-4860-840C-1C8C8735E2AD}
1176
1177=item Win32::InitiateSystemShutdown
1178
1179(MACHINE, MESSAGE, TIMEOUT, FORCECLOSE, REBOOT)
1180
1181Shutsdown the specified MACHINE, notifying users with the
1182supplied MESSAGE, within the specified TIMEOUT interval.  Forces
1183closing of all documents without prompting the user if FORCECLOSE is
1184true, and reboots the machine if REBOOT is true.  This function works
1185only on WinNT.
1186
1187=item Win32::IsAdminUser()
1188
1189Returns non zero if the account in whose security context the
1190current process/thread is running belongs to the local group of
1191Administrators in the built-in system domain; returns 0 if not.
1192On Windows Vista it will only return non-zero if the process is
1193actually running with elevated privileges.  Returns C<undef>
1194and prints a warning if an error occurred.  This function always
1195returns 1 on Win9X.
1196
1197=item Win32::IsWinNT()
1198
1199[CORE] Returns non zero if the Win32 subsystem is Windows NT.
1200
1201=item Win32::IsWin95()
1202
1203[CORE] Returns non zero if the Win32 subsystem is Windows 95.
1204
1205=item Win32::LoadLibrary(LIBNAME)
1206
1207Loads a dynamic link library into memory and returns its module
1208handle.  This handle can be used with Win32::GetProcAddress() and
1209Win32::FreeLibrary().  This function is deprecated.  Use the Win32::API
1210module instead.
1211
1212=item Win32::LoginName()
1213
1214[CORE] Returns the username of the owner of the current perl process.
1215The return value may be a Unicode string.
1216
1217=item Win32::LookupAccountName(SYSTEM, ACCOUNT, DOMAIN, SID, SIDTYPE)
1218
1219Looks up ACCOUNT on SYSTEM and returns the domain name the SID and
1220the SID type.
1221
1222=item Win32::LookupAccountSID(SYSTEM, SID, ACCOUNT, DOMAIN, SIDTYPE)
1223
1224Looks up SID on SYSTEM and returns the account name, domain name,
1225and the SID type.
1226
1227=item Win32::MsgBox(MESSAGE [, FLAGS [, TITLE]])
1228
1229Create a dialog box containing MESSAGE.  FLAGS specifies the
1230required icon and buttons according to the following table:
1231
1232	0 = OK
1233	1 = OK and Cancel
1234	2 = Abort, Retry, and Ignore
1235	3 = Yes, No and Cancel
1236	4 = Yes and No
1237	5 = Retry and Cancel
1238
1239	MB_ICONSTOP          "X" in a red circle
1240	MB_ICONQUESTION      question mark in a bubble
1241	MB_ICONEXCLAMATION   exclamation mark in a yellow triangle
1242	MB_ICONINFORMATION   "i" in a bubble
1243
1244TITLE specifies an optional window title.  The default is "Perl".
1245
1246The function returns the menu id of the selected push button:
1247
1248	0  Error
1249
1250	1  OK
1251	2  Cancel
1252	3  Abort
1253	4  Retry
1254	5  Ignore
1255	6  Yes
1256	7  No
1257
1258=item Win32::NodeName()
1259
1260[CORE] Returns the Microsoft Network node-name of the current machine.
1261
1262=item Win32::OutputDebugString(STRING)
1263
1264Sends a string to the application or system debugger for display.
1265The function does nothing if there is no active debugger.
1266
1267Alternatively one can use the I<Debug Viewer> application to
1268watch the OutputDebugString() output:
1269
1270http://www.microsoft.com/technet/sysinternals/utilities/debugview.mspx
1271
1272=item Win32::RegisterServer(LIBRARYNAME)
1273
1274Loads the DLL LIBRARYNAME and calls the function DllRegisterServer.
1275
1276=item Win32::SetChildShowWindow(SHOWWINDOW)
1277
1278[CORE] Sets the I<ShowMode> of child processes started by system().
1279By default system() will create a new console window for child
1280processes if Perl itself is not running from a console.  Calling
1281SetChildShowWindow(0) will make these new console windows invisible.
1282Calling SetChildShowWindow() without arguments reverts system() to the
1283default behavior.  The return value of SetChildShowWindow() is the
1284previous setting or C<undef>.
1285
1286The following symbolic constants for SHOWWINDOW are available
1287(but not exported) from the Win32 module: SW_HIDE, SW_SHOWNORMAL,
1288SW_SHOWMINIMIZED, SW_SHOWMAXIMIZED and SW_SHOWNOACTIVATE.
1289
1290=item Win32::SetConsoleCP(ID)
1291
1292Sets the input code page used by the console associated with the
1293calling process.  The return value of SetConsoleCP() is nonzero on
1294success or zero on failure.  To get the console's input code page, see
1295GetConsoleCP().
1296
1297=item Win32::SetConsoleOutputCP(ID)
1298
1299Sets the output code page used by the console associated with the
1300calling process.  The return value of SetConsoleOutputCP() is nonzero on
1301success or zero on failure.  To get the console's output code page, see
1302GetConsoleOutputCP().
1303
1304=item Win32::SetCwd(NEWDIRECTORY)
1305
1306[CORE] Sets the current active drive and directory.  This function does not
1307work with UNC paths, since the functionality required to required for
1308such a feature is not available under Windows 95.
1309
1310=item Win32::SetLastError(ERROR)
1311
1312[CORE] Sets the value of the last error encountered to ERROR.  This is
1313that value that will be returned by the Win32::GetLastError()
1314function.
1315
1316=item Win32::Sleep(TIME)
1317
1318[CORE] Pauses for TIME milliseconds.  The timeslices are made available
1319to other processes and threads.
1320
1321=item Win32::Spawn(COMMAND, ARGS, PID)
1322
1323[CORE] Spawns a new process using the supplied COMMAND, passing in
1324arguments in the string ARGS.  The pid of the new process is stored in
1325PID.  This function is deprecated.  Please use the Win32::Process module
1326instead.
1327
1328=item Win32::UnregisterServer(LIBRARYNAME)
1329
1330Loads the DLL LIBRARYNAME and calls the function
1331DllUnregisterServer.
1332
1333=back
1334
1335=cut
1336