473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Getting the systems Temp Directory

I was wondering, what's the "proper" (hehe) way to retrieve the system's
temp directory in VB 6.

Like for example, on my Windows XP machine the temp directory that is used
by programs for their temporary files is "C:\Documents And
Settings\MyUserName\Local Settings\Temp". Somehow those programs must look
up that value, and I'd like to do the same for my VB program.

Now I know I can look this up in the registry under
HKEY_CURRENT_USER\Environment, but I have no way of knowing if this
technique would be specific to WinXP.

Is there a Win32 API call that retrieves the temp folder? Or perhaps a way
of reading the "TMP" or "TEMP" environment variables?

Thanks....
Jul 17 '05 #1
3 27607
Yes, the GetTempPath API will return it. See
http://vbnet.mvps.org/code/system/windirs.htm

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Adam Parkin" <sk****@dfaslk.com> wrote in message
news:9BWjc.40469$NG2.1048@edtnps84...
: I was wondering, what's the "proper" (hehe) way to retrieve the system's
: temp directory in VB 6.
:
: Like for example, on my Windows XP machine the temp directory that is used
: by programs for their temporary files is "C:\Documents And
: Settings\MyUserName\Local Settings\Temp". Somehow those programs must
look
: up that value, and I'd like to do the same for my VB program.
:
: Now I know I can look this up in the registry under
: HKEY_CURRENT_USER\Environment, but I have no way of knowing if this
: technique would be specific to WinXP.
:
: Is there a Win32 API call that retrieves the temp folder? Or perhaps a
way
: of reading the "TMP" or "TEMP" environment variables?
:
: Thanks....
:
:

Jul 17 '05 #2
"Adam Parkin" <sk****@dfaslk.com> wrote in message news:<9BWjc.40469$NG2.1048@edtnps84>...
I was wondering, what's the "proper" (hehe) way to retrieve the system's
temp directory in VB 6.

Like for example, on my Windows XP machine the temp directory that is used
by programs for their temporary files is "C:\Documents And
Settings\MyUserName\Local Settings\Temp". Somehow those programs must look
up that value, and I'd like to do the same for my VB program.

Now I know I can look this up in the registry under
HKEY_CURRENT_USER\Environment, but I have no way of knowing if this
technique would be specific to WinXP.

Is there a Win32 API call that retrieves the temp folder? Or perhaps a way
of reading the "TMP" or "TEMP" environment variables?


Environ$("temp")
Environ$("tmp")

Private Declare Function GetTempPath Lib "kernel32" Alias
"GetTempPathA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal
lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long

Public Function TempFile() As String
' return temporary file name or empty string if error
Dim sDir As String
Dim sBuff As String
Dim x As Long
sBuff = Space$(512)
sDir = Space$(512)
x = GetTempPath(Len(sDir), sDir)
x = GetTempFileName(sDir, "TMP", 0, sBuff)
x = InStr(sBuff, vbNullChar)
If x > 0 Then
TempFile = Left(sBuff, x - 1)
Else
TempFile = ""
End If
End Function
Jul 17 '05 #3
That was exactly what I was looking for, thanks!

Adam

"Randy Birch" <rg************@mvps.org> wrote in message
news:Sr******************@news01.bloor.is.net.cabl e.rogers.com...
Yes, the GetTempPath API will return it. See
http://vbnet.mvps.org/code/system/windirs.htm

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Adam Parkin" <sk****@dfaslk.com> wrote in message
news:9BWjc.40469$NG2.1048@edtnps84...
: I was wondering, what's the "proper" (hehe) way to retrieve the system's
: temp directory in VB 6.
:
: Like for example, on my Windows XP machine the temp directory that is used : by programs for their temporary files is "C:\Documents And
: Settings\MyUserName\Local Settings\Temp". Somehow those programs must
look
: up that value, and I'd like to do the same for my VB program.
:
: Now I know I can look this up in the registry under
: HKEY_CURRENT_USER\Environment, but I have no way of knowing if this
: technique would be specific to WinXP.
:
: Is there a Win32 API call that retrieves the temp folder? Or perhaps a
way
: of reading the "TMP" or "TEMP" environment variables?
:
: Thanks....
:
:

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: john bailo | last post by:
I noticed for the first time there is a temp directory in the \winnt\system32 directory. For a web services application, this caused me grief as when the server c: drive filled up, the temp...
0
by: Matthew Fitzpatrick | last post by:
My application has a settings class that is serialized to save and deserialized to load. I'm having a problem where i catch the WM_QUERYENDSESSION event via WinProc to save my application's...
5
by: Patrick | last post by:
Hello - I am working on a program that creates a small temp file. The ideal would be it creates the file in the user %temp% directory - whatever that is - the default is %USERPROFILE%\Local...
2
by: Lars Netzel | last post by:
I'm trying to write a PDF to disk on the server (crystal reports export) I'm getting aproblem that Access is denied to save the file to disk and reading here (you don't need to read):...
0
by: Andrés G. Aragoneses | last post by:
When trying to use a webservices, not very often I obtain the following exception: Server was unable to process request. ---> Access to the temp directory is denied. Identity 'NT...
6
by: Najd | last post by:
Hi All, I'm developping a DLL that requiers the path of the Temp directory of the user logged. I used GetTempPath(), GetEnvironmentVariable() and ExpandEnvironmentStrings(), but the 3 methodes...
0
by: oritc123 | last post by:
Hello . I am having the following error when I run my application under Windows Vista ( it runs fine under Windows XP ) : "Access to the temp directory is denied. Identity 'ORITSLAPTOP\orit'...
3
by: hardieca | last post by:
Hi, I have decorated a number of my classes with a custom attribute. I would like to loop through every type in my application, sniff for the attribute, and eventually publish the entire list of...
6
by: Aussie Rules | last post by:
Hi, In my application I need to write an XML file to disk, but am concerned that permission might be a problem. The file only needs to be written out and used for another reason and can then...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.