5 use vars qw|$VERSION $XS_VERSION @ISA @EXPORT @EXPORT_OK|;
10 @ISA = qw|Exporter DynaLoader|;
12 $XS_VERSION = $VERSION;
13 $VERSION = eval $VERSION;
18 OWNER_SECURITY_INFORMATION
19 GROUP_SECURITY_INFORMATION
20 DACL_SECURITY_INFORMATION
21 SACL_SECURITY_INFORMATION
49 CSIDL_DESKTOPDIRECTORY
53 CSIDL_COMMON_STARTMENU
56 CSIDL_COMMON_DESKTOPDIRECTORY
60 CSIDL_COMMON_FAVORITES
70 CSIDL_PROGRAM_FILES_COMMON
71 CSIDL_COMMON_TEMPLATES
72 CSIDL_COMMON_DOCUMENTS
73 CSIDL_COMMON_ADMINTOOLS
79 CSIDL_RESOURCES_LOCALIZED
84 # We won't bother with the constant stuff, too much of a hassle. Just hard
88 sub WIN31_CLASS { &NULL }
90 sub OWNER_SECURITY_INFORMATION { 0x00000001 }
91 sub GROUP_SECURITY_INFORMATION { 0x00000002 }
92 sub DACL_SECURITY_INFORMATION { 0x00000004 }
93 sub SACL_SECURITY_INFORMATION { 0x00000008 }
95 sub MB_ICONHAND { 0x00000010 }
96 sub MB_ICONQUESTION { 0x00000020 }
97 sub MB_ICONEXCLAMATION { 0x00000030 }
98 sub MB_ICONASTERISK { 0x00000040 }
99 sub MB_ICONWARNING { 0x00000030 }
100 sub MB_ICONERROR { 0x00000010 }
101 sub MB_ICONINFORMATION { 0x00000040 }
102 sub MB_ICONSTOP { 0x00000010 }
105 # Newly added constants. These have an empty prototype, unlike the
106 # the ones above, which aren't prototyped for compatibility reasons.
109 sub SW_SHOWNORMAL () { 1 }
110 sub SW_SHOWMINIMIZED () { 2 }
111 sub SW_SHOWMAXIMIZED () { 3 }
112 sub SW_SHOWNOACTIVATE () { 4 }
114 sub CSIDL_DESKTOP () { 0x0000 } # <desktop>
115 sub CSIDL_PROGRAMS () { 0x0002 } # Start Menu\Programs
116 sub CSIDL_PERSONAL () { 0x0005 } # "My Documents" folder
117 sub CSIDL_FAVORITES () { 0x0006 } # <user name>\Favorites
118 sub CSIDL_STARTUP () { 0x0007 } # Start Menu\Programs\Startup
119 sub CSIDL_RECENT () { 0x0008 } # <user name>\Recent
120 sub CSIDL_SENDTO () { 0x0009 } # <user name>\SendTo
121 sub CSIDL_STARTMENU () { 0x000B } # <user name>\Start Menu
122 sub CSIDL_MYMUSIC () { 0x000D } # "My Music" folder
123 sub CSIDL_MYVIDEO () { 0x000E } # "My Videos" folder
124 sub CSIDL_DESKTOPDIRECTORY () { 0x0010 } # <user name>\Desktop
125 sub CSIDL_NETHOOD () { 0x0013 } # <user name>\nethood
126 sub CSIDL_FONTS () { 0x0014 } # windows\fonts
127 sub CSIDL_TEMPLATES () { 0x0015 }
128 sub CSIDL_COMMON_STARTMENU () { 0x0016 } # All Users\Start Menu
129 sub CSIDL_COMMON_PROGRAMS () { 0x0017 } # All Users\Start Menu\Programs
130 sub CSIDL_COMMON_STARTUP () { 0x0018 } # All Users\Startup
131 sub CSIDL_COMMON_DESKTOPDIRECTORY () { 0x0019 } # All Users\Desktop
132 sub CSIDL_APPDATA () { 0x001A } # Application Data, new for NT4
133 sub CSIDL_PRINTHOOD () { 0x001B } # <user name>\PrintHood
134 sub CSIDL_LOCAL_APPDATA () { 0x001C } # non roaming, user\Local Settings\Application Data
135 sub CSIDL_COMMON_FAVORITES () { 0x001F }
136 sub CSIDL_INTERNET_CACHE () { 0x0020 }
137 sub CSIDL_COOKIES () { 0x0021 }
138 sub CSIDL_HISTORY () { 0x0022 }
139 sub CSIDL_COMMON_APPDATA () { 0x0023 } # All Users\Application Data
140 sub CSIDL_WINDOWS () { 0x0024 } # GetWindowsDirectory()
141 sub CSIDL_SYSTEM () { 0x0025 } # GetSystemDirectory()
142 sub CSIDL_PROGRAM_FILES () { 0x0026 } # C:\Program Files
143 sub CSIDL_MYPICTURES () { 0x0027 } # "My Pictures", new for Win2K
144 sub CSIDL_PROFILE () { 0x0028 } # USERPROFILE
145 sub CSIDL_PROGRAM_FILES_COMMON () { 0x002B } # C:\Program Files\Common
146 sub CSIDL_COMMON_TEMPLATES () { 0x002D } # All Users\Templates
147 sub CSIDL_COMMON_DOCUMENTS () { 0x002E } # All Users\Documents
148 sub CSIDL_COMMON_ADMINTOOLS () { 0x002F } # All Users\Start Menu\Programs\Administrative Tools
149 sub CSIDL_ADMINTOOLS () { 0x0030 } # <user name>\Start Menu\Programs\Administrative Tools
150 sub CSIDL_COMMON_MUSIC () { 0x0035 } # All Users\My Music
151 sub CSIDL_COMMON_PICTURES () { 0x0036 } # All Users\My Pictures
152 sub CSIDL_COMMON_VIDEO () { 0x0037 } # All Users\My Video
153 sub CSIDL_RESOURCES () { 0x0038 } # %windir%\Resources\, For theme and other windows resources.
154 sub CSIDL_RESOURCES_LOCALIZED () { 0x0039 } # %windir%\Resources\<LangID>, for theme and other windows specific resources.
155 sub CSIDL_CDBURN_AREA () { 0x003B } # <user name>\Local Settings\Application Data\Microsoft\CD Burning
157 sub 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.
158 sub 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.
160 sub VER_NT_WORKSTATION () { 0x0000001 } # The operating system is Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
163 sub VER_SUITE_BACKOFFICE () { 0x00000004 } # Microsoft BackOffice components are installed.
164 sub VER_SUITE_BLADE () { 0x00000400 } # Windows Server 2003, Web Edition is installed.
165 sub VER_SUITE_COMPUTE_SERVER () { 0x00004000 } # Windows Server 2003, Compute Cluster Edition is installed.
166 sub VER_SUITE_DATACENTER () { 0x00000080 } # Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed.
167 sub 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.
168 sub VER_SUITE_EMBEDDEDNT () { 0x00000040 } # Windows XP Embedded is installed.
169 sub VER_SUITE_PERSONAL () { 0x00000200 } # Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed.
170 sub 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.
171 sub 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.
172 sub 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.
173 sub VER_SUITE_STORAGE_SERVER () { 0x00002000 } # Windows Storage Server 2003 R2 or Windows Storage Server 2003 is installed.
174 sub 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.
176 sub VER_SUITE_WH_SERVER () { 0x00008000 } # Windows Home Server is installed.
179 sub SM_TABLETPC () { 86 }
180 sub SM_MEDIACENTER () { 87 }
181 sub SM_STARTER () { 88 }
182 sub SM_SERVERR2 () { 89 }
184 sub PRODUCT_UNDEFINED () { 0x000 } # An unknown product
185 sub PRODUCT_ULTIMATE () { 0x001 } # Ultimate
186 sub PRODUCT_HOME_BASIC () { 0x002 } # Home Basic
187 sub PRODUCT_HOME_PREMIUM () { 0x003 } # Home Premium
188 sub PRODUCT_ENTERPRISE () { 0x004 } # Enterprise
189 sub PRODUCT_HOME_BASIC_N () { 0x005 } # Home Basic N
190 sub PRODUCT_BUSINESS () { 0x006 } # Business
191 sub PRODUCT_STANDARD_SERVER () { 0x007 } # Server Standard (full installation)
192 sub PRODUCT_DATACENTER_SERVER () { 0x008 } # Server Datacenter (full installation)
193 sub PRODUCT_SMALLBUSINESS_SERVER () { 0x009 } # Windows Small Business Server
194 sub PRODUCT_ENTERPRISE_SERVER () { 0x00A } # Server Enterprise (full installation)
195 sub PRODUCT_STARTER () { 0x00B } # Starter
196 sub PRODUCT_DATACENTER_SERVER_CORE () { 0x00C } # Server Datacenter (core installation)
197 sub PRODUCT_STANDARD_SERVER_CORE () { 0x00D } # Server Standard (core installation)
198 sub PRODUCT_ENTERPRISE_SERVER_CORE () { 0x00E } # Server Enterprise (core installation)
199 sub PRODUCT_ENTERPRISE_SERVER_IA64 () { 0x00F } # Server Enterprise for Itanium-based Systems
200 sub PRODUCT_BUSINESS_N () { 0x010 } # Business N
201 sub PRODUCT_WEB_SERVER () { 0x011 } # Web Server (full installation)
202 sub PRODUCT_CLUSTER_SERVER () { 0x012 } # HPC Edition
203 sub PRODUCT_HOME_SERVER () { 0x013 } # Home Server Edition
204 sub PRODUCT_STORAGE_EXPRESS_SERVER () { 0x014 } # Storage Server Express
205 sub PRODUCT_STORAGE_STANDARD_SERVER () { 0x015 } # Storage Server Standard
206 sub PRODUCT_STORAGE_WORKGROUP_SERVER () { 0x016 } # Storage Server Workgroup
207 sub PRODUCT_STORAGE_ENTERPRISE_SERVER () { 0x017 } # Storage Server Enterprise
208 sub PRODUCT_SERVER_FOR_SMALLBUSINESS () { 0x018 } # Windows Server 2008 for Windows Essential Server Solutions
209 sub PRODUCT_SMALLBUSINESS_SERVER_PREMIUM () { 0x019 } # Windows Small Business Server Premium
210 sub PRODUCT_HOME_PREMIUM_N () { 0x01A } # Home Premium N
211 sub PRODUCT_ENTERPRISE_N () { 0x01B } # Enterprise N
212 sub PRODUCT_ULTIMATE_N () { 0x01C } # Ultimate N
213 sub PRODUCT_WEB_SERVER_CORE () { 0x01D } # Web Server (core installation)
214 sub PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT () { 0x01E } # Windows Essential Business Server Management Server
215 sub PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY () { 0x01F } # Windows Essential Business Server Security Server
216 sub PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING () { 0x020 } # Windows Essential Business Server Messaging Server
217 sub PRODUCT_SERVER_FOUNDATION () { 0x021 } # Server Foundation
219 sub PRODUCT_SERVER_FOR_SMALLBUSINESS_V () { 0x023 } # Windows Server 2008 without Hyper-V for Windows Essential Server Solutions
220 sub PRODUCT_STANDARD_SERVER_V () { 0x024 } # Server Standard without Hyper-V (full installation)
221 sub PRODUCT_DATACENTER_SERVER_V () { 0x025 } # Server Datacenter without Hyper-V (full installation)
222 sub PRODUCT_ENTERPRISE_SERVER_V () { 0x026 } # Server Enterprise without Hyper-V (full installation)
223 sub PRODUCT_DATACENTER_SERVER_CORE_V () { 0x027 } # Server Datacenter without Hyper-V (core installation)
224 sub PRODUCT_STANDARD_SERVER_CORE_V () { 0x028 } # Server Standard without Hyper-V (core installation)
225 sub PRODUCT_ENTERPRISE_SERVER_CORE_V () { 0x029 } # Server Enterprise without Hyper-V (core installation)
226 sub PRODUCT_HYPERV () { 0x02A } # Microsoft Hyper-V Server
228 sub PRODUCT_STARTER_N () { 0x02F } # Starter N
229 sub PRODUCT_PROFESSIONAL () { 0x030 } # Professional
230 sub PRODUCT_PROFESSIONAL_N () { 0x031 } # Professional N
232 sub PRODUCT_STARTER_E () { 0x042 } # Starter E
233 sub PRODUCT_HOME_BASIC_E () { 0x043 } # Home Basic E
234 sub PRODUCT_HOME_PREMIUM_E () { 0x044 } # Home Premium E
235 sub PRODUCT_PROFESSIONAL_E () { 0x045 } # Professional E
236 sub PRODUCT_ENTERPRISE_E () { 0x046 } # Enterprise E
237 sub PRODUCT_ULTIMATE_E () { 0x047 } # Ultimate E
239 sub PRODUCT_UNLICENSED () { 0xABCDABCD } # product has not been activated and is no longer in the grace period
241 sub PROCESSOR_ARCHITECTURE_AMD64 () { 9 } # x64 (AMD or Intel)
242 sub PROCESSOR_ARCHITECTURE_IA64 () { 6 } # Intel Itanium Processor Family (IPF)
243 sub PROCESSOR_ARCHITECTURE_INTEL () { 0 } # x86
244 sub PROCESSOR_ARCHITECTURE_UNKNOWN () { 0xffff } # Unknown architecture.
246 sub _GetProcessorArchitecture {
248 386 => PROCESSOR_ARCHITECTURE_INTEL,
249 486 => PROCESSOR_ARCHITECTURE_INTEL,
250 586 => PROCESSOR_ARCHITECTURE_INTEL,
251 2200 => PROCESSOR_ARCHITECTURE_IA64,
252 8664 => PROCESSOR_ARCHITECTURE_AMD64,
253 }->{Win32::GetChipName()};
254 return defined($arch) ? $arch : PROCESSOR_ARCHITECTURE_UNKNOWN;
257 ### This method is just a simple interface into GetOSVersion(). More
258 ### specific or demanding situations should use that instead.
260 my ($cached_os, $cached_desc);
263 unless (defined $cached_os) {
264 my($desc, $major, $minor, $build, $id, undef, undef, $suitemask, $producttype)
265 = Win32::GetOSVersion();
266 my $arch = _GetProcessorArchitecture();
267 my $productinfo = Win32::GetProductInfo(6, 0, 0, 0);
268 ($cached_os, $cached_desc) = _GetOSName($desc, $major, $minor, $build, $id,
269 $suitemask, $producttype, $productinfo, $arch);
271 return wantarray ? ($cached_os, $cached_desc) : $cached_os;
274 sub GetOSDisplayName {
275 # Calling GetOSDisplayName() with arguments is for the test suite only!
276 my($name,$desc) = @_ ? @_ : GetOSName();
278 if ($desc =~ /^Windows Home Server\b/ || $desc =~ /^Windows XP Professional x64 Edition\b/) {
279 ($name, $desc) = ($desc, "");
281 elsif ($desc =~ s/\s*(Windows (.*) Server( \d+)?)//) {
287 s/^/Windows / unless /^Win32s$/;
290 if ($desc =~ s/\s*(HPC|Small Business|Web) Server//) {
293 s/(200.)/$name Server $1/;
295 s/^Windows (20(03|08|12))/Windows Server $1/;
298 $name .= " $desc" if length $desc;
302 sub _GetSystemMetrics {
303 my($index,$metrics) = @_;
304 return Win32::GetSystemMetrics($index) unless ref $metrics;
305 return $metrics->{$index} if ref $metrics eq "HASH" && defined $metrics->{$index};
306 return 1 if ref $metrics eq "ARRAY" && grep $_ == $index, @$metrics;
311 # The $metrics argument only exists for the benefit of t/GetOSName.t
312 my($csd, $major, $minor, $build, $id, $suitemask, $producttype, $productinfo, $arch, $metrics) = @_;
323 elsif ($minor == 10) {
326 elsif ($minor == 90) {
334 elsif ($major == 4) {
337 elsif ($major == 5) {
340 if ($producttype == VER_NT_WORKSTATION) {
341 $desc = "Professional";
344 if ($suitemask & VER_SUITE_DATACENTER) {
345 $desc = "Datacenter Server";
347 elsif ($suitemask & VER_SUITE_ENTERPRISE) {
348 $desc = "Advanced Server";
350 elsif ($suitemask & VER_SUITE_SMALLBUSINESS_RESTRICTED) {
351 $desc = "Small Business Server";
357 # XXX ignoring "Windows 2000 Advanced Server Limited Edition" for Itanium
358 # XXX and "Windows 2000 Datacenter Server Limited Edition" for Itanium
360 elsif ($minor == 1) {
362 if (_GetSystemMetrics(SM_MEDIACENTER, $metrics)) {
363 $desc = "Media Center Edition";
365 elsif (_GetSystemMetrics(SM_TABLETPC, $metrics)) {
366 # Tablet PC Edition is based on XP Pro
367 $desc = "Tablet PC Edition";
369 elsif (_GetSystemMetrics(SM_STARTER, $metrics)) {
370 $desc = "Starter Edition";
372 elsif ($suitemask & VER_SUITE_PERSONAL) {
373 $desc = "Home Edition";
376 $desc = "Professional";
378 # XXX ignoring all Windows XP Embedded and Fundamentals versions
380 elsif ($minor == 2) {
383 if (_GetSystemMetrics(SM_SERVERR2, $metrics)) {
384 # XXX R2 was released for all x86 and x64 versions,
385 # XXX but only Enterprise Edition for Itanium.
389 if ($suitemask == VER_SUITE_STORAGE_SERVER) {
390 $desc .= " Windows Storage Server";
392 elsif ($suitemask == VER_SUITE_WH_SERVER) {
393 $desc .= " Windows Home Server";
395 elsif ($producttype == VER_NT_WORKSTATION && $arch == PROCESSOR_ARCHITECTURE_AMD64) {
396 $desc .= " Windows XP Professional x64 Edition";
399 # Test for the server type.
400 if ($producttype != VER_NT_WORKSTATION) {
401 if ($arch == PROCESSOR_ARCHITECTURE_IA64) {
402 if ($suitemask & VER_SUITE_DATACENTER) {
403 $desc .= " Datacenter Edition for Itanium-based Systems";
405 elsif ($suitemask & VER_SUITE_ENTERPRISE) {
406 $desc .= " Enterprise Edition for Itanium-based Systems";
409 elsif ($arch == PROCESSOR_ARCHITECTURE_AMD64) {
410 if ($suitemask & VER_SUITE_DATACENTER) {
411 $desc .= " Datacenter x64 Edition";
413 elsif ($suitemask & VER_SUITE_ENTERPRISE) {
414 $desc .= " Enterprise x64 Edition";
417 $desc .= " Standard x64 Edition";
421 if ($suitemask & VER_SUITE_COMPUTE_SERVER) {
422 $desc .= " Windows Compute Cluster Server";
424 elsif ($suitemask & VER_SUITE_DATACENTER) {
425 $desc .= " Datacenter Edition";
427 elsif ($suitemask & VER_SUITE_ENTERPRISE) {
428 $desc .= " Enterprise Edition";
430 elsif ($suitemask & VER_SUITE_BLADE) {
431 $desc .= " Web Edition";
433 elsif ($suitemask & VER_SUITE_SMALLBUSINESS_RESTRICTED) {
434 $desc .= " Small Business Server";
437 if ($desc !~ /Windows (Home|Storage) Server/) {
438 $desc .= " Standard Edition";
445 elsif ($major == 6) {
447 if ($producttype == VER_NT_WORKSTATION) {
454 elsif ($minor == 1) {
455 if ($producttype == VER_NT_WORKSTATION) {
463 elsif ($minor == 2) {
464 if ($producttype == VER_NT_WORKSTATION) {
472 if ($productinfo == PRODUCT_ULTIMATE) {
473 $desc .= " Ultimate";
475 elsif ($productinfo == PRODUCT_HOME_PREMIUM) {
476 $desc .= " Home Premium";
478 elsif ($productinfo == PRODUCT_HOME_BASIC) {
479 $desc .= " Home Basic";
481 elsif ($productinfo == PRODUCT_ENTERPRISE) {
482 $desc .= " Enterprise";
484 elsif ($productinfo == PRODUCT_BUSINESS) {
485 # "Windows 7 Business" had a name change to "Windows 7 Professional"
486 $desc .= $minor == 0 ? " Business" : " Professional";
488 elsif ($productinfo == PRODUCT_STARTER) {
491 elsif ($productinfo == PRODUCT_CLUSTER_SERVER) {
492 $desc .= " HPC Server";
494 elsif ($productinfo == PRODUCT_DATACENTER_SERVER) {
495 $desc .= " Datacenter";
497 elsif ($productinfo == PRODUCT_DATACENTER_SERVER_CORE) {
498 $desc .= " Datacenter Edition (core installation)";
500 elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER) {
501 $desc .= " Enterprise";
503 elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_CORE) {
504 $desc .= " Enterprise Edition (core installation)";
506 elsif ($productinfo == PRODUCT_ENTERPRISE_SERVER_IA64) {
507 $desc .= " Enterprise Edition for Itanium-based Systems";
509 elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER) {
510 $desc .= " Small Business Server";
512 elsif ($productinfo == PRODUCT_SMALLBUSINESS_SERVER_PREMIUM) {
513 $desc .= " Small Business Server Premium Edition";
515 elsif ($productinfo == PRODUCT_STANDARD_SERVER) {
516 $desc .= " Standard";
518 elsif ($productinfo == PRODUCT_STANDARD_SERVER_CORE) {
519 $desc .= " Standard Edition (core installation)";
521 elsif ($productinfo == PRODUCT_WEB_SERVER) {
522 $desc .= " Web Server";
524 elsif ($productinfo == PRODUCT_PROFESSIONAL) {
525 $desc .= " Professional";
528 if ($arch == PROCESSOR_ARCHITECTURE_INTEL) {
529 $desc .= " (32-bit)";
531 elsif ($arch == PROCESSOR_ARCHITECTURE_AMD64) {
532 $desc .= " (64-bit)";
537 unless (defined $os) {
538 warn "Unknown Windows version [$id:$major:$minor]";
548 # XXX What about "Small Business Server"? NT, 200, 2003, 2008 editions...
551 # XXX XP, Vista, 7 all have starter editions
552 #push(@tags, "Starter Edition") if _GetSystemMetrics(SM_STARTER, $metrics);
556 unshift(@tags, $desc) if length $desc;
557 $desc = join(" ", @tags);
561 $desc .= " " if length $desc;
564 return ("Win$os", $desc);
567 # "no warnings 'redefine';" doesn't work for 5.8.7 and earlier
577 Win32 - Interfaces to some Win32 API Functions
581 The Win32 module contains functions to access Win32 APIs.
583 =head2 Alphabetical Listing of Win32 Functions
585 It is recommended to C<use Win32;> before any of these functions;
586 however, for backwards compatibility, those marked as [CORE] will
587 automatically do this for you.
589 In the function descriptions below the term I<Unicode string> is used
590 to indicate that the string may contain characters outside the system
591 codepage. The caveat I<If supported by the core Perl version>
592 generally means Perl 5.8.9 and later, though some Unicode pathname
593 functionality may work on earlier versions.
597 =item Win32::AbortSystemShutdown(MACHINE)
599 Aborts a system shutdown (started by the
600 InitiateSystemShutdown function) on the specified MACHINE.
602 =item Win32::BuildNumber()
604 [CORE] Returns the ActivePerl build number. This function is
605 only available in the ActivePerl binary distribution.
607 =item Win32::CopyFile(FROM, TO, OVERWRITE)
609 [CORE] The Win32::CopyFile() function copies an existing file to a new
610 file. All file information like creation time and file attributes will
611 be copied to the new file. However it will B<not> copy the security
612 information. If the destination file already exists it will only be
613 overwritten when the OVERWRITE parameter is true. But even this will
614 not overwrite a read-only file; you have to unlink() it first
617 =item Win32::CreateDirectory(DIRECTORY)
619 Creates the DIRECTORY and returns a true value on success. Check $^E
620 on failure for extended error information.
622 DIRECTORY may contain Unicode characters outside the system codepage.
623 Once the directory has been created you can use
624 Win32::GetANSIPathName() to get a name that can be passed to system
625 calls and external programs.
627 =item Win32::CreateFile(FILE)
629 Creates the FILE and returns a true value on success. Check $^E on
630 failure for extended error information.
632 FILE may contain Unicode characters outside the system codepage. Once
633 the file has been created you can use Win32::GetANSIPathName() to get
634 a name that can be passed to system calls and external programs.
636 =item Win32::DomainName()
638 [CORE] Returns the name of the Microsoft Network domain or workgroup
639 that the owner of the current perl process is logged into. The
640 "Workstation" service must be running to determine this
641 information. This function does B<not> work on Windows 9x.
643 =item Win32::ExpandEnvironmentStrings(STRING)
645 Takes STRING and replaces all referenced environment variable
646 names with their defined values. References to environment variables
647 take the form C<%VariableName%>. Case is ignored when looking up the
648 VariableName in the environment. If the variable is not found then the
649 original C<%VariableName%> text is retained. Has the same effect
652 $string =~ s/%([^%]*)%/$ENV{$1} || "%$1%"/eg
654 However, this function may return a Unicode string if the environment
655 variable being expanded hasn't been assigned to via %ENV. Access
656 to %ENV is currently always using byte semantics.
658 =item Win32::FormatMessage(ERRORCODE)
660 [CORE] Converts the supplied Win32 error number (e.g. returned by
661 Win32::GetLastError()) to a descriptive string. Analogous to the
662 perror() standard-C library function. Note that C<$^E> used
663 in a string context has much the same effect.
665 C:\> perl -e "$^E = 26; print $^E;"
666 The specified disk or diskette cannot be accessed
668 =item Win32::FsType()
670 [CORE] Returns the name of the filesystem of the currently active
671 drive (like 'FAT' or 'NTFS'). In list context it returns three values:
672 (FSTYPE, FLAGS, MAXCOMPLEN). FSTYPE is the filesystem type as
673 before. FLAGS is a combination of values of the following table:
675 0x00000001 supports case-sensitive filenames
676 0x00000002 preserves the case of filenames
677 0x00000004 supports Unicode in filenames
678 0x00000008 preserves and enforces ACLs
679 0x00000010 supports file-based compression
680 0x00000020 supports disk quotas
681 0x00000040 supports sparse files
682 0x00000080 supports reparse points
683 0x00000100 supports remote storage
684 0x00008000 is a compressed volume (e.g. DoubleSpace)
685 0x00010000 supports object identifiers
686 0x00020000 supports the Encrypted File System (EFS)
688 MAXCOMPLEN is the maximum length of a filename component (the part
689 between two backslashes) on this file system.
691 =item Win32::FreeLibrary(HANDLE)
693 Unloads a previously loaded dynamic-link library. The HANDLE is
694 no longer valid after this call. See L<LoadLibrary|Win32::LoadLibrary(LIBNAME)>
695 for information on dynamically loading a library.
697 =item Win32::GetACP()
699 Returns the current Windows ANSI code page identifier for the operating
700 system. See also GetOEMCP(), GetConsoleCP() and GetConsoleOutputCP().
702 =item Win32::GetANSIPathName(FILENAME)
704 Returns an ANSI version of FILENAME. This may be the short name
705 if the long name cannot be represented in the system codepage.
707 While not currently implemented, it is possible that in the future
708 this function will convert only parts of the path to FILENAME to a
711 If FILENAME doesn't exist on the filesystem, or if the filesystem
712 doesn't support short ANSI filenames, then this function will
713 translate the Unicode name into the system codepage using replacement
716 =item Win32::GetArchName()
718 Use of this function is deprecated. It is equivalent with
719 $ENV{PROCESSOR_ARCHITECTURE}. This might not work on Win9X.
721 =item Win32::GetChipName()
723 Returns the processor type: 386, 486 or 586 for x86 processors, 8664
724 for the x64 processor and 2200 for the Itanium. Since it returns the
725 native processor type it will return a 64-bit processor type even when
726 called from a 32-bit Perl running on 64-bit Windows.
728 =item Win32::GetConsoleCP()
730 Returns the input code page used by the console associated with the
731 calling process. To set the console's input code page, see
732 SetConsoleCP(). See also GetConsoleOutputCP(), GetACP() and
735 =item Win32::GetConsoleOutputCP()
737 Returns the output code page used by the console associated with the
738 calling process. To set the console's output code page, see
739 SetConsoleOutputCP(). See also GetConsoleCP(), GetACP(), and
742 =item Win32::GetCwd()
744 [CORE] Returns the current active drive and directory. This function
745 does not return a UNC path, since the functionality required for such
746 a feature is not available under Windows 95.
748 If supported by the core Perl version, this function will return an
749 ANSI path name for the current directory if the long pathname cannot
750 be represented in the system codepage.
752 =item Win32::GetCurrentProcessId()
754 Returns the process identifier of the current process. Until the
755 process terminates, the process identifier uniquely identifies the
756 process throughout the system.
758 The current process identifier is normally also available via the
759 predefined $$ variable. Under fork() emulation however $$ may contain
760 a pseudo-process identifier that is only meaningful to the Perl
761 kill(), wait() and waitpid() functions. The
762 Win32::GetCurrentProcessId() function will always return the regular
763 Windows process id, even when called from inside a pseudo-process.
765 =item Win32::GetCurrentThreadId()
767 Returns the thread identifier of the calling thread. Until the thread
768 terminates, the thread identifier uniquely identifies the thread
769 throughout the system.
771 =item Win32::GetFileVersion(FILENAME)
773 Returns the file version number from the VERSIONINFO resource of
774 the executable file or DLL. This is a tuple of four 16 bit numbers.
775 In list context these four numbers will be returned. In scalar context
776 they are concatenated into a string, separated by dots.
778 =item Win32::GetFolderPath(FOLDER [, CREATE])
780 Returns the full pathname of one of the Windows special folders.
781 The folder will be created if it doesn't exist and the optional CREATE
782 argument is true. The following FOLDER constants are defined by the
783 Win32 module, but only exported on demand:
788 CSIDL_COMMON_ADMINTOOLS
790 CSIDL_COMMON_DESKTOPDIRECTORY
791 CSIDL_COMMON_DOCUMENTS
792 CSIDL_COMMON_FAVORITES
794 CSIDL_COMMON_PICTURES
795 CSIDL_COMMON_PROGRAMS
796 CSIDL_COMMON_STARTMENU
798 CSIDL_COMMON_TEMPLATES
802 CSIDL_DESKTOPDIRECTORY
817 CSIDL_PROGRAM_FILES_COMMON
820 CSIDL_RESOURCES_LOCALIZED
828 Note that not all folders are defined on all versions of Windows.
830 Please refer to the MSDN documentation of the CSIDL constants,
831 currently available at:
833 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
835 This function will return an ANSI folder path if the long name cannot
836 be represented in the system codepage. Use Win32::GetLongPathName()
837 on the result of Win32::GetFolderPath() if you want the Unicode
838 version of the folder name.
840 =item Win32::GetFullPathName(FILENAME)
842 [CORE] GetFullPathName combines the FILENAME with the current drive
843 and directory name and returns a fully qualified (aka, absolute)
844 path name. In list context it returns two elements: (PATH, FILE) where
845 PATH is the complete pathname component (including trailing backslash)
846 and FILE is just the filename part. Note that no attempt is made to
847 convert 8.3 components in the supplied FILENAME to longnames or
848 vice-versa. Compare with Win32::GetShortPathName() and
849 Win32::GetLongPathName().
851 If supported by the core Perl version, this function will return an
852 ANSI path name if the full pathname cannot be represented in the
855 =item Win32::GetLastError()
857 [CORE] Returns the last error value generated by a call to a Win32 API
858 function. Note that C<$^E> used in a numeric context amounts to the
861 =item Win32::GetLongPathName(PATHNAME)
863 [CORE] Returns a representation of PATHNAME composed of longname
864 components (if any). The result may not necessarily be longer
865 than PATHNAME. No attempt is made to convert PATHNAME to the
866 absolute path. Compare with Win32::GetShortPathName() and
867 Win32::GetFullPathName().
869 This function may return the pathname in Unicode if it cannot be
870 represented in the system codepage. Use Win32::GetANSIPathName()
871 before passing the path to a system call or another program.
873 =item Win32::GetNextAvailDrive()
875 [CORE] Returns a string in the form of "<d>:" where <d> is the first
876 available drive letter.
878 =item Win32::GetOEMCP()
880 Returns the current original equipment manufacturer (OEM) code page
881 identifier for the operating system. See also GetACP(), GetConsoleCP()
882 and GetConsoleOutputCP().
884 =item Win32::GetOSDisplayName()
886 Returns the "marketing" name of the Windows operating system version
887 being used. It returns names like these (random samples):
889 Windows 2000 Datacenter Server
890 Windows XP Professional
891 Windows XP Tablet PC Edition
893 Windows Server 2003 Enterprise Edition for Itanium-based Systems
894 Windows Vista Ultimate (32-bit)
895 Windows Small Business Server 2008 R2 (64-bit)
897 The display name describes the native Windows version, so even on a
898 32-bit Perl this function may return a "Windows ... (64-bit)" name
899 when running on a 64-bit Windows.
901 This function should only be used to display the actual OS name to the
902 user; it should not be used to determine the class of operating systems
903 this system belongs to. The Win32::GetOSName(), Win32::GetOSVersion,
904 Win32::GetProductInfo() and Win32::GetSystemMetrics() functions provide
905 the base information to check for certain capabilities, or for families
908 =item Win32::GetOSName()
910 In scalar context returns the name of the Win32 operating system
911 being used. In list context returns a two element list of the OS name
912 and whatever edition information is known about the particular build
913 (for Win9X boxes) and whatever service packs have been installed.
914 The latter is roughly equivalent to the first item returned by
915 GetOSVersion() in list context.
917 The description will also include tags for other special editions,
918 like "R2", "Media Center", "Tablet PC", or "Starter Edition".
920 Currently the possible values for the OS name are
936 This routine is just a simple interface into GetOSVersion(). More
937 specific or demanding situations should use that instead. Another
938 option would be to use POSIX::uname(), however the latter appears to
939 report only the OS family name and not the specific OS. In scalar
940 context it returns just the ID.
942 The name "WinXP/.Net" is used for historical reasons only, to maintain
943 backwards compatibility of the Win32 module. Windows .NET Server has
944 been renamed as Windows 2003 Server before final release and uses a
945 different major/minor version number than Windows XP.
947 Similarly the name "WinWin32s" should have been "Win32s" but has been
948 kept as-is for backwards compatibility reasons too.
950 =item Win32::GetOSVersion()
952 [CORE] Returns the list (STRING, MAJOR, MINOR, BUILD, ID), where the
953 elements are, respectively: An arbitrary descriptive string, the major
954 version number of the operating system, the minor version number, the
955 build number, and a digit indicating the actual operating system.
956 For the ID, the values are 0 for Win32s, 1 for Windows 9X/Me and 2 for
957 Windows NT/2000/XP/2003/Vista/2008/7. In scalar context it returns just
960 Currently known values for ID MAJOR and MINOR are as follows:
968 Windows NT 3.51 2 3 51
973 Windows Server 2003 2 5 2
974 Windows Server 2003 R2 2 5 2
975 Windows Home Server 2 5 2
978 Windows Server 2008 2 6 0
980 Windows Server 2008 R2 2 6 1
982 Windows Server 2012 2 6 2
984 On Windows NT 4 SP6 and later this function returns the following
985 additional values: SPMAJOR, SPMINOR, SUITEMASK, PRODUCTTYPE.
987 The version numbers for Windows 2003 and Windows Home Server are
988 identical; the SUITEMASK field must be used to differentiate between\
991 The version numbers for Windows Vista and Windows Server 2008 are
992 identical; the PRODUCTTYPE field must be used to differentiate between
995 The version numbers for Windows 7 and Windows Server 2008 R2 are
996 identical; the PRODUCTTYPE field must be used to differentiate between
999 The version numbers for Windows 8 and Windows Server 2012 are
1000 identical; the PRODUCTTYPE field must be used to differentiate between
1003 SPMAJOR and SPMINOR are are the version numbers of the latest
1004 installed service pack.
1006 SUITEMASK is a bitfield identifying the product suites available on
1007 the system. Known bits are:
1009 VER_SUITE_SMALLBUSINESS 0x00000001
1010 VER_SUITE_ENTERPRISE 0x00000002
1011 VER_SUITE_BACKOFFICE 0x00000004
1012 VER_SUITE_COMMUNICATIONS 0x00000008
1013 VER_SUITE_TERMINAL 0x00000010
1014 VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020
1015 VER_SUITE_EMBEDDEDNT 0x00000040
1016 VER_SUITE_DATACENTER 0x00000080
1017 VER_SUITE_SINGLEUSERTS 0x00000100
1018 VER_SUITE_PERSONAL 0x00000200
1019 VER_SUITE_BLADE 0x00000400
1020 VER_SUITE_EMBEDDED_RESTRICTED 0x00000800
1021 VER_SUITE_SECURITY_APPLIANCE 0x00001000
1022 VER_SUITE_STORAGE_SERVER 0x00002000
1023 VER_SUITE_COMPUTE_SERVER 0x00004000
1024 VER_SUITE_WH_SERVER 0x00008000
1026 The VER_SUITE_xxx names are listed here to crossreference the Microsoft
1027 documentation. The Win32 module does not provide symbolic names for these
1030 PRODUCTTYPE provides additional information about the system. It should
1031 be one of the following integer values:
1033 1 - Workstation (NT 4, 2000 Pro, XP Home, XP Pro, Vista, etc)
1034 2 - Domaincontroller
1035 3 - Server (2000 Server, Server 2003, Server 2008, etc)
1037 Note that a server that is also a domain controller is reported as
1038 PRODUCTTYPE 2 (Domaincontroller) and not PRODUCTTYPE 3 (Server).
1040 =item Win32::GetShortPathName(PATHNAME)
1042 [CORE] Returns a representation of PATHNAME that is composed of short
1043 (8.3) path components where available. For path components where the
1044 file system has not generated the short form the returned path will
1045 use the long form, so this function might still for instance return a
1046 path containing spaces. Returns C<undef> when the PATHNAME does not
1047 exist. Compare with Win32::GetFullPathName() and
1048 Win32::GetLongPathName().
1050 =item Win32::GetSystemMetrics(INDEX)
1052 Retrieves the specified system metric or system configuration setting.
1053 Please refer to the Microsoft documentation of the GetSystemMetrics()
1054 function for a reference of available INDEX values. All system
1055 metrics return integer values.
1057 =item Win32::GetProcAddress(INSTANCE, PROCNAME)
1059 Returns the address of a function inside a loaded library. The
1060 information about what you can do with this address has been lost in
1061 the mist of time. Use the Win32::API module instead of this deprecated
1064 =item Win32::GetProductInfo(OSMAJOR, OSMINOR, SPMAJOR, SPMINOR)
1066 Retrieves the product type for the operating system on the local
1067 computer, and maps the type to the product types supported by the
1068 specified operating system. Please refer to the Microsoft
1069 documentation of the GetProductInfo() function for more information
1070 about the parameters and return value. This function requires Windows
1073 See also the Win32::GetOSName() and Win32::GetOSDisplayName()
1074 functions which provide a higher level abstraction of the data
1075 returned by this function.
1077 =item Win32::GetTickCount()
1079 [CORE] Returns the number of milliseconds elapsed since the last
1080 system boot. Resolution is limited to system timer ticks (about 10ms
1081 on WinNT and 55ms on Win9X).
1083 =item Win32::GuidGen()
1085 Creates a globally unique 128 bit integer that can be used as a
1086 persistent identifier in a distributed setting. To a very high degree
1087 of certainty this function returns a unique value. No other
1088 invocation, on the same or any other system (networked or not), should
1089 return the same value.
1091 The return value is formatted according to OLE conventions, as groups
1092 of hex digits with surrounding braces. For example:
1094 {09531CF1-D0C7-4860-840C-1C8C8735E2AD}
1096 =item Win32::InitiateSystemShutdown
1098 (MACHINE, MESSAGE, TIMEOUT, FORCECLOSE, REBOOT)
1100 Shutsdown the specified MACHINE, notifying users with the
1101 supplied MESSAGE, within the specified TIMEOUT interval. Forces
1102 closing of all documents without prompting the user if FORCECLOSE is
1103 true, and reboots the machine if REBOOT is true. This function works
1106 =item Win32::IsAdminUser()
1108 Returns non zero if the account in whose security context the
1109 current process/thread is running belongs to the local group of
1110 Administrators in the built-in system domain; returns 0 if not.
1111 On Windows Vista it will only return non-zero if the process is
1112 actually running with elevated privileges. Returns C<undef>
1113 and prints a warning if an error occurred. This function always
1116 =item Win32::IsWinNT()
1118 [CORE] Returns non zero if the Win32 subsystem is Windows NT.
1120 =item Win32::IsWin95()
1122 [CORE] Returns non zero if the Win32 subsystem is Windows 95.
1124 =item Win32::LoadLibrary(LIBNAME)
1126 Loads a dynamic link library into memory and returns its module
1127 handle. This handle can be used with Win32::GetProcAddress() and
1128 Win32::FreeLibrary(). This function is deprecated. Use the Win32::API
1131 =item Win32::LoginName()
1133 [CORE] Returns the username of the owner of the current perl process.
1134 The return value may be a Unicode string.
1136 =item Win32::LookupAccountName(SYSTEM, ACCOUNT, DOMAIN, SID, SIDTYPE)
1138 Looks up ACCOUNT on SYSTEM and returns the domain name the SID and
1141 =item Win32::LookupAccountSID(SYSTEM, SID, ACCOUNT, DOMAIN, SIDTYPE)
1143 Looks up SID on SYSTEM and returns the account name, domain name,
1146 =item Win32::MsgBox(MESSAGE [, FLAGS [, TITLE]])
1148 Create a dialogbox containing MESSAGE. FLAGS specifies the
1149 required icon and buttons according to the following table:
1153 2 = Abort, Retry, and Ignore
1154 3 = Yes, No and Cancel
1156 5 = Retry and Cancel
1158 MB_ICONSTOP "X" in a red circle
1159 MB_ICONQUESTION question mark in a bubble
1160 MB_ICONEXCLAMATION exclamation mark in a yellow triangle
1161 MB_ICONINFORMATION "i" in a bubble
1163 TITLE specifies an optional window title. The default is "Perl".
1165 The function returns the menu id of the selected push button:
1177 =item Win32::NodeName()
1179 [CORE] Returns the Microsoft Network node-name of the current machine.
1181 =item Win32::OutputDebugString(STRING)
1183 Sends a string to the application or system debugger for display.
1184 The function does nothing if there is no active debugger.
1186 Alternatively one can use the I<Debug Viewer> application to
1187 watch the OutputDebugString() output:
1189 http://www.microsoft.com/technet/sysinternals/utilities/debugview.mspx
1191 =item Win32::RegisterServer(LIBRARYNAME)
1193 Loads the DLL LIBRARYNAME and calls the function DllRegisterServer.
1195 =item Win32::SetChildShowWindow(SHOWWINDOW)
1197 [CORE] Sets the I<ShowMode> of child processes started by system().
1198 By default system() will create a new console window for child
1199 processes if Perl itself is not running from a console. Calling
1200 SetChildShowWindow(0) will make these new console windows invisible.
1201 Calling SetChildShowWindow() without arguments reverts system() to the
1202 default behavior. The return value of SetChildShowWindow() is the
1203 previous setting or C<undef>.
1205 The following symbolic constants for SHOWWINDOW are available
1206 (but not exported) from the Win32 module: SW_HIDE, SW_SHOWNORMAL,
1207 SW_SHOWMINIMIZED, SW_SHOWMAXIMIZED and SW_SHOWNOACTIVATE.
1209 =item Win32::SetConsoleCP(ID)
1211 Sets the input code page used by the console associated with the
1212 calling process. The return value of SetConsoleCP() is nonzero on
1213 success or zero on failure. To get the console's input code page, see
1216 =item Win32::SetConsoleOutputCP(ID)
1218 Sets the output code page used by the console associated with the
1219 calling process. The return value of SetConsoleOutputCP() is nonzero on
1220 success or zero on failure. To get the console's output code page, see
1221 GetConsoleOutputCP().
1223 =item Win32::SetCwd(NEWDIRECTORY)
1225 [CORE] Sets the current active drive and directory. This function does not
1226 work with UNC paths, since the functionality required to required for
1227 such a feature is not available under Windows 95.
1229 =item Win32::SetLastError(ERROR)
1231 [CORE] Sets the value of the last error encountered to ERROR. This is
1232 that value that will be returned by the Win32::GetLastError()
1235 =item Win32::Sleep(TIME)
1237 [CORE] Pauses for TIME milliseconds. The timeslices are made available
1238 to other processes and threads.
1240 =item Win32::Spawn(COMMAND, ARGS, PID)
1242 [CORE] Spawns a new process using the supplied COMMAND, passing in
1243 arguments in the string ARGS. The pid of the new process is stored in
1244 PID. This function is deprecated. Please use the Win32::Process module
1247 =item Win32::UnregisterServer(LIBRARYNAME)
1249 Loads the DLL LIBRARYNAME and calls the function
1250 DllUnregisterServer.