China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 10:29
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Resolved] The Difficulty of Batch Creating and Modifying Shortcuts with Shortcuts View 1,937 Replies 9
Original Poster Posted 2008-07-31 14:46 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
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 ]
Attachments
SCUT.rar (108.6 KiB, Downloads: 137)
Floor 2 Posted 2008-07-31 15:55 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
No one answered, so I'll bump it up myself.
Floor 3 Posted 2008-07-31 16:10 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Hehe, why are all the experts lurking today. Still waiting.
Floor 4 Posted 2008-07-31 16:25 ·  中国 广东 广州 电信
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Floor 5 Posted 2008-08-01 14:13 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Experts are really good at lurking, and no one has visited yet.
Floor 6 Posted 2008-08-02 12:07 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
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...
Floor 7 Posted 2008-08-02 13:26 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
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
Floor 8 Posted 2008-08-02 14:07 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
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.
Floor 9 Posted 2008-08-02 17:37 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
I've tried using WINRAR to pack, but I still can't create this special parameter shortcut. Really disappointed.
Floor 10 Posted 2008-08-04 08:23 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
mkd +2 2008-08-04 09:46
Forum Jump: