|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『楼 主』:
[圆满解决]shortcuts批量创建修改快捷键的难题
使用 LLM 解释/回答一下
结合批处理,shortcuts可以实现批量创建和修改快捷键,但是在实际中遇到一个问题。那就是如果shortcuts创建或修改快捷键的/P参数或者/W参数或者/I参数中存在带空格的路径,那么创建快捷方式就会失败,而快捷键参数的路径中如果本身存在空格,那么本身就要求使用引号来包括路径,因而产生了冲突。如何解决这个问题呢?如目标为"D:\UGS\NX 6.0\MACH\auxiliary\cls2clf.bat" 参数为"D:\UGS\NX 6.0\" 工作路径为"D:\UGS\NX 6.0\MACH\auxiliary\",图标为“D:\UGS\NX 6.0\UGTO2D\ugto2d.ico,0”的快捷方式使用shortcuts创建时就会失败。
下面是批处理文件和我的打包的快捷方式,大家测试下如何解决这个问题下面的程序中BS是字符替换工具,替换任意指定的字符。
@ECHO OFF
REM 当改变了文件路径后批量替换(修复)快捷方式.变量LNKPATH为需要替换的快捷方式文件夹的路径;OLDPATH为原始文件安装路径;NEWPATH为新的移动路径
REM 假设安装了CATIA后移动了文件路径或者要制作绿色CATIA,那么快捷方式路径应该做相应变化
SET LNKPATH="%ALLUSERSPROFILE%\「开始」菜单\程序\【HYSOFT】\UGSNX6绿色精简版"
SET OLDPATH="D:\UGS
SET NEWPATH="D:\PROGRAMS PROFILES\UGS"
SET PATH=%CD%;%CD%\GTOOLS\;%PROGRAMFILES%\WINRAR;%PATH%
IF NOT EXIST ".\GTOOLS\BS.exe" SET ERR=安装支持目录下缺少字符替换工具,安装程序无法继续&&GOTO:ERROR
IF NOT EXIST ".\GTOOLS\SC.exe" SET ERR=安装支持目录缺少快捷方式创建工具,安装程序无法继续&&GOTO:ERROR
FOR /F "DELIMS=" %%I IN ('DIR /B/S "%LNKPATH%\*.LNK"') DO (
SC /F:"%%I" /A:Q>"%TEMP%\SCUT.TXT"
BS "%TEMP%\SCUT.TXT" %OLDPATH% %NEWPATH% /I>NUL&CLS
setlocal enabledelayedexpansion
FOR /F "TOKENS=1,* DELIMS==" %%A IN (%TEMP%\SCUT.TXT) DO CALL SET %%A=%%B
IF EXIST "!TargetPath!" SC.EXE /F:"%%I" /A:E /T:"!TargetPath!" /P:"!Arguments!" /W:"!WorkingDirectory!" /I:"!IconLocation!" /D:"鸿越软件"
endlocal
)
SET ERR=替换修复完成,谢谢您使用鸿越软件制作的该工具&&GOTO:ERROR
:ERROR
>"%TEMP%\Temp.vbs" Echo intAnswer = MsgBox("%ERR%" , vbYes, "鸿越软件温馨提示您!")
cscript //nologo "%TEMP%\Temp.vbs"
EXIT
Last edited by HUNRYBECKY on 2008-8-4 at 08:23 AM ]
Combined with batch processing, shortcuts can be used to create and modify shortcuts in batches. But in practice, a problem is encountered. That is, if there are paths with spaces in the /P parameter or /W parameter or /I parameter when creating or modifying shortcuts with shortcuts, the creation of the shortcut will fail. And if there are spaces in the path of the shortcut parameter, it itself requires that the path be enclosed in quotes, thus causing a conflict. How to solve this problem? For example, a shortcut with the target "D:\UGS\NX 6.0\MACH\auxiliary\cls2clf.bat", the parameter "D:\UGS\NX 6.0\", the working path "D:\UGS\NX 6.0\MACH\auxiliary\", and the icon "D:\UGS\NX 6.0\UGTO2D\ugto2d.ico,0" will fail when created with shortcuts.
The following is the batch file and the shortcut I packaged. Please test how to solve this problem. The BS in the following program is a character replacement tool to replace any specified characters.
@ECHO OFF
REM When the file path is changed, batch replace (repair) shortcuts. The variable LNKPATH is the path of the shortcut folder to be replaced; OLDPATH is the original file installation path; NEWPATH is the new moved path
REM Suppose that after installing CATIA, the file path is moved or a green CATIA is to be made, then the shortcut path should be changed accordingly
SET LNKPATH="%ALLUSERSPROFILE%\「开始」菜单\程序\【HYSOFT】\UGSNX6绿色精简版"
SET OLDPATH="D:\UGS
SET NEWPATH="D:\PROGRAMS PROFILES\UGS"
SET PATH=%CD%;%CD%\GTOOLS\;%PROGRAMFILES%\WINRAR;%PATH%
IF NOT EXIST ".\GTOOLS\BS.exe" SET ERR=The character replacement tool is missing in the installation support directory, and the installation program cannot continue&&GOTO:ERROR
IF NOT EXIST ".\GTOOLS\SC.exe" SET ERR=The shortcut creation tool is missing in the installation support directory, and the installation program cannot continue&&GOTO:ERROR
FOR /F "DELIMS=" %%I IN ('DIR /B/S "%LNKPATH%\*.LNK"') DO (
SC /F:"%%I" /A:Q>"%TEMP%\SCUT.TXT"
BS "%TEMP%\SCUT.TXT" %OLDPATH% %NEWPATH% /I>NUL&CLS
setlocal enabledelayedexpansion
FOR /F "TOKENS=1,* DELIMS==" %%A IN (%TEMP%\SCUT.TXT) DO CALL SET %%A=%%B
IF EXIST "!TargetPath!" SC.EXE /F:"%%I" /A:E /T:"!TargetPath!" /P:"!Arguments!" /W:"!WorkingDirectory!" /I:"!IconLocation!" /D:"鸿越软件"
endlocal
)
SET ERR=Replacement and repair completed, thank you for using the tool made by Hongyue Software&&GOTO:ERROR
:ERROR
>"%TEMP%\Temp.vbs" Echo intAnswer = MsgBox("%ERR%" , vbYes, "Hongyue Software kindly reminds you!")
cscript //nologo "%TEMP%\Temp.vbs"
EXIT
Last edited by HUNRYBECKY on 2008-8-4 at 08:23 AM ]
附件
1: SCUT.rar (2008-7-31 14:46, 108.6 KiB,下载次数: 137)
|
|
2008-7-31 14:46 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
没有人回答,自己顶一个。
No one answered, so I'll bump it up myself.
|
|
2008-7-31 15:55 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
呵呵,高手们今天怎么都潜水了。继续等待。
Hehe, why are all the experts lurking today. Still waiting.
|
|
2008-7-31 16:10 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
|
2008-7-31 16:25 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
高手们真会潜水,到现在还没有人光顾。
Experts are really good at lurking, and no one has visited yet.
|
|
2008-8-1 14:13 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
我自己再顶下,不知道是这个问题太简单还是因为其他原因,居然都没有人回答。。。。
I'll give it a bump myself. I don't know if this question is too simple or for some other reason, but居然 no one has answered...
|
|
2008-8-2 12:07 |
|
|
dato
高级用户
   
