How do I access the "temp directory" environment variable in VB

HI,

I need to get the location of the temp directory from a VB call.

How do I do that (api call, etc)?

Thanks,

chris Schene
Christopher ScheneSystem Engineer/Software EngineerAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
One way...

    Private Sub Command1_Click()
        Dim UserTempFolder As String
        UserTempFolder = Environ("Temp")
        Debug.Print UserTempFolder
    End Sub
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You want the Users temp folder?...or the Machines temp folder?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Also what version VB are you working in?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
The user's temp folder...VB 6.0
0
 
TiwariVikasConnect With a Mentor Commented:
Hi cshene ,

you can access any environment variable with following code:

Dim objShell as object
Dim strTemp as string
Set objShell = CreateObject("Wscript.Shell")
strTemp = objShell.ExpandEnvironmentStrings("%temp%")
msgbox strTemp
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Why use a late bound scripting object when the Environ() function does the same thing?...

Both examples produced the same output on my system.  (WinXP SP2)
0
 
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.