取得暫存路徑

使用API

API名稱:GetTempPath
動態連結程式庫: kernel32.dll

VB6入口點:GetTempPathA
VB.NET入口點: GetTempPathW


程式說明

取得暫存(temp)資料夾之位置。


VB6程式碼

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
    (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Dim buffer As String, length As Integer


Private Sub Command1_Click()
    buffer = Space$(512)
    length = GetTempPath(Len(buffer), buffer)
    Text1.Text = Left$(buffer, length)
End Sub

VB.NET程式碼

Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1
    Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" (ByVal nBufferLength As Integer, ByVal lpBuffer As String) As Integer

    Dim temppath As String
    Dim slength As Integer


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        temppath = Space(255)
        slength = GetTempPath(255, temppath)
        temppath = Microsoft.VisualBasic.Left(temppath, slength)
        TextBox1.Text = temppath
    End Sub
End Class

下載