Slavatar Asked:2021-10-30 20:36:31 +0000 UTC2021-10-30 20:36:31 +0000 UTC 2021-10-30 20:36:31 +0000 UTC Python 中的 Windows 系统管理 772 需要通过python来更改Windows 10系统的设置/参数,例如: 沉默的 关闭电脑 互联网关闭 降低亮度 等等。 最好的实施方案是什么?(是的,一切都可以通过控制台使用 os.system 完成,但我认为这不是完全正确的解决方案) python 1 个回答 Voted Best Answer Violet 2021-11-03T15:29:39Z2021-11-03T15:29:39Z 使用pywinrm重新启动打印管理器服务的示例 import winrm def spooler_restart(server): ad_user, ad_pass = get_ad_data() s = winrm.Session(server, auth=(ad_user, ad_pass), transport='ntlm') # server = IP or DNS stop = s.run_cmd('net stop spooler') status_stop = stop.std_out.translate(None, b'\r\n').decode('cp866').replace('The ', '').replace('.', '\n') time.sleep(1) start = s.run_cmd('net start spooler') status_start = start.std_out.translate(None, b'\r\n').decode('cp866').replace('The ', '').replace('.', '\n') if 'stopped successfully' in status_stop and 'started successfully' in status_start: return str(stop.status_code) + ', Служба успешно остановлена\n' + \ str(start.status_code) + ', Служба успешно запущена' else: return str(stop.status_code) + str(start.status_code)
使用pywinrm重新启动打印管理器服务的示例