Running a command with Exec (Perl)
This code can be found in
Chapter 11 of Windows Server 2003 Security 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.
use Win32::OLE;
$strServer = '';
$strCommand = 'netsh dhcp server ' . $strServer . ' set auditlog d:\\dhcp\\audit';
print "Running command: $strCommand\n";
print "\n";
$objShell = Win32::OLE->new('Wscript.Shell');
$objProc = $objShell->Exec($strCommand);
do {
select(undef, undef, undef, 100 / 1000.0);
} until ($objProc->Status != 0);
if ($objProc->ExitCode != 0) {
print 'EXIT CODE: ' . $objProc->ExitCode, "\n";
print 'ERROR: ' . $objProc->StdErr->ReadAll, "\n";
}
print 'OUTPUT: ' . $objProc->StdOut->ReadAll, "\n";
|
This code has been viewed 2400 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|