我已经使用Python的WMI很长一段时间了,我使用Python提升来处理服务。但是,Robot Framework的IDE(RIDE)遇到了问题,它由于elevate.elevate()而终止,因为Python解释器以管理员权限再次启动,RIDE认为测试已经中断
我在本地机器上,所有运行Robot-FW的用户都有管理权限,UAC关闭。我发现在初始化wmi对象时可能需要“模拟”,但是尝试了以下操作之后,我无法完成任何操作,除非我“获得”管理权限
以下是我所尝试的:
#
# Tried impersonation delegate. Used a moniker from various sources, but they don't work too.
#
wmi_obj = wmi.WMI(impersonation_level="Impersonate", privileges=["SystemProfile", "MachineAccount", "Security"])
class ManageServiceException(Exception) :
pass
def GetServiceInfo(service_name) :
"""
Get information about the service(s) whose name matches with the _service_name_.
Return an object of the service, if found or raise an exception.
Eg: obj.State
"""
global wmi_obj
#elevate.elevate(show_console=False) # tried show_console=True and False
try:
return wmi_obj.Win32_Service(Name=service_name)
except:
raise ManageServiceException("No service found with name %s"% service_name)
我可以在services.msc中控制服务,而不必“以管理员身份运行”。我也想在这里做同样的事
最终找到了正确的解决方案:
相关问题 更多 >
编程相关推荐