积分 916
发帖 377
注册 2004-3-8
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
不知道这段VBS是否支持空格,不过从某种情况下偶更宁愿建个.lnk文件直接使用copy的方式释放,用iexpress打包就行了,psexec执行,脚本有时候用起来也烦一堆的ABC
'Create autoshutdown Desktop icon
Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("AllUsersDesktop")
Set link = Shell.CreateShortcut(DesktopPath & "\自动关机.lnk")
link.Arguments = "-s -t 0 -f"
link.Description = "自动关闭计算机"
'link.HotKey = "CTRL+ALT+SHIFT+E"
link.IconLocation = "%SystemRoot%\system32\shutdown.exe"
link.TargetPath = "%SystemRoot%\system32\shutdown.exe"
link.WindowStyle = 7
link.WorkingDirectory = "%systemroot%"
link.Save
Const ALL_USERS_DESKTOP = &H19&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ALL_USERS_DESKTOP)
Set objFolderItem = objFolder.ParseName("自动关机.lnk")
Set objShortcut = objFolderItem.GetLink
objShortcut.SetIconLocation "%systemroot%\System32\SHELL32.dll", 27
objShortcut.Save
I don't know if this VBS supports spaces, but in some cases I'd rather create a .lnk file and release it directly using the copy method, package it with iexpress, and execute it with psexec. Scripts can be annoying with a bunch of ABCs sometimes
'Create autoshutdown Desktop icon
Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("AllUsersDesktop")
Set link = Shell.CreateShortcut(DesktopPath & "\自动关机.lnk")
link.Arguments = "-s -t 0 -f"
link.Description = "Automatically shut down the computer"
'link.HotKey = "CTRL+ALT+SHIFT+E"
link.IconLocation = "%SystemRoot%\system32\shutdown.exe"
link.TargetPath = "%SystemRoot%\system32\shutdown.exe"
link.WindowStyle = 7
link.WorkingDirectory = "%systemroot%"
link.Save
Const ALL_USERS_DESKTOP = &H19&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ALL_USERS_DESKTOP)
Set objFolderItem = objFolder.ParseName("自动关机.lnk")
Set objShortcut = objFolderItem.GetLink
objShortcut.SetIconLocation "%systemroot%\System32\SHELL32.dll", 27
objShortcut.Save
|

