The VB trick to get the path of the current temporary directory:
Private Declare Function GetTempPath Lib \"kernel32\" Alias \"GetTempPathA\" (ByVal nBufferL
Const WindowsFolder = 0
Const SystemFolder = 1
Const TemporaryFolder = 2
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim tempFolder: tempFolder = fso.GetSpecialFolder(TemporaryFolder)
WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)
It took me a while to find it on Google. So for the next one looking for the same as me...
Based entirely on AnthonyWJones' answer, here is my solution:
Public Enum SpecialFolder
WindowsFolder = 0
SystemFolder = 1
TempFolder = 2
End Enum
Public Function GetFolder(folder As Integer) As String
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
GetFolder = objFSO.GetSpecialFolder(folder)
End Function
So, for example, you'd use GetFolder(TempFolder)
to obtain the pathname of the user's temp folder.
Another possibility:
CreateObject("WScript.Shell").ExpandEnvironmentStrings("%Temp%")
You can also keep using the GetTempPath
API. It's a bit tricky to call APIs from vbscript though. Here are some pointers on how to make Win32 API calls from vbscript:
Reference 1
Reference 2
Reference 3