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

Posted on 2006-06-22
Last Modified: 2013-11-13

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

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


chris Schene
Question by:Christopher Schene
  • 4
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16964294
You want the Users temp folder?...or the Machines temp folder?
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16964297
Also what version VB are you working in?

Author Comment

by:Christopher Schene
ID: 16964360
The user's temp folder...VB 6.0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 86

Accepted Solution

Mike Tomlinson earned 275 total points
ID: 16964377
One way...

    Private Sub Command1_Click()
        Dim UserTempFolder As String
        UserTempFolder = Environ("Temp")
        Debug.Print UserTempFolder
    End Sub

Assisted Solution

TiwariVikas earned 75 total points
ID: 16966765
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
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16968797
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)

Author Comment

by:Christopher Schene
ID: 16975003

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 138
Auto-indent certain lines in Notepad++ 10 145
SQL Insert parts by customer 12 53
MySQL programmer starter 25 28
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question