Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine Temp Directory

Status
Not open for further replies.
Nov 21, 2000
26
0
0
US
How do I determine what the current users Temp directory is? The users are going to be on Win98, and Windows 2000 Pro so I can not hard code c:\windows\temp
 
I generally use the following function: Environ. For example,

dim strTemp as String

strTemp = Environ("TEMP")

Hope this is of use... John Whyte
jwhyte@skipton.co.uk
 
From the API Text Viewer:

[tt]
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
[/tt]

Call this function like this:
[tt]
Dim sTempPath as String
Dim lRC as Long

sTempPath = space$(300) 'MAX_PATH is 254
lRC = GetTempPath(len(sTempPath), sTempPath)
if lRC = 0 then
[tab]'An error ocurred
endif
[/tt]

Chip H.
 
Or :

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert this code to the module :

Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As _
Long, lParam As Any) As Long
Declare Sub ReleaseCapture Lib "User32" ()
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTCAPTION = 2

'Insert this code to your form:

Public Function GetTmpPath()
Dim strFolder As String
Dim lngResult As Long
strFolder = String(MAX_PATH, 0)
lngResult = GetTempPath(MAX_PATH, strFolder)
If lngResult <> 0 Then
GetTmpPath = Left(strFolder, InStr(strFolder, _
Chr(0)) - 1)
Else
GetTmpPath = &quot;&quot;
End If
End Function

Private Sub Form_Load()
MsgBox GetTmpPath
End Sub

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.
Download Demo version on my Site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top