小玩意系列:增强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



你可能感兴趣的:(程序设计,Seventhsaint,人工智能)