[python-win32] rename computer

Tim Golden mail at timgolden.me.uk
Mon Dec 19 15:32:36 CET 2011


On 19/12/2011 14:20, cd wrote:
> import wmi
> c = wmi.WMI().Win32_ComputerSystem
> computer = c()[0]
> for propertyName in sorted( list( c.properties ) ):
> if propertyName == 'Name':
> print setattr( computer, propertyName, 'newname' )

Ah.

I'm afraid, good as WMI is, it's not that good. You need to
invoke the right method on the Win32_ComputerSystem instance.

The appropriate method is referenced here:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa393056%28v=vs.85%29.aspx


There are some examples here:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394586%28v=vs.85%29.aspx


and the (definitely untested) Python equivalent is something
like this:

<code>
import wmi

c = wmi.WMI ()
for system in c.Win32_ComputerSystem ():
   system.Rename ("NEW-NAME", "TIM", "PASSWORD")

</code>

TJG


More information about the python-win32 mailing list