Is there a way to programmatically turn on remote registry?

Kevin Holleran kdawg44 at gmail.com
Wed Oct 24 07:40:46 EDT 2012


On Tue, Oct 23, 2012 at 11:44 AM, Kevin Holleran <kdawg44 at gmail.com> wrote:

> On Tue, Oct 23, 2012 at 11:39 AM, Tim Golden <mail at timgolden.me.uk> wrote:
>
>> On 23/10/2012 16:17, Kevin Holleran wrote:
>> > I am still having a small implementation problem....
>> >
>> > [code]
>> > HKLM = winreg.HKEY_LOCAL_MACHINE
>> > NICs =
>> >
>> "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}"
>> >
>> >  registry = wmi.WMI(host, namespace="default").StdRegProv
>> >   _, names = registry.EnumKey(HKLM,NICs) # <-- Error
>> > [/code]
>> >
>> > [error]
>> >   File "wmi.pyc", line 241, in handle_com_error
>> > wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147352567, 'Exception
>> > occurred.', (0,
>> >  u'SWbemProperty', u'Type mismatch ', None, 0, -2147217403), None)>
>> > [\error]
>>
>>
>> I can see nothing wrong with that. On my system the following code works
>> fine:
>>
>> <code>
>> import _winreg as winreg
>> import wmi
>>
>> host = "SVR18"
>>
>> HKLM = winreg.HKEY_LOCAL_MACHINE
>> NICs =
>>
>> "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}"
>>
>> registry = wmi.WMI(host, namespace="default").StdRegProv
>> _, names = registry.EnumKey(HKLM,NICs) # <-- Error
>>
>> print names
>>
>> </code>
>>
>> Am I understanding you correctly? Can you send me an interpreter
>> screendump showing the failure with the traceback (just in case anything
>> useful occurs to me when I see it)?
>>
>>
>> TJG
>>
>
> I will but I have to run to a meeting.  I will send over.  Another note,
> probably should have mentioned earlier, I am using py2exe & running the
> executable from the the machine that has access to these systems.
>
> Kevin
>

Here is the full traceback:

[output]
Scan_NIC_Driver_Info_1.2.py -i testing_MSK_Server.csv -o
MSK_Test_output.csv -u unreachable.csv
Parsing input file...

Connecting to IP...

Traceback (most recent call last):
  File
"D:\Development\Scripts\Python\Scan_NIC_Driver_Info\Scan_NIC_Driver_Info_
1.2.py", line 70, in <module>
    _, names = registry.EnumKey(HKLM,NICs)
  File "C:\Python27\lib\site-packages\wmi.py", line 431, in __call__
    handle_com_error ()
  File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
    raise klass (com_error=err)
wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147352567, 'Exception
occurred.', (0,
 u'SWbemProperty', u'Type mismatch ', None, 0, -2147217403), None)>

[/output]

Basically, it parses a list of hosts from a CSV, outputs a series of lines:
host, driverDesc, diverDate, driverVersion.  Basically it pings the host
first to make sure its up.

Here are the relevant parts to the script:

[code]
 registry = wmi.WMI(host, namespace="default").StdRegProv
        _, names = registry.EnumKey(HKLM,NICs)
        print("Connected successfully.")
        try:
            for name in names:
                print name
                NIC = NICs + "\\" + name
                _, value_names, value_types = registry.EnumValues(HKLM, NIC)
                for value_name, value_type in zip(value_names, value_types):
                    if value_type == winreg.REG_SZ:
                        if value_name == "BusType":
                            _, busType = registry.GetStringValue(HKLM,
NICs, value_name)
                        elif value_name == "DriverDesc":
                            _, driverDesc = registry.GetStringValue(HKLM,
NICs, value_name)
                        elif value_name == "DriverDate":
                            _, driverDate = registry.GetStringValue(HKLM,
NICs, value_name)
                        elif value_name == "DriverVersion":
                            _, driverVersion =
registry.GetStringValue(HKLM, NICs, value_name)
                    if busType == 5:
                        outputline = host + "," + driverDesc + "," +
driverDate + "," + driverVersion + "\n"
                        print outputline
                        outputFile.write(outputLine)
        except:
            print "Unable to query registry key for NIC adapters"
[/code]

Thanks again.

Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121024/079be15c/attachment.html>


More information about the Python-list mailing list