我正在尝试自动执行需要重新启动本地计算机以及远程计算机中的服务的部署。我正在尝试读取每行包含主机名的主机文件,并将其存储在列表中,并对其进行遍历以停止每台计算机中的服务。
import wmi
import win32serviceutil
with open ('D:\hosts_read.txt', 'r') as hostsfiles:
content = hostsfiles.readlines()
content = [x.strip() for x in content]
for i in range(len(content)):
c = wmi.WMI
(content[i],user='piladmin',password='x41P6pIUQ0L8dvnVQOSabHQWTSPVKA')
print('connected to'+ content[i])
for service in c.Win32_Service():
service_name = ['PTC_Windchill','PTC Windchill Directory Server','PTCWindchillHTTPServerSSO']
for s in service_name:
win32serviceutil.StartService(s)
当我执行这段代码时,它说-"User credentials cannot be used for local connections ', None, 0, -2147217308), None)"
对于localhost,执行本身就在那里停止。我该如何实现?