Pywin32: A module to support python for Win32 extensions.
Basicly, it could be used to invoke all wmi class to do what you want in Windows.(http://msdn.microsoft.com/en-us/library/windows/desktop/aa394554(v=vs.85).aspx).
We use this module to do network configuration, such as DNS config.
However there is something special when we dispatch WMI methods.
Environment: python2.7, OS:WIN7
To invoke these methods of Win32_NetworkAdapterConfiguration object. Here I didn't use these methods directly, but wrap all input parameters into a SpawnInstance_. It seems wired but worked.
1 import win32com.client
2
3 objLocator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
4 objService = objLocator.ConnectServer(".","root\cimv2")
5 nobj = objService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
6 obj = nobj[0]##
7 print obj.IpAddress ## get Ip
8
9 ##To invoke SetWINSServer, you need put all arguments in to a special object.
10 obj_method = obj.Methods_("SetWINSServer")
11 obj_in_param = obj_method.inParameters.SpawnInstance_()
12 obj_in_param.WINSPrimaryServer="127.0.0.1"
13 obj_in_param.WINSSecondaryServer="127.0.0.2"#invoke the SetWINServer method, and it worked.
14 obj.ExecMethod_("SetWINSServer", obj_in_param)
Almost all these methods of Win32_NetworkAdapterConfiguration could be used like this. However, "SetMTU" can't, maybe it's because "this method is not supported", I try it in Windows 2008R2 but get the same error. It said SetMTU is not supported here. http://msdn.microsoft.com/en-us/library/windows/desktop/aa393463(v=vs.85).aspx