http://dato.ys168.com
google search bot
http://dato.minidns.net/ |
|
2008-8-2 13:26 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
谢谢 dato,这个VBS脚本也无法实现带参数的特殊路径。
COPY方法是无法实现的我所要求的,因为我是自动根据软件安装的目录自动替换对应路径,因为有些软件要创建一大堆快捷方式,如果我是先使用RAR压缩后自动解包到对应路径,如果释放目录和源安装目录相同,那么就自动跳过,如果不相同,则使用SHORTCUT命令来自动替换对应路径。
Thanks dato, this VBS script also can't achieve special paths with parameters. The COPY method can't achieve what I requested because I automatically replace the corresponding paths according to the software installation directory. Because some software needs to create a large number of shortcuts. If I first use RAR to compress and then automatically unpack to the corresponding path, if the extraction directory is the same as the source installation directory, then automatically skip; if not the same, then use the SHORTCUT command to automatically replace the corresponding path.
|
|
2008-8-2 14:07 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
试过使用WINRAR打包,也无法建立这种特殊参数的快捷方式。真失望。
I've tried using WINRAR to pack, but I still can't create this special parameter shortcut. Really disappointed.
|
|
2008-8-2 17:37 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
问题已经圆满解决,经过在外国网站疯狂搜索,才发现shortcut有一个特别的转移符号\,呵呵,要保留双引号",那么只要在其前面加上\就可以,由于发现有些快捷方式路径后也有一个\符号,如"D:\UGS\",这些可能产生冲突,所以先面的批处理进行了相应处理,避免了这种情况的发生.经过测试,对于带很多复杂参数的快捷键已经可以完全正确处理了.
@ECHO OFF
REM 当改变了文件路径后批量替换(修复)快捷方式.变量LNKPATH为需要替换的快捷方式文件夹的路径;OLDPATH为原始文件安装路径;NEWPATH为新的移动路径
REM 假设安装了CATIA后移动了文件路径或者要制作绿色CATIA,那么快捷方式路径应该做相应变化
SET LNKPATH="D:\UGS\GTOOLS\SCUT"
SET OLDPATH="D:\UGS"
SET NEWPATH="D:\Program Files\UGS"
SET PATH=%CD%;%CD%\GTOOLS\;%PROGRAMFILES%\WINRAR;%PATH%
IF NOT EXIST ".\GTOOLS\BS.exe" SET ERR=安装支持目录下缺少字符替换工具,安装程序无法继续&&GOTO:ERROR
IF NOT EXIST ".\GTOOLS\SC.exe" SET ERR=安装支持目录缺少快捷方式创建工具,安装程序无法继续&&GOTO:ERROR
FOR /F "DELIMS=" %%I IN ('DIR /B/S "%LNKPATH%\*.LNK"') DO (
SC /F:"%%I" /A:Q>"%TEMP%\SCUT.TXT"
BS "%TEMP%\SCUT.TXT" %OLDPATH% %NEWPATH% /I
BS "%TEMP%\SCUT.TXT" """ "\\"" /I>NUL&CLS
BS "%TEMP%\SCUT.TXT" "\\\\" "\\" /I>NUL&CLS
setlocal enabledelayedexpansion
FOR /F "TOKENS=1,* DELIMS==" %%A IN (%TEMP%\SCUT.TXT) DO CALL SET %%A=%%B
IF DEFINED Arguments IF "!Arguments:~-1!"=="\" (SET Arguments=!Arguments!\)
IF DEFINED WorkingDirectory IF "!WorkingDirectory:~-1!"=="\" (SET WorkingDirectory=!WorkingDirectory!\) ELSE (SET WorkingDirectory=!WorkingDirectory!\\)
SC.EXE /F:"%%I" /A:E /T:"!TargetPath!" /P:"!Arguments!" /W:"!WorkingDirectory!" /I:"!IconLocation!" /D:"鸿越软件" >NUL
endlocal
)
SET ERR=替换修复完成,谢谢您使用鸿越软件制作的该工具&&GOTO:ERROR
:ERROR
>"%TEMP%\Temp.vbs" Echo intAnswer = MsgBox("%ERR%" , vbYes, "鸿越软件温馨提示您!")
cscript //nologo "%TEMP%\Temp.vbs"
IF EXIST "%TEMP%" DEL /F/S/Q/A "%TEMP%\*.*">NUL
EXIT
The problem has been completely solved. After searching frantically on foreign websites, I found that shortcut has a special escape character \, heh. To keep the double quotes ", you just need to add \ in front of it. Since I found that some shortcut paths also have a \ symbol later, such as "D:\UGS\", these might cause conflicts, so the batch processing below made corresponding treatments to avoid this situation. After testing, it can completely and correctly handle shortcuts with many complex parameters.
@ECHO OFF
REM Batch replacement (repair) of shortcuts when the file path is changed. The variable LNKPATH is the path of the shortcut folder to be replaced; OLDPATH is the original file installation path; NEWPATH is the new move path
REM Suppose that after installing CATIA, the file path is moved or a green CATIA is to be made, then the shortcut path should be changed accordingly
SET LNKPATH="D:\UGS\GTOOLS\SCUT"
SET OLDPATH="D:\UGS"
SET NEWPATH="D:\Program Files\UGS"
SET PATH=%CD%;%CD%\GTOOLS\;%PROGRAMFILES%\WINRAR;%PATH%
IF NOT EXIST ".\GTOOLS\BS.exe" SET ERR=The character replacement tool is missing in the installation support directory, and the installation program cannot continue&&GOTO:ERROR
IF NOT EXIST ".\GTOOLS\SC.exe" SET ERR=The shortcut creation tool is missing in the installation support directory, and the installation program cannot continue&&GOTO:ERROR
FOR /F "DELIMS=" %%I IN ('DIR /B/S "%LNKPATH%\*.LNK"') DO (
SC /F:"%%I" /A:Q>"%TEMP%\SCUT.TXT"
BS "%TEMP%\SCUT.TXT" %OLDPATH% %NEWPATH% /I
BS "%TEMP%\SCUT.TXT" """ "\\"" /I>NUL&CLS
BS "%TEMP%\SCUT.TXT" "\\\\" "\\" /I>NUL&CLS
setlocal enabledelayedexpansion
FOR /F "TOKENS=1,* DELIMS==" %%A IN (%TEMP%\SCUT.TXT) DO CALL SET %%A=%%B
IF DEFINED Arguments IF "!Arguments:~-1!"=="\" (SET Arguments=!Arguments!\)
IF DEFINED WorkingDirectory IF "!WorkingDirectory:~-1!"=="\" (SET WorkingDirectory=!WorkingDirectory!\) ELSE (SET WorkingDirectory=!WorkingDirectory!\\)
SC.EXE /F:"%%I" /A:E /T:"!TargetPath!" /P:"!Arguments!" /W:"!WorkingDirectory!" /I:"!IconLocation!" /D:"Hongyue Software" >NUL
endlocal
)
SET ERR=Replacement and repair are completed. Thank you for using the tool made by Hongyue Software&&GOTO:ERROR
:ERROR
>"%TEMP%\Temp.vbs" Echo intAnswer = MsgBox("%ERR%" , vbYes, "Hongyue Software Warm Reminder You!")
cscript //nologo "%TEMP%\Temp.vbs"
IF EXIST "%TEMP%" DEL /F/S/Q/A "%TEMP%\*.*">NUL
EXIT
此帖被 +2 点积分 点击查看详情 评分人:【 mkd 】 | 分数: +2 | 时间:2008-8-4 09:46 |
|
|
|
2008-8-4 08:23 |
|