1. Description

    Functions to:

    • Get the user name
    • Get the temporary directory
    • Get the name of a temporary file for a fiven directory and a given prefix. 
  2. Answer

    Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
    As Long Public 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 Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String)
    As Long Public Sub test() Dim sUserName As String Dim sTempPath As String Dim sTempFileName As String Dim lSize As Long Dim lReturn
    As Long ' Get UserName sUserName = Space(255) lSize = Len(sUserName) lReturn = GetUserName(sUserName, lSize)
    sUserName = Left(sUserName, lSize - 1) ' Get Temp-Directory sTempPath = Space(255) lReturn = GetTempPath(Len(sTempPath), sTempPath) sTempPath = Left(sTempPath, lReturn) ' Get Name of a Temp File for a given directory and a given prefix sTempFileName = Space(255) lReturn = GetTempFileName(sTempPath, "TMP", 0, sTempFileName) sTempFileName = Left(sTempFileName, InStr(sTempFileName, Chr(0)) - 1) End Sub 

Date created:
01/22/2015 11:38:32
Last updated:
02/11/2015 10:25:40
Product(range):
OMS-500
Print