在用户桌面上创建当前文件夹的快捷方式 [英] Create a shortcut to current folder on user's desktop
问题描述
我想在用户桌面上自动创建指向当前文件夹的快捷方式.我正在使用的某些用户不知道如何创建快捷方式或如何拖放文件夹.我只想创建一个名为单击我在桌面上将此文件夹创建快捷方式"的文件,即可在我想要的任何文件夹中使用.
I would like to automatically create a shortcut to the current's folder on the user's desktop. Some users I'm working with don't know how to create shortcuts or how to drag and drop a folder. I just want to create a file named "CLICK ME TO CREATE A SHORTCUT TO THIS FOLDER ON YOUR DESKTOP" that will work in any folder I want.
例如,如果我运行C:\ myRandomFolder \ CLICK ME.无论如何,我希望它在"D:\ Documents and Settings \%username%"上创建一个名为"myRandomFolder"的"C:\ myRandomFolder \"快捷方式. \桌面".
For example, if I run C:\myRandomFolder\CLICK ME.whatever, I want it to create a shortcut to "C:\myRandomFolder\" named "myRandomFolder" on "D:\Documents and Settings\%username%\Desktop".
我想知道是否最好使用批处理文件(.bat),VB脚本(.vbs)或任何其他脚本语言来执行此操作.最简单,更好的方法是什么?
I'm wondering if I'm better using a batch file (.bat), VB Script (.vbs) or any other scripting language to do so. What would be the easiest and better way of doing it?
推荐答案
最好的方法最终似乎是VBS脚本.这是我终于正常工作的地方:
The best way finally seems to be a VBS Script. Here is what I finally got working right:
Option Explicit
On Error Resume Next
Private WshShell
Private strDesktop
Private oShellLink
Private aSplit
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
aSplit = Split(WScript.ScriptFullName, "\")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & aSplit(Ubound(aSplit) - 1) & ".lnk")
oShellLink.TargetPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
oShellLink.WindowStyle = 1
oShellLink.Description = "Shortcut Script"
oShellLink.WorkingDirectory = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
oShellLink.Save
MsgBox "Shortcut to " & Replace(WScript.ScriptFullName, WScript.ScriptName, "") & " added yo your desktop!"
这篇关于在用户桌面上创建当前文件夹的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!