# Kod uaktywnia protok DHCP dla okrelonego poczenia

use Win32::OLE qw(in);
$Win32::OLE::Warn = 3;

# ------ KONFIGURACJA SKRYPTU ------
$strComputer = '.';
$strConnection = 'Poczenie lokalne';
# ------ KONIEC KONFIGURACJI ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colNA = $objWMI->ExecQuery('select * ' . ' from Win32_NetworkAdapter ' . ' where NetConnectionID = \'' . $strConnection . '\'');
foreach my $objNA (in $colNA) {
    $colNAConfig = $objWMI->ExecQuery('ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=\'' . $objNA->DeviceID . '\'} ' . ' WHERE resultClass = win32_NetworkAdapterConfiguration ');
    foreach my $objNAConfig (in $colNAConfig) {
        if ($objNAConfig->DHCPEnabled == 1) {
            print "Protok DHCP uaktywniono ju dla $strConnection\n";
        }
        else {
            $intRC = $objNAConfig->EnableDHCP();
            if ($intRC == 0) {
                print "Protok DHCP uaktywniono dla $strConnection\n";
            }
            elsif ($intRC == 1) {
                print "Konieczne jest przeadowanie systemu, aby zacz uywa protokou DHCP dla $strConnection\n";
            }
            else {
                print 'Wystpi bd podczas uaktywniania protokou DHCP dla ' . $strConnection . ': ' . $intRC, "\n";
            }
        }
    }
}
