5 use vars qw|$VERSION @ISA @EXPORT @EXPORT_OK|;
10 @ISA = qw|Exporter DynaLoader|;
16 OWNER_SECURITY_INFORMATION
17 GROUP_SECURITY_INFORMATION
18 DACL_SECURITY_INFORMATION
19 SACL_SECURITY_INFORMATION
47 CSIDL_DESKTOPDIRECTORY
51 CSIDL_COMMON_STARTMENU
54 CSIDL_COMMON_DESKTOPDIRECTORY
58 CSIDL_COMMON_FAVORITES
68 CSIDL_PROGRAM_FILES_COMMON
69 CSIDL_COMMON_TEMPLATES
70 CSIDL_COMMON_DOCUMENTS
71 CSIDL_COMMON_ADMINTOOLS
77 CSIDL_RESOURCES_LOCALIZED
82 # Routines available in core:
90 # Win32::FormatMessage ERRORCODE
91 # Win32::Spawn COMMAND, ARGS, PID
96 # We won't bother with the constant stuff, too much of a hassle. Just hard
100 sub WIN31_CLASS { &NULL }
102 sub OWNER_SECURITY_INFORMATION { 0x00000001 }
103 sub GROUP_SECURITY_INFORMATION { 0x00000002 }
104 sub DACL_SECURITY_INFORMATION { 0x00000004 }
105 sub SACL_SECURITY_INFORMATION { 0x00000008 }
107 sub MB_ICONHAND { 0x00000010 }
108 sub MB_ICONQUESTION { 0x00000020 }
109 sub MB_ICONEXCLAMATION { 0x00000030 }
110 sub MB_ICONASTERISK { 0x00000040 }
111 sub MB_ICONWARNING { 0x00000030 }
112 sub MB_ICONERROR { 0x00000010 }
113 sub MB_ICONINFORMATION { 0x00000040 }
114 sub MB_ICONSTOP { 0x00000010 }
117 # Newly added constants. These have an empty prototype, unlike the
118 # the ones above, which aren't prototyped for compatibility reasons.
121 sub SW_SHOWNORMAL () { 1 }
122 sub SW_SHOWMINIMIZED () { 2 }
123 sub SW_SHOWMAXIMIZED () { 3 }
124 sub SW_SHOWNOACTIVATE () { 4 }
126 sub CSIDL_DESKTOP () { 0x0000 } # <desktop>
127 sub CSIDL_PROGRAMS () { 0x0002 } # Start Menu\Programs
128 sub CSIDL_PERSONAL () { 0x0005 } # "My Documents" folder
129 sub CSIDL_FAVORITES () { 0x0006 } # <user name>\Favorites
130 sub CSIDL_STARTUP () { 0x0007 } # Start Menu\Programs\Startup
131 sub CSIDL_RECENT () { 0x0008 } # <user name>\Recent
132 sub CSIDL_SENDTO () { 0x0009 } # <user name>\SendTo
133 sub CSIDL_STARTMENU () { 0x000B } # <user name>\Start Menu
134 sub CSIDL_MYMUSIC () { 0x000D } # "My Music" folder
135 sub CSIDL_MYVIDEO () { 0x000E } # "My Videos" folder
136 sub CSIDL_DESKTOPDIRECTORY () { 0x0010 } # <user name>\Desktop
137 sub CSIDL_NETHOOD () { 0x0013 } # <user name>\nethood
138 sub CSIDL_FONTS () { 0x0014 } # windows\fonts
139 sub CSIDL_TEMPLATES () { 0x0015 }
140 sub CSIDL_COMMON_STARTMENU () { 0x0016 } # All Users\Start Menu
141 sub CSIDL_COMMON_PROGRAMS () { 0x0017 } # All Users\Start Menu\Programs
142 sub CSIDL_COMMON_STARTUP () { 0x0018 } # All Users\Startup
143 sub CSIDL_COMMON_DESKTOPDIRECTORY () { 0x0019 } # All Users\Desktop
144 sub CSIDL_APPDATA () { 0x001A } # Application Data, new for NT4
145 sub CSIDL_PRINTHOOD () { 0x001B } # <user name>\PrintHood
146 sub CSIDL_LOCAL_APPDATA () { 0x001C } # non roaming, user\Local Settings\Application Data
147 sub CSIDL_COMMON_FAVORITES () { 0x001F }
148 sub CSIDL_INTERNET_CACHE () { 0x0020 }
149 sub CSIDL_COOKIES () { 0x0021 }
150 sub CSIDL_HISTORY () { 0x0022 }
151 sub CSIDL_COMMON_APPDATA () { 0x0023 } # All Users\Application Data
152 sub CSIDL_WINDOWS () { 0x0024 } # GetWindowsDirectory()
153 sub CSIDL_SYSTEM () { 0x0025 } # GetSystemDirectory()
154 sub CSIDL_PROGRAM_FILES () { 0x0026 } # C:\Program Files
155 sub CSIDL_MYPICTURES () { 0x0027 } # "My Pictures", new for Win2K
156 sub CSIDL_PROFILE () { 0x0028 } # USERPROFILE
157 sub CSIDL_PROGRAM_FILES_COMMON () { 0x002B } # C:\Program Files\Common
158 sub CSIDL_COMMON_TEMPLATES () { 0x002D } # All Users\Templates
159 sub CSIDL_COMMON_DOCUMENTS () { 0x002E } # All Users\Documents
160 sub CSIDL_COMMON_ADMINTOOLS () { 0x002F } # All Users\Start Menu\Programs\Administrative Tools
161 sub CSIDL_ADMINTOOLS () { 0x0030 } # <user name>\Start Menu\Programs\Administrative Tools
162 sub CSIDL_COMMON_MUSIC () { 0x0035 } # All Users\My Music
163 sub CSIDL_COMMON_PICTURES () { 0x0036 } # All Users\My Pictures
164 sub CSIDL_COMMON_VIDEO () { 0x0037 } # All Users\My Video
165 sub CSIDL_RESOURCES () { 0x0038 } # %windir%\Resources\, For theme and other windows resources.
166 sub CSIDL_RESOURCES_LOCALIZED () { 0x0039 } # %windir%\Resources\<LangID>, for theme and other windows specific resources.
167 sub CSIDL_CDBURN_AREA () { 0x003B } # <user name>\Local Settings\Application Data\Microsoft\CD Burning
169 ### This method is just a simple interface into GetOSVersion(). More
170 ### specific or demanding situations should use that instead.
172 my ($found_os, $found_desc);
175 my ($os,$desc,$major, $minor, $build, $id)=("","");
176 unless (defined $found_os) {
177 # If we have a run this already, we have the results cached
180 # Use the standard API call to determine the version
181 ($desc, $major, $minor, $build, $id) = Win32::GetOSVersion();
183 # If id==0 then its a win32s box -- Meaning Win3.11
188 # Magic numbers from MSDN documentation of OSVERSIONINFO
189 # Most version names can be parsed from just the id and minor
206 # This _really_ shouldnt happen. At least not for quite a while
207 # Politely warn and return undef
208 unless (defined $os) {
209 warn qq[Windows version [$id:$major:$minor] unknown!];
215 # But distinguising W2k and Vista from NT4 requires looking at the major version
217 $os = {5 => "2000", 6 => "Vista"}->{$major} || "NT4";
220 # For the rest we take a look at the build numbers and try to deduce
221 # the exact release name, but we put that in the $desc
222 elsif ($os eq "95") {
223 if ($build eq '67109814') {
226 elsif ($build eq '67306684') {
229 elsif ($build eq '67109975') {
233 elsif ($os eq "98" && $build eq '67766446') {
239 $desc = "$tag $desc";
246 # cache the results, so we dont have to do this again
247 $found_os = "Win$os";
251 return wantarray ? ($found_os, $found_desc) : $found_os;
262 Win32 - Interfaces to some Win32 API Functions
266 The Win32 module contains functions to access Win32 APIs.
268 =head2 Alphabetical Listing of Win32 Functions
270 It is recommended to C<use Win32;> before any of these functions;
271 however, for backwards compatibility, those marked as [CORE] will
272 automatically do this for you.
276 =item Win32::AbortSystemShutdown(MACHINE)
278 Aborts a system shutdown (started by the
279 InitiateSystemShutdown function) on the specified MACHINE.
281 =item Win32::BuildNumber()
283 [CORE] Returns the ActivePerl build number. This function is
284 only available in the ActivePerl binary distribution.
286 =item Win32::CopyFile(FROM, TO, OVERWRITE)
288 [CORE] The Win32::CopyFile() function copies an existing file to a new
289 file. All file information like creation time and file attributes will
290 be copied to the new file. However it will B<not> copy the security
291 information. If the destination file already exists it will only be
292 overwritten when the OVERWRITE parameter is true. But even this will
293 not overwrite a read-only file; you have to unlink() it first
296 =item Win32::DomainName()
298 [CORE] Returns the name of the Microsoft Network domain that the
299 owner of the current perl process is logged into. This function does
300 B<not> work on Windows 9x.
302 =item Win32::ExpandEnvironmentStrings(STRING)
304 Takes STRING and replaces all referenced environment variable
305 names with their defined values. References to environment variables
306 take the form C<%VariableName%>. Case is ignored when looking up the
307 VariableName in the environment. If the variable is not found then the
308 original C<%VariableName%> text is retained. Has the same effect
311 $string =~ s/%([^%]*)%/$ENV{$1} || "%$1%"/eg
313 =item Win32::FormatMessage(ERRORCODE)
315 [CORE] Converts the supplied Win32 error number (e.g. returned by
316 Win32::GetLastError()) to a descriptive string. Analogous to the
317 perror() standard-C library function. Note that C<$^E> used
318 in a string context has much the same effect.
320 C:\> perl -e "$^E = 26; print $^E;"
321 The specified disk or diskette cannot be accessed
323 =item Win32::FsType()
325 [CORE] Returns the name of the filesystem of the currently active
326 drive (like 'FAT' or 'NTFS'). In list context it returns three values:
327 (FSTYPE, FLAGS, MAXCOMPLEN). FSTYPE is the filesystem type as
328 before. FLAGS is a combination of values of the following table:
330 0x00000001 supports case-sensitive filenames
331 0x00000002 preserves the case of filenames
332 0x00000004 supports Unicode in filenames
333 0x00000008 preserves and enforces ACLs
334 0x00000010 supports file-based compression
335 0x00000020 supports disk quotas
336 0x00000040 supports sparse files
337 0x00000080 supports reparse points
338 0x00000100 supports remote storage
339 0x00008000 is a compressed volume (e.g. DoubleSpace)
340 0x00010000 supports object identifiers
341 0x00020000 supports the Encrypted File System (EFS)
343 MAXCOMPLEN is the maximum length of a filename component (the part
344 between two backslashes) on this file system.
346 =item Win32::FreeLibrary(HANDLE)
348 Unloads a previously loaded dynamic-link library. The HANDLE is
349 no longer valid after this call. See L<LoadLibrary|Win32::LoadLibrary(LIBNAME)>
350 for information on dynamically loading a library.
352 =item Win32::GetArchName()
354 Use of this function is deprecated. It is equivalent with
355 $ENV{PROCESSOR_ARCHITECTURE}. This might not work on Win9X.
357 =item Win32::GetChipName()
359 Returns the processor type: 386, 486 or 586 for Intel processors,
360 21064 for the Alpha chip.
362 =item Win32::GetCwd()
364 [CORE] Returns the current active drive and directory. This function
365 does not return a UNC path, since the functionality required for such
366 a feature is not available under Windows 95.
368 =item Win32::GetFileVersion(FILENAME)
370 Returns the file version number from the VERSIONINFO resource of
371 the executable file or DLL. This is a tuple of four 16 bit numbers.
372 In list context these four numbers will be returned. In scalar context
373 they are concatenated into a string, separated by dots.
375 =item Win32::GetFolderPath(FOLDER [, CREATE])
377 Returns the full pathname of one of the Windows special folders.
378 The folder will be created if it doesn't exist and the optional CREATE
379 argument is true. The following FOLDER constants are defined by the
380 Win32 module, but only exported on demand:
385 CSIDL_COMMON_ADMINTOOLS
387 CSIDL_COMMON_DESKTOPDIRECTORY
388 CSIDL_COMMON_DOCUMENTS
389 CSIDL_COMMON_FAVORITES
391 CSIDL_COMMON_PICTURES
392 CSIDL_COMMON_PROGRAMS
393 CSIDL_COMMON_STARTMENU
395 CSIDL_COMMON_TEMPLATES
399 CSIDL_DESKTOPDIRECTORY
414 CSIDL_PROGRAM_FILES_COMMON
417 CSIDL_RESOURCES_LOCALIZED
425 Note that not all folders are defined on all versions of Windows.
427 Please refer to the MSDN documentation of the CSIDL constants,
428 currently available at:
430 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
432 =item Win32::GetFullPathName(FILENAME)
434 [CORE] GetFullPathName combines the FILENAME with the current drive
435 and directory name and returns a fully qualified (aka, absolute)
436 path name. In list context it returns two elements: (PATH, FILE) where
437 PATH is the complete pathname component (including trailing backslash)
438 and FILE is just the filename part. Note that no attempt is made to
439 convert 8.3 components in the supplied FILENAME to longnames or
440 vice-versa. Compare with Win32::GetShortPathName and
441 Win32::GetLongPathName.
443 =item Win32::GetLastError()
445 [CORE] Returns the last error value generated by a call to a Win32 API
446 function. Note that C<$^E> used in a numeric context amounts to the
449 =item Win32::GetLongPathName(PATHNAME)
451 [CORE] Returns a representation of PATHNAME composed of longname
452 components (if any). The result may not necessarily be longer
453 than PATHNAME. No attempt is made to convert PATHNAME to the
454 absolute path. Compare with Win32::GetShortPathName and
455 Win32::GetFullPathName.
457 =item Win32::GetNextAvailDrive()
459 [CORE] Returns a string in the form of "<d>:" where <d> is the first
460 available drive letter.
462 =item Win32::GetOSVersion()
464 [CORE] Returns the list (STRING, MAJOR, MINOR, BUILD, ID), where the
465 elements are, respectively: An arbitrary descriptive string, the major
466 version number of the operating system, the minor version number, the
467 build number, and a digit indicating the actual operating system.
468 For the ID, the values are 0 for Win32s, 1 for Windows 9X/Me and 2 for
469 Windows NT/2000/XP/2003. In scalar context it returns just the ID.
471 Currently known values for ID MAJOR and MINOR are as follows:
478 Windows NT 3.51 2 3 51
482 Windows Server 2003 2 5 2
485 On Windows NT 4 SP6 and later this function returns the following
486 additional values: SPMAJOR, SPMINOR, SUITEMASK, PRODUCTTYPE.
488 SPMAJOR and SPMINOR are are the version numbers of the latest
489 installed service pack.
491 SUITEMASK is a bitfield identifying the product suites available on
492 the system. Known bits are:
494 VER_SUITE_SMALLBUSINESS 0x00000001
495 VER_SUITE_ENTERPRISE 0x00000002
496 VER_SUITE_BACKOFFICE 0x00000004
497 VER_SUITE_COMMUNICATIONS 0x00000008
498 VER_SUITE_TERMINAL 0x00000010
499 VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020
500 VER_SUITE_EMBEDDEDNT 0x00000040
501 VER_SUITE_DATACENTER 0x00000080
502 VER_SUITE_SINGLEUSERTS 0x00000100
503 VER_SUITE_PERSONAL 0x00000200
504 VER_SUITE_BLADE 0x00000400
505 VER_SUITE_EMBEDDED_RESTRICTED 0x00000800
506 VER_SUITE_SECURITY_APPLIANCE 0x00001000
508 The VER_SUITE_xxx names are listed here to crossreference the Microsoft
509 documentation. The Win32 module does not provide symbolic names for these
512 PRODUCTTYPE provides additional information about the system. It should
513 be one of the following integer values:
515 1 - Workstation (NT 4, 2000 Pro, XP Home, XP Pro)
519 =item Win32::GetOSName()
521 In scalar context returns the name of the Win32 operating system
522 being used. In list context returns a two element list of the OS name
523 and whatever edition information is known about the particular build
524 (for Win9X boxes) and whatever service packs have been installed.
525 The latter is roughly equivalent to the first item returned by
526 GetOSVersion() in list context.
528 Currently the possible values for the OS name are
530 Win32s Win95 Win98 WinMe WinNT3.51 WinNT4 Win2000 WinXP/.Net Win2003
532 This routine is just a simple interface into GetOSVersion(). More
533 specific or demanding situations should use that instead. Another
534 option would be to use POSIX::uname(), however the latter appears to
535 report only the OS family name and not the specific OS. In scalar
536 context it returns just the ID.
538 The name "WinXP/.Net" is used for historical reasons only, to maintain
539 backwards compatibility of the Win32 module. Windows .NET Server has
540 been renamed as Windows 2003 Server before final release and uses a
541 different major/minor version number than Windows XP.
543 =item Win32::GetShortPathName(PATHNAME)
545 [CORE] Returns a representation of PATHNAME that is composed of short
546 (8.3) path components where available. For path components where the
547 file system has not generated the short form the returned path will
548 use the long form, so this function might still for instance return a
549 path containing spaces. Compare with Win32::GetFullPathName and
550 Win32::GetLongPathName.
552 =item Win32::GetProcAddress(INSTANCE, PROCNAME)
554 Returns the address of a function inside a loaded library. The
555 information about what you can do with this address has been lost in
556 the mist of time. Use the Win32::API module instead of this deprecated
559 =item Win32::GetTickCount()
561 [CORE] Returns the number of milliseconds elapsed since the last
562 system boot. Resolution is limited to system timer ticks (about 10ms
563 on WinNT and 55ms on Win9X).
565 =item Win32::GuidGen()
567 Creates a globally unique 128 bit integer that can be used as a
568 persistent identifier in a distributed setting. To a very high degree
569 of certainty this function returns a unique value. No other
570 invocation, on the same or any other system (networked or not), should
571 return the same value.
573 The return value is formatted according to OLE conventions, as groups
574 of hex digits with surrounding braces. For example:
576 {09531CF1-D0C7-4860-840C-1C8C8735E2AD}
578 =item Win32::InitiateSystemShutdown
580 (MACHINE, MESSAGE, TIMEOUT, FORCECLOSE, REBOOT)
582 Shutsdown the specified MACHINE, notifying users with the
583 supplied MESSAGE, within the specified TIMEOUT interval. Forces
584 closing of all documents without prompting the user if FORCECLOSE is
585 true, and reboots the machine if REBOOT is true. This function works
588 =item Win32::IsAdminUser()
590 Returns non zero if the account in whose security context the
591 current process/thread is running belongs to the local group of
592 Administrators in the built-in system domain; returns 0 if not.
593 Returns the undefined value and prints a warning if an error occurred.
594 This function always returns 1 on Win9X.
596 =item Win32::IsWinNT()
598 [CORE] Returns non zero if the Win32 subsystem is Windows NT.
600 =item Win32::IsWin95()
602 [CORE] Returns non zero if the Win32 subsystem is Windows 95.
604 =item Win32::LoadLibrary(LIBNAME)
606 Loads a dynamic link library into memory and returns its module
607 handle. This handle can be used with Win32::GetProcAddress and
608 Win32::FreeLibrary. This function is deprecated. Use the Win32::API
611 =item Win32::LoginName()
613 [CORE] Returns the username of the owner of the current perl process.
615 =item Win32::LookupAccountName(SYSTEM, ACCOUNT, DOMAIN, SID, SIDTYPE)
617 Looks up ACCOUNT on SYSTEM and returns the domain name the SID and
620 =item Win32::LookupAccountSID(SYSTEM, SID, ACCOUNT, DOMAIN, SIDTYPE)
622 Looks up SID on SYSTEM and returns the account name, domain name,
625 =item Win32::MsgBox(MESSAGE [, FLAGS [, TITLE]])
627 Create a dialogbox containing MESSAGE. FLAGS specifies the
628 required icon and buttons according to the following table:
632 2 = Abort, Retry, and Ignore
633 3 = Yes, No and Cancel
637 MB_ICONSTOP "X" in a red circle
638 MB_ICONQUESTION question mark in a bubble
639 MB_ICONEXCLAMATION exclamation mark in a yellow triangle
640 MB_ICONINFORMATION "i" in a bubble
642 TITLE specifies an optional window title. The default is "Perl".
644 The function returns the menu id of the selected push button:
656 =item Win32::NodeName()
658 [CORE] Returns the Microsoft Network node-name of the current machine.
660 =item Win32::RegisterServer(LIBRARYNAME)
662 Loads the DLL LIBRARYNAME and calls the function DllRegisterServer.
664 =item Win32::SetChildShowWindow(SHOWWINDOW)
666 [CORE] Sets the I<ShowMode> of child processes started by system().
667 By default system() will create a new console window for child
668 processes if Perl itself is not running from a console. Calling
669 SetChildShowWindow(0) will make these new console windows invisible.
670 Calling SetChildShowWindow() without arguments reverts system() to the
671 default behavior. The return value of SetChildShowWindow() is the
672 previous setting or C<undef>. This function is only available in
673 MSWin32 builds of perl.
675 The following symbolic constants for SHOWWINDOW are available
676 (but not exported) from the Win32 module: SW_HIDE, SW_SHOWNORMAL,
677 SW_SHOWMINIMIZED, SW_SHOWMAXIMIZED and SW_SHOWNOACTIVATE.
679 =item Win32::SetCwd(NEWDIRECTORY)
681 [CORE] Sets the current active drive and directory. This function does not
682 work with UNC paths, since the functionality required to required for
683 such a feature is not available under Windows 95.
685 =item Win32::SetLastError(ERROR)
687 [CORE] Sets the value of the last error encountered to ERROR. This is
688 that value that will be returned by the Win32::GetLastError()
691 =item Win32::Sleep(TIME)
693 [CORE] Pauses for TIME milliseconds. The timeslices are made available
694 to other processes and threads.
696 =item Win32::Spawn(COMMAND, ARGS, PID)
698 [CORE] Spawns a new process using the supplied COMMAND, passing in
699 arguments in the string ARGS. The pid of the new process is stored in
700 PID. This function is deprecated. Please use the Win32::Process module
703 =item Win32::UnregisterServer(LIBRARYNAME)
705 Loads the DLL LIBRARYNAME and calls the function