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
  • 相关阅读:
    构建之法阅读笔记02
    学习进度条
    构建之法阅读笔记01
    c++ 与C的区别
    c++ 菜单动态效果
    c++ 方框中绘制菜单代码
    c++ 绘制方框
    c++ 条件编译
    c++ 预处理和多重替换
    c++ 文件共享打开
  • 原文地址:https://www.cnblogs.com/slqt/p/5773432.html
Copyright © 2011-2022 走看看