Win32


Over in the Forums (http://www.roth.net/forums) a question was asked about converting VBScript into Perl. This reminded me of a question that I am still frequently asked about: how do you use COM objects in Perl? It just so happens that we have a PowerPoint presentation that I gave at the 2000 Perl Conference on this very subject: http://www.roth.net/conference/perl/2000/Perl2000.ppt

In brief, a Perl script can interact with most COM objects. This is done using the Win32::OLE extension which comes as part of Activestate’s Win32 Perl. There is experimental support for COM eventing but it has unfortunately been experimental for several versions now.

One of the annoyances that Win32 Perl bothers me with is the lack of traversing the PATH. There are some Win32 specific functions built in such as Win32::GetFullPathName() and Win32::ExpandEnvironmentStrings() which are very useful when dealing with Windows’ paths, but suck when dealing with a PATH relative file.
For example, if you have a path like "rundll32.exe" there is no way for Perl to easily determine that this represents c:\Windows\System32\RunnDll32.exe. This should be pretty simple to do since "%SystemRoot%\System32" listed in the PATH variable by default. The closest Win32 Perl comes to solving this is to use Win32::GetFullPathName(), but this would prefix the file with a path based on the current working directory (from Win32::GetCWD()), not traverse the PATH looking for a file match.
It is too bad that there isn’t a simple solution to this. However, until the day when such functionality is added to Win32 Perl you can use the script in our Perl Script Repository called FindInPath.pl which does traverse the PATH looking for files: http://www.roth.net/perl/scripts/scripts.asp?FindInPath.pl

« Previous Page