简体   繁体   中英

How do I change a computer's name with the WMI module in Python

So right now I'm in the middle of trying to develop a script that would automate a few file manipulating and name changing tasks within our POS software. I've created a function that copy's the config folders from the main server's pos directory. Now I'll have another function that changes the computer name, and then I'll have a function that reboots the computer. I know this can be done within power-shell, but I do also know you can can change many properties within windows with the Windows Management Instrumentation(WMI) module imported into python. The main function I'm worrying about right now is the one affiliated with changing the computer name. I've looked through Tim Golden's WMI tutorials and have thoroughly searched the web with no luck. If anybody could steer me in the right direction it would be greatly appreciated.

Hey guys so I did a little more digging and figured out how to change the name of the computer with the wmi module.

Here's the code:

import wmi

c = wmi.WMI()

for system in c.Win32_ComputerSystem():
        system.Rename('NewCompName', Username, Password)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM