批处理文件 - 从 ALLUSERS 桌面删除快捷方式

Dam*_*ien 3 windows-7 windows-vista symbolic-link unattended batch-file

在 Vista/7 中,如果我尝试使用以下命令删除快捷方式 -:

del "%allusersprofile%\Desktop\MyShortcut.lnk"
Run Code Online (Sandbox Code Playgroud)

...Windows 将此文件夹视为空文件夹,并且不会删除该文件。

环境变量“allusersprofile”指向“C:\ProgramData”,但“Desktop”实际上是指向 C:\Users\Public\Desktop 文件夹的软符号链接。

问题似乎是这些软链接只是 Window Explorer 的快捷方式,无法被 cmd 提示或批处理文件识别。

我能看到的唯一解决方案是执行以下操作-:

经验值:

del "%allusersprofile%\Desktop\MyShortcut.lnk"
Run Code Online (Sandbox Code Playgroud)

远景/7:

del "%PUBLIC%\Desktop\MyShortcut.lnk"
Run Code Online (Sandbox Code Playgroud)

两种操作系统有没有通用的解决方案?

Pen*_*der 5

正如 Garrett 在对这个问题的评论中所述,我看到的唯一解决方案如下:

SET Version=XP

VER | FINDSTR /IL "6.1." > NUL
IF %ERRORLEVEL% EQU 0 SET Version=7

IF %Version% EQU 7  (
 del "%PUBLIC%\Desktop\MyShortcut.lnk"
)
IF %Version% EQU XP  (
 del "%allusersprofile%\Desktop\MyShortcut.lnk"
)
Run Code Online (Sandbox Code Playgroud)

有人可能会注意到,根据这个StackOverflow问题和Raymond Chen的博客文章, a dirof%allusersprofile%\Desktop\<directory>应该在 XP 和 7 上都给出正确的结果,但根据我的经验,它没有。