Windows API

Windows API

I’m writing a program which needs to clean up the temp files which are in the Temp directory as define by the Temp Environment setting. I don’t want the program to assume that the Temp directory is always C:WindowsTemp. There for I was wondering if there is an API or some other method to determine where is the Temp directory on the users PC. The program is being written in VB 3 Pro and running under Windows95, and all people using this program are running Windows95 as well.

Here’s an answer from my new book about this exact API call:

The GetTempPath API call returns the current temporary directory in use bythe system. This lets you keep your own temporary files confined to aknown location. In addition, you don’t have to guess where you can putthem or have to resort to putting them in the home directory.

The code for the TempDirectory function is listed here:

Public Function TempDirectory() As String   Dim sBuffer As String   Dim iBufLen As Long   Dim iReturn As Long      iBufLen = BUFFER_LENGTH   sBuffer = Space(BUFFER_LENGTH)      iReturn = GetTempPath(iBufLen, sBuffer)   TempDirectory = Left$(sBuffer, iBufLen – 1)End Function
Next, add this API declaration to the declarations section of the module:
Declare Function GetTempPath _   Lib “kernel32” _   Alias “GetTempPathA” _   (ByVal nBufferLength As Long, _   ByVal lpBuffer As String) As Long
That’s all there is to it. Try this line of code somewhere in yourapplication:
Debug.Print TempDirectory
That will probably print something like this line:
Either way, it’s the temporary directory in use by Windows, so you can besure it exists.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several