vbscript to rename a shortcut
Hi,
I need a vbscript to remove the file extension from the shortcutname.
for eg, readme.txt - the extn .txt need to be removed.
i tried with the below script,it removes the file extension but while launching the file again it browses for the file again.
Option Explicit
Dim objShell, objFSO, strAllUsersProfile
Set objShell = CreateObject("Wscript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strAllUsersProfile = objShell.ExpandEnvironmentStrings("%ProgramData%")
If objFSO.FileExists(trim(strAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\test\New Text Document.txt")) then
objFSO.MoveFile strAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\test\New Text Document.txt", strAllUsersProfile & "\Start Menu\Programs\test\New Text Document"
End If
Set objShell = Nothing
Set objFSO = Nothing
I need a vbscript to remove the file extension from the shortcutname.
for eg, readme.txt - the extn .txt need to be removed.
i tried with the below script,it removes the file extension but while launching the file again it browses for the file again.
Option Explicit
Dim objShell, objFSO, strAllUsersProfile
Set objShell = CreateObject("Wscript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strAllUsersProfile = objShell.ExpandEnvironmentStrings("%ProgramData%")
If objFSO.FileExists(trim(strAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\test\New Text Document.txt")) then
objFSO.MoveFile strAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\test\New Text Document.txt", strAllUsersProfile & "\Start Menu\Programs\test\New Text Document"
End If
Set objShell = Nothing
Set objFSO = Nothing
0 Comments
[ - ] Hide Comments

so that the conversation will remain readable.
Answer this question
or Comment on this question for clarity
Answers
Option Explicit
Dim objShell, objFSO, strAllUsersProfile
Set objShell = CreateObject("Wscript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strAllUsersProfile = objShell.ExpandEnvironmentStrings("%ProgramData%")
If objFSO.FileExists(trim(strAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\test\New Text Document.txt")) then
objFSO.MoveFile strAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\test\New Text Document.txt", strAllUsersProfile & "\Start Menu\Programs\test\New Text Document"
End If
Set objShell = Nothing
Set objFSO = Nothing
What you are doing here is renaming a file put in a location meant for application shortcuts and you are doing that well using your script!
Files without extension would actually look out for program using which it should execute. Only a shortcut file would look out for the target file location.
Files with .lnk extension are shortcuts. If your shortcut does display the file extension then the name of the shortcut might be "New Text Document.txt.lnk" and you might want to rename it to "New Text Document.lnk".
Please log in to comment
Comments