代码之家  ›  专栏  ›  技术社区  ›  johnashu

在Windows中关闭蓝牙

  •  0
  • johnashu  · 技术社区  · 8 年前

    我想关闭Windows中的蓝牙适配器,因为它有时会干扰其他设备。

    我正在Windows中使用python 3.6和PyQt5。

    我已尝试使用停止服务。

    net stop bthserv /y

    这只会停止服务,但不会关闭控制面板或任务栏中的蓝牙

    enter image description here

    我是否可以在windows中使用命令行或使用Python/PyQt5关闭此功能?

    from subprocess import TimeoutExpired, Popen, run, call, check_output, STARTUPINFO, STARTF_USESHOWWINDOW, SW_HIDE, PIPE, STDOUT
    
    class BT:
        def process_f(self, command, bsize=4096):
    
            print('1a) Process started...')
    
            startupinfo = STARTUPINFO()
            startupinfo.dwFlags |= STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = SW_HIDE
    
            p = Popen(command, stdout=PIPE, stderr=PIPE,
                    startupinfo=startupinfo, bufsize=bsize, universal_newlines=True)
            try:
                out, err = p.communicate(timeout=300)            
            except TimeoutExpired:
                p.kill()            
                out, err = p.communicate()
            return out.split(), err.split()
    
        def service_switch(self, service, on=False, off=False):
            """ Start or stop a service in windows """
    
            if on:
                switch = 'start'
            elif off:
                switch = 'stop'
            else:
                return False
    
            command = 'net {} {} /y'.format(switch, service)
    
            p = self.process_f(command)
    
            out, err = p[0], p[1]
    
            print('STDOUT: {}'.format(out))
            print('STDERR: {}'.format(err))
    
    bt = BT()
    
    bt.service_switch('bthserv', on=True)
    # bt.service_switch('bthserv', off=True)
    
    0 回复  |  直到 8 年前