本机环境:Win 10,python3.6
远程机器: Win7、WinServer
因python在windows上执行需要用到 wmi 模块。
wmi 模块下载地址:https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/
请对照自己python实际运行环境下载模块
import wmi def sys_version(ipaddress, user, password): conn = wmi.WMI(computer=ipaddress, user=user, password=password) for sys in conn.Win32_OperatingSystem(): print ("Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber) #系统信息 print (sys.OSArchitecture.encode("UTF8") ) # 系统的位数 print (sys.NumberOfProcesses) # 系统的进程数 try: filename = r"C:UsersadminDesktop1.bat" # 此文件在远程服务器上 cmd_callbat = r"cmd /c call %s" % filename conn.Win32_Process.Create(CommandLine=cmd_callbat) #执行bat文件 Win32_Process.Create except Exception as e: print(e) if __name__ == '__main__': sys_version(ipaddress="192.168.1.x", user="xxx", password="xxx")