当前位置: 首页>编程语言>正文

自动安装鼠标动态光标

安装鼠标动态安装需要在

​ 个性化>主题>鼠标光标>预览

里一个一个的选择

这样太累了,使用python脚本来自动化安装。

逻辑

  1. 获取当前文件夹的鼠标动态光标
  2. 生成对应.inf格式安装文件
  3. 确认是否安装.inf文件

注意1

由于执行的安装命令是:rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 ./Install.inf可能只在部分Windows版本可以使用

经过测试 win7和win10都成功安装

注意2

脚本同级目录中.cur文件或.ani文件有一共15个,且默认排序(按文件名称递增)后需要遵循如下顺序:

  1. 正常选择
  2. 帮助选择
  3. 后台运行
  4. 精确定位
  5. 选定文本
  6. 手写
  7. 不可用
  8. 垂直调整
  9. 水平调整
  10. 沿对角线调整1
  11. 沿对角线调整2
  12. 移动
  13. 候选
  14. 链接选择

脚本正文

import os
import re

CUR_DIR = os.getcwd().split(os.sep)[-1]

ls = list(filter(lambda file: not os.path.isdir(file),
                 os.listdir(os.getcwd())))
ls = list(
    filter(lambda name: bool(re.findall(r'(^.*\.ani$)|(^.*\.cur$)', name)),
           ls))[:15]
ls.sort()

Strings_list = [
    'pointer', 'help', 'work', 'busy', 'cross', 'text', 'hand', 'unavailiable',
    'vert', 'horz', 'dgn1', 'dgn2', 'move', 'alternate', 'link'
]
Strings_list = list(
    map(lambda h, f: h + ' = \"' + f + '\"\r\n', Strings_list, ls))

inf_head = r'''[Version]
signature="$CHICAGO$"

[DefaultInstall]
CopyFiles = Scheme.Cur
AddReg    = Scheme.Reg,Wreg

[DestinationDirs]
Scheme.Cur = 10,"%CUR_DIR%"

[Scheme.Reg]
HKCU,"Control Panel\Cursors\Schemes","%SCHEME_NAME%",,"%10%\%CUR_DIR%\%pointer%,%10%\%CUR_DIR%\%help%,%10%\%CUR_DIR%\%work%,%10%\%CUR_DIR%\%busy%,%10%\%CUR_DIR%\%Cross%,%10%\%CUR_DIR%\%Text%,%10%\%CUR_DIR%\%Hand%,%10%\%CUR_DIR%\%Unavailiable%,%10%\%CUR_DIR%\%Vert%,%10%\%CUR_DIR%\%Horz%,%10%\%CUR_DIR%\%Dgn1%,%10%\%CUR_DIR%\%Dgn2%,%10%\%CUR_DIR%\%move%,%10%\%CUR_DIR%\%alternate%,%10%\%CUR_DIR%\%link%"

[Wreg]
HKCU,"Control Panel\Cursors",,0x00020000,"%SCHEME_NAME%"
HKCU,"Control Panel\Cursors",AppStarting,0x00020000,"%10%\%CUR_DIR%\%work%"
HKCU,"Control Panel\Cursors",Arrow,0x00020000,"%10%\%CUR_DIR%\%pointer%"
HKCU,"Control Panel\Cursors",Crosshair,0x00020000,"%10%\%CUR_DIR%\%Cross%"
HKCU,"Control Panel\Cursors",Hand,0x00020000,"%10%\%CUR_DIR%\%link%"
HKCU,"Control Panel\Cursors",Help,0x00020000,"%10%\%CUR_DIR%\%Help%"
HKCU,"Control Panel\Cursors",IBeam,0x00020000,"%10%\%CUR_DIR%\%Text%"
HKCU,"Control Panel\Cursors",No,0x00020000,"%10%\%CUR_DIR%\%Unavailiable%"
HKCU,"Control Panel\Cursors",NWPen,0x00020000,"%10%\%CUR_DIR%\%Hand%"
HKCU,"Control Panel\Cursors",SizeAll,0x00020000,"%10%\%CUR_DIR%\%move%"
HKCU,"Control Panel\Cursors",SizeNESW,0x00020000,"%10%\%CUR_DIR%\%Dgn2%"
HKCU,"Control Panel\Cursors",SizeNS,0x00020000,"%10%\%CUR_DIR%\%Vert%"
HKCU,"Control Panel\Cursors",SizeNWSE,0x00020000,"%10%\%CUR_DIR%\%Dgn1%"
HKCU,"Control Panel\Cursors",SizeWE,0x00020000,"%10%\%CUR_DIR%\%Horz%"
HKCU,"Control Panel\Cursors",UpArrow,0x00020000,"%10%\%CUR_DIR%\%alternate%"
HKCU,"Control Panel\Cursors",Wait,0x00020000,"%10%\%CUR_DIR%\%busy%"
HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce\Setup\","",,"rundll32.exe shell32.dll,Control_RunDLL main.cpl @0,1"

'''

with open('Install.inf', 'w', newline='') as inf:
    inf.write(inf_head)
    inf.write('[Scheme.Cur]\r\n')
    for i in ls:
        inf.write('\"' + i + '\"\r\n')
    inf.write('\r\n')
    inf.write('[Strings]\r\n')
    inf.write('CUR_DIR = \"Cursors\' + CUR_DIR + '\"\r\n')
    inf.write('SCHEME_NAME = \"' + CUR_DIR + '\"\r\n')
    inf.write('SCHEME_DESCRIPTION = \"' + CUR_DIR + '\"\r\n')
    inf.writelines(Strings_list)

i = input("Do you want to install it now?")
if (i.strip() in ["", "Y", "y"]):
    #auto
    import subprocess
    s = subprocess.Popen(
        "rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 ./Install.inf",
        shell=True)
    s.wait()
    input("Install Success")
else:
    input(
        "Click on the file Install.inf right mouse button, the shortcut menu to choose - to install"
    )


https://www.xamrdz.com/lan/5n62016591.html

相关文章: