Пример #1
0
def set_env(name, value, current=True):
    """Set HKCU/HKLM environment variables"""
    root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
    key = winreg.OpenKey(root, "Environment")
    try:
        _x, key_type = winreg.QueryValueEx(key, name)
    except WindowsError:
        key_type = winreg.REG_EXPAND_SZ
    key = winreg.OpenKey(root, "Environment", 0, winreg.KEY_SET_VALUE)
    winreg.SetValueEx(key, name, 0, key_type, value)
    from win32gui import SendMessageTimeout
    from win32con import (HWND_BROADCAST, WM_SETTINGCHANGE,
                          SMTO_ABORTIFHUNG)
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
                       "Environment", SMTO_ABORTIFHUNG, 5000)
Пример #2
0
def broadcast_change():
    '''
    Refresh the windows environment.

    Returns (bool): True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' reg.broadcast_change
    '''
    # https://msdn.microsoft.com/en-us/library/windows/desktop/ms644952(v=vs.85).aspx
    _, res = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0,
                                SMTO_ABORTIFHUNG, 5000)
    return not bool(res)
Пример #3
0
def RunVideoWallpaper(player_window_handel):#设置视频壁纸
    if(player_window_handel!=0):
        #查找桌面窗口
        desktop_window_handel = FindWindow("Progman", "Program Manager")
        #设置player_window为desktop_window的子窗口
        SetParent(player_window_handel, desktop_window_handel)
        #核心语句,向desktop_window发送0x52C启用Active Desktop
        SendMessageTimeout(desktop_window_handel, 0x52C, 0, 0, SMTO_ABORTIFHUNG, 100)
        #因为有两个同类同名的WorkerW窗口,所以遍历所以顶层窗口
        workerw=[0]
        EnumWindows(_MyCallback, workerw)
        #获取player_windows名称
        player_windows_name = GetWindowText(player_window_handel)
        while(True):#防止win+tab将player_window发送到图标窗口的父窗口(原因不明)及SetParent导致静态壁纸窗口重新出现
            #隐藏静态壁纸窗口
            ShowWindow(workerw[0], SW_HIDE)
            #判断player_window是否在desktop_window下
            player_under_desktop = FindWindowEx(desktop_window_handel, None, "SDL_app", player_windows_name)
            if(player_under_desktop==0):#如果player_window位置不正确
                #将player_window设置为desktop_window的子窗口
                SetParent(player_window_handel, desktop_window_handel)
Пример #4
0
    def SendCommandApp(self, cmd):
        try:
            if self.FindMarantzWindow():
                hAtom = GlobalAddAtom(cmd)
                SendMessageTimeout(
                    self.hwndMarantzControl,
                    WM_APP+102, 
                    hAtom, 
                    0, 
                    SMTO_BLOCK|SMTO_ABORTIFHUNG,
                    500 # Wait at most 500ms
                )
                time.sleep(0.1) # Wait 100ms for command to be processed by MarantzSerial
                return False

            else:
                self.PrintError("MarantzControl application not found")
                return True

        except:
            self.PrintError("Unable to send command to MarantzControl")
            return True
Пример #5
0
 def set_user_env(reg, parent=None):
     """Set HKCU (current user) environment variables"""
     reg = listdict2envdict(reg)
     types = dict()
     key = OpenKey(HKEY_CURRENT_USER, "Environment")
     for name in reg:
         try:
             _x, types[name] = QueryValueEx(key, name)
         except WindowsError:
             types[name] = REG_EXPAND_SZ
     key = OpenKey(HKEY_CURRENT_USER, "Environment", 0, KEY_SET_VALUE)
     for name in reg:
         SetValueEx(key, name, 0, types[name], reg[name])
     try:
         from win32gui import SendMessageTimeout
         from win32con import (HWND_BROADCAST, WM_SETTINGCHANGE,
                               SMTO_ABORTIFHUNG)
         SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
                            "Environment", SMTO_ABORTIFHUNG, 5000)
     except ImportError:
         QMessageBox.warning(parent, _("Warning"),
                     _("Module <b>pywin32 was not found</b>.<br>"
                       "Please restart this Windows <i>session</i> "
                       "(not the computer) for changes to take effect."))
Пример #6
0
def set_env(name, value):
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', 0, winreg.KEY_ALL_ACCESS)
    winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, value)
    winreg.CloseKey(key)
    SendMessageTimeout( win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment', win32con.SMTO_ABORTIFHUNG, 100)
Пример #7
0
def broadcast_change():
    #    SendMessage(
    #        win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment')
    "Alerting active windows to the settings change..."
    SendMessageTimeout(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0,
                       'Environment', win32con.SMTO_ABORTIFHUNG, 0)
Пример #8
0
def _inform_os_environment_changed():
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, 100)