Error checking example (Perl)

This code can be found in Chapter 1 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# Adapted from VBScript code contained in the book:
#      "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0

use Win32::OLE;
$Win32::OLE::Warn = 3;

use strict;

my $objDomain;
$objDomain = Win32::OLE->GetObject('LDAP://cn=users,dc=rallencorp,dc=com');
if ( Win32::OLE::LastError()) {
    print 'An error occured getting the domain object: ' . ('' . Win32::OLE::LastError()), "\n";
    exit 0;
}
my $strDescr;
$strDescr = $objDomain->Get('description');
if (Win32::OLE::LastError()) {
    print 'An error occured getting the description: ' . ('' . Win32::OLE::LastError()), "\n";
    exit 0;
}
print 'Description: ' . $strDescr, "\n";
undef $objDomain ;
undef $strDescr ;

This code has been viewed 1391 times.

New from the creators of TechTasks.com: StatSheet.com