小玩意系列:增强Windows运行栏的功能 (二)

源自:http://blog.csdn.net/zhaoyl03/article/details/8887724

这一篇是技术文章,上接小玩意系列:增强Windows运行栏的功能 (一),主要讲如何批处理写注册表,从而实现SeventhSaint的install和uninstall功能。

SeventhSaint的install过程,实际上是在注册表里添加xxx.exe项,并将默认键值改为可执行文件或批处理文件的路径的过程。明白了这一点,就不难看懂如下install.bat的代码

::install.bat
@echo off

set version=1.0

if /i "%windir%"=="C:\Windows" (
    echo The windows directory is %windir%.
) else (
    echo The OS is not in C:\Windows.
    echo The SeventhSaint is not installed!
    goto :end
)

if /i "%cd%"=="C:\SeventhSaint\%version%" (
    echo The current directory is %cd%.
) else (
    echo The current directory is not c:\SeventhSaint\%version%.
    echo The SeventhSaint is not installed!
    goto :end
)

cd commands
dir /d /b *.bat> ../commands.txt
cd ..

@echo Windows Registry Editor Version 5.00>adds.txt.
for /f "tokens=1 delims=." %%i in (commands.txt) do (   
    @echo.>>adds.txt
    @echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%%i.exe] >>adds.txt
    @echo @="C:\\SeventhSaint\\%version%\\commands\\%%i.bat">>adds.txt
)

ren adds.txt adds.reg
reg import adds.reg
del adds.reg

echo The SeventhSaint is successfully installed, enjoy!

:end
pause


注意,install代码的前面两个if分别是判断Windows操作系统是否在c盘,以及SeventhSaint的路径是否正确。


SeventhSaint的uninstall过程,实际上删除在install时在注册表里添加的xxx.exe项的过程。uninstall.bat的代码和install的代码类似,如下

::uninstall
@echo off

set version=1.0
@echo Windows Registry Editor Version 5.00>adds.txt.
for /f "tokens=1 delims=." %%i in (commands.txt) do (   
    @echo.>>adds.txt
    @echo [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%%i.exe] >>adds.txt
)

ren adds.txt adds.reg
reg import adds.reg
del adds.reg
del commands.txt

echo The SeventhSaint is completely uninstalled!

pause



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值