What is the cause of the error in this Python WMI script? (Windows 8.1) (Network adapter configuration) (Python 2.7)
<p>I am trying to make a Python script that will set my IP address to a static one instead of a dynamic one. I have searched up methods for this and the WMI implementation for Python seemed to be the best option. The stackoverflow question I got the information about is <a href="http://stackoverflow.com/a/7581831/5899439">here</a>. </p>

<p>I can get the IP address to be set to the static address but then I have to set the DNS server as well. <a href="https://community.spiceworks.com/topic/405339-replace-static-dns-settings-with-wmi-and-powershell" rel="nofollow">This site here</a> is where I got the basis for the DNS setting but it is causing problems. </p>

<p><strong>Traceback from IDLE</strong></p>

<pre><code>Traceback (most recent call last):
File "C:\Users\james_000\Desktop\SetIP.py", line 18, in &lt;module&gt;
    c = nic.SetDNSServerSearchOrder(dns)
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)
x_wmi: &lt;x_wmi: Unexpected COM Error (-2147352567, 'Exception occurred.', (0,
u'SWbemProperty', u'Type mismatch ', None, 0, -2147217403), None)&gt;
</code></pre>

<p><strong>SetIP.py</strong></p>

<pre><code>import wmi

nic_configs = wmi.WMI('').Win32_NetworkAdapterConfiguration(IPEnabled=True)

# First network adaptor
nic = nic_configs[0]

# IP address, subnetmask and gateway values should be unicode objects
ip = u'192.168.0.151'
subnetmask = u'255.255.255.0'
gateway = u'192.168.0.1'
dns = u'192.168.0.1'

# Set IP address, subnetmask and default gateway
# Note: EnableStatic() and SetGateways() methods require *lists* of values to be passed
a = nic.EnableStatic(IPAddress=[ip],SubnetMask=[subnetmask])
b = nic.SetGateways(DefaultIPGateway=[gateway])
c = nic.SetDNSServerSearchOrder(dns)
d = nic.SetDynamicDNSRegistration(true)

print(a)
print(b)
print(c)
print(d)
</code></pre>

<p>Please don't add solutions in comments as it makes it harder for other people to learn about how to fix the problem. </p>

<p>SetDNSServerSearchOrder is looking for an array of Strings</p>

<pre><code>c = nic.SetDNSServerSearchOrder(dns)
</code></pre>

<p>should be</p>

<pre><code>c = nic.SetDNSServerSearchOrder([dns])
</code></pre>

python windows wmi