Configure remote control (Perl)

This code can be found in Chapter 17 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.

# This code configures the RemoteControl setting of a Terminal session.
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

use constant DISABLE => 0;
use constant ENABLE_INPUT_NOTIFY => 1;
use constant ENABLE_INPUT_NO_NOTIFY => 2;
use constant ENABLE_NO_INPUT_NOTIFY => 3;
use constant ENABLE_NO_INPUT_NO_NOTIFY => 4;

$strComputer = '.';
$intSetting = ENABLE_NO_INPUT_NO_NOTIFY;
$strTerminal = 'RDP-Tcp';
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colItems = $objWMI->ExecQuery('Select * from Win32_TSRemoteControlSetting Where ' . ' TerminalName = \'' . $strTerminal . '\'');
foreach my $objItem (in $colItems) {
    $intRC = $objItem->RemoteControl($intSetting);
    if ($intRC) {
        print "Error setting RemoteControl value\n";
    }
    else {
        print "Set RemoteControl value: $intSetting\n";
    }
}

This code has been viewed 722 times.

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