zoukankan      html  css  js  c++  java
  • python根据服务名获取服务启动路径

    #coding=utf8
    import _winreg as winreg
    
    class Win32Environment:
        """Utility class to get/set windows environment variable"""
        def __init__(self, scope,name):
            self.scope = scope
            if scope == 'user':
                self.root = winreg.HKEY_CURRENT_USER
                self.service_subkey = 'Services'
                self.process_subkey = 'Software\Classes'
            else:
                self.root = winreg.HKEY_LOCAL_MACHINE
                self.service_subkey = 'SYSTEM\CurrentControlSet\Services\'+name
                self.process_subkey = 'Software'
        
        def get_service_path(self, name):
            key = winreg.OpenKey(self.root, self.service_subkey, 0, winreg.KEY_READ)
            try:
                value, _ = winreg.QueryValueEx(key, name)
            except Exception as e:
                return e
            return value    
    try:
        win=Win32Environment(scope="system",name='salt-minion')
        a=win.get_service_path('ImagePath')
        if not a:
            win=Win32Environment(scope="user",name='salt-minion')
            a=win.get_service_path('ImagePath')
        print a        
    except Exception as e:
        print e
  • 相关阅读:
    Mycat之按照时间进行分片
    Mysql binlog解析器
    字体属性和文本属性总结
    css选择器
    CSS的三种引入方式
    CSS样式语法
    应用程序与数据库结合使用的三种方式
    存储过程
    子查询
    多表查询
  • 原文地址:https://www.cnblogs.com/slqt/p/5773432.html
Copyright © 2011-2022 走看看