首页 > 其他分享 >add shortcut

add shortcut

时间:2024-03-23 23:11:24浏览次数:17  
标签:name menu shortcut add key reg

@echo off

%1 %2
ver|find "5.">nul&&goto :Admin
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof

:Admin
set current_dir=%~dp0
%~d0
cd %~dp0

python bin/add_shortcut_menu.py --config=add

echo "Install successful"

pause

@echo off

%1 %2
ver|find "5.">nul&&goto :Admin
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof

:Admin
set current_dir=%~dp0
%~d0
cd %~dp0

python bin/add_shortcut_menu.py --config=delete

echo Uninstall Successful

pause

"""
Created by gaoxing on 2021.3.3
Open the shortcut by click the mouse's right button
"""

import argparse
import traceback
import os
from sys import version_info
import sys
import ctypes


if version_info.major == 3:
import winreg as reg
else:
import _winreg as reg


# the shortcut name
menu_name = 'ZipPkt'


def add_shortcut_menu():
"""Add a shortcut key for all of the file while click the right button of the mouse"""
# The path of the shortcut
menu_command = os.getcwd() + os.sep + 'bin' + os.sep + 'ZipPkt.exe'
print(menu_command)
# Set the path of registry
key = reg.OpenKey(reg.HKEY_CLASSES_ROOT, r'*\\shell')
# Set the shortcut keys
reg.SetValue(key, menu_name, reg.REG_SZ, menu_name + '(&A)')
sub_key = reg.OpenKey(key, menu_name)
# Set the execute line, menu_command + ' %v', such as atrace2trace.exe atrace
reg.SetValue(sub_key, 'command', reg.REG_SZ, menu_command + ' "%v"')
# Added by gaoxing on 2021.5.11, set the icon
icon_key = reg.OpenKeyEx(reg.HKEY_CLASSES_ROOT, r'*\\shell\\' + menu_name, 0, reg.KEY_WRITE)
reg.SetValueEx(icon_key, "icon", 0, reg.REG_SZ, menu_command)
# close the subkey and key
reg.CloseKey(sub_key)
reg.CloseKey(key)
reg.CloseKey(icon_key)

 

def delete_shortcut_menu():
"""Delete the shortcut key which added before"""
try:
key = reg.OpenKey(reg.HKEY_CLASSES_ROOT, r'*\\shell')
menu_key = reg.OpenKey(key, menu_name)
reg.DeleteKey(menu_key, 'command')
reg.DeleteKey(key, menu_name)
except Exception as e:
print(traceback.print_exc())

 

def check_permission():
""" Check if got the permission of admin """
try:
ctypes.windll.shell32.IsUserAnAdmin()
except:
return False


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Added shortcut key menu')
parser.add_argument('--config', default='add', help='The operation to add or delete shortcut key')
args = parser.parse_args()
if args.config == 'add':
add_shortcut_menu()
else:
delete_shortcut_menu()

 

标签:name,menu,shortcut,add,key,reg
From: https://www.cnblogs.com/Hpp918039/p/18091875

相关文章

  • Oracle函数7—日期函数(sysdate 、to_date、add_months、last_day......)
    文章目录1、日期获取(sysdate、current_date)2、设置时间格式(to_date、to_char)3、两个日期的差(直接加减)4、月份加减(add_months)5、取某月最后一天(last_day)6、两个日期相差月份数(months_between)7、获取下个周几是几号(next_day)8、获取指定时间的年或月或日(extract)9、时间的四......
  • 【飞浆AI实战】交通灯检测:手把手带你入门PaddleDetection,从训练到部署
    前言本次分享将带领大家从0到1完成一个目标检测任务的模型训练评估和推理部署全流程,项目将采用以PaddleDetection为核心的飞浆深度学习框架进行开发,并总结开发过程中踩过的一些坑,希望能为有类似项目需求的同学提供一点帮助。项目背景和目标背景:目标检测是计算机视觉的一......
  • linux下InetAddress.getLocalHost()很慢10s
    问题原因:执行InetAddress.getLocalHost()方法的时候,根据系统名称去hosts文件里找匹配的ip发现找不到合适的IP,一直处于等待状态。解决办法:1、查看本机系统名称 2、编辑hosts文件,在其后补充“cenos1”     参考链接:https://blog.csdn.net/lijun169/article/detail......
  • 内存检测工具——ASan(AddressSanitizer)的介绍和使用
    ASan介绍ASan全称AddressSanitizer,是一种内存错误检测工具,目的是帮助开发者检测和调试内存相关的问题,如使用未分配的内存、使用已释放的内存、堆内存溢出等。ASan是由Google开发的,广泛用于C、C++等语言的代码中。ASan的工作原理是在编译时将额外的代码插入到目标程序中,对内存的......
  • 使用 openssl 进行 RSA/ECB/PKCS1PADDING 加解密
    使用java进行RSA/ECB/PKCS1PADDING是非常方便的,例如下面的示例publicstaticStringpublicDecrypt(PublicKeypublicKey,Stringencrypted)throwsException{Ciphercipher=Cipher.getInstance("RSA/ECB/PKCS1Padding");cipher.init(Cipher.DECRYPT_......
  • [983] Add a notification after finishing the Python script
    ref:HowtoimplementaPythondesktopnotifierusingtheplyermoduleYoucangenerateanotificationafteryourPythoncodefinishesexecutingusingvariousmethods.Hereareafewoptions:UsingPlyer(Cross-Platform):Installthe plyer libraryusi......
  • GIS人必备神器降临!快速搞定洪水淹没分析!ArcGIS AddIn无源淹没分析插件!
            最近有很多小伙伴给我发私信,想使用我开发的一款基于无源淹没分析算法对洪水淹没进行分析的GIS插件。大部分小伙伴是因为看了我之前发的一个讲解洪水淹没分析算法的视频,在视频中我给大家展示了给某高校水利课题组开发的两款用于洪水淹没分析的插件:一个是基于8邻......
  • add魔术方法对象重写加法运算符
    对象重载add魔术方法#__add__魔术方法(与之相关的__radd__反向加法)''' 触发时机:使用对象进行运算相加的时候自动触发 功能:对象运算 参数:二个对象参数 返回值:运算后的值''''''类似的还有如下等等(了解): __sub__(self,other)定义减法的行为:- __mul__(......
  • 【机械臂路径规划】基于ADD-RRT、RRV、改进的Bridge Test等算法实现固定基座机械臂路
     ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,代码获取、论文复现及科研仿真合作可私信。......
  • paddleocr 在docker环境下部署
    paddleocr在docker环境下部署第一步查看cuda的版本nvcc-V,我的是11.2;nvidia-smi对应的cudaversion是11.6,所以采用了registry.baidubce.com/paddlepaddle/paddle:latest-dev-cuda11.6-cudnn8.4-trt8.4-gcc82作为基础镜像Docker镜像源选择,DockerHub地址Dockerfile......