我正在尝试检查网络位置快捷方式是否在我的网络快捷方式中(如果存在)将其删除并再创建一个名为homedrive的快捷方式。它如何使homedrive但不删除旧的。旧的用户名hense注册为什么我用%username%。我只需要帮助删除
提前感谢
Const NETHOOD = &H13&
Set objWSHShell = CreateObject("Wscript.Shell")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETHOOD)
Set objFolderItem = objFolder.Self
strNetHood = objFolderItem.Path
Set Shell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Networkpath = Shell.SpecialFolders("NETHOOD")
shortcut = Networkpath & "\%username%.lnk"
If FSO.FileExists(shortcut) Then
FSO.DeleteFile shortcut
End If
strShortcutName = "HomeDrive"
strShortcutPath = "\\homer-2\IT$\%username%"
Set objShortcut = objWSHShell.CreateShortcut _
(strNetHood & "\" & strShortcutName & ".lnk")
objShortcut.TargetPath = strShortcutPath
objShortcut.Save
答案 0 :(得分:0)
此
>> Set Shell = CreateObject("WScript.Shell")
>> Set FSO = CreateObject("Scripting.FileSystemObject")
>> sFSpec = FSO.BuildPath("%HOME%", "tmp.txt")
>> WScript.Echo CStr(FSO.FileExists(sFSpec)), sFSpec
>> sFSpec = Shell.ExpandEnvironmentStrings(sFSpec)
>> WScript.Echo CStr(FSO.FileExists(sFSpec)), sFSpec
>>
False %HOME%\tmp.txt
True C:\Documents and Settings\eh\tmp.txt
>>
证明FSO不会自动扩展环境变量。所以
shortcut = Networkpath & "\%username%.lnk"
If FSO.FileExists(shortcut) Then
永远不会成真。使用Shell.ExpandEnvironmentStrings()
。