VBScript get temp folder

删除回忆录丶 提交于 2021-02-08 06:03:33

问题


fso.GetSpecialFolder(2) correctly returns the temp folder for me, when run from a VBS file. However, when run from within an Autodesk Revit journal file, which has historically been VBS compliant, I get back the proper path and a GUID after Temp. I had never seen this before, and I am unsure if this is perhaps a known issue in newer builds of Windows 10 (it's been about three years since I tested this), or is this more likely an issue with Autodesk's implementation of VBScript support? I suspect the latter. Which then raises the question, is there another good way to get the full temp path in VBScript? I could use

Dim strUser : strUser = CreateObject("WScript.Network").UserName
"C:\Users\" & strUser & "\AppData\Local\Temp"

It's just been so long since I played with VBS, I'm not remembering if there is a better answer, or this is the consistently workable way to go. And, more than anything I want to know if .GetSpecialFolder(2) is broken in some way in Windows, or just by Autodesk.


回答1:


Isn't it logical to have different values on different environments / scripting hosts?

GetSpecialFolder(2) simply returns the process environment variable named TMP. Any change on that variable -which is quite legal-, affects the value that GetSpecialFolder(2) returns.

GetSpecialFolder method

Constant: TemporaryFolder
Value: 2
The Temp folder is used to store temporary files. Its path is found in the TMP environment variable.

Since GetSpecialFolder(2) will always return an existing directory path I probably would use it with the thought that this is intended by the environment; the Autodesk Revit.

Other than that, I'd use something like below if I want the usual temporary path because even they are rare, there are installations where system drive is not C:. Relying on %localappdata% makes more sense in that manner.

Set WshShell = CreateObject("Wscript.Shell")
TempPath = WshShell.ExpandEnvironmentStrings("%localappdata%\Temp")


来源:https://stackoverflow.com/questions/63161269/vbscript-get-temp-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!