Category Archives: Visual Basic 6 (VB6)

Partial Path Formatting

Ensures the path contains a trailing backslash. Module Public Sub CheckPath(MyPath$) ‘ Adds the \ to the Application Path when required    MyPath$ = App.Path    If Not Right(MyPath$, 1) = “\” Then        MyPath$ = MyPath$ & “\”    End IfEnd Sub Usage Private Sub Command1_Click()    Dim MyPath As String    Dim FileName As String     FileName = App.EXEName    Call CheckPath(MyPath$)    MsgBox “The location of: ” & FileName & ” is… Read More »

Determine Disk Type

Given a drive letter, returns the type of disk present, if connected. Module Option Explicit ‘API Calls ‘Function GetDriveType’lpRootPathName : string that specifies the root directory of the disk to return information about. If lpRootPathName is an empty string, the function uses the root of the current directory.Public Declare Function GetDriveType Lib “kernel32.dll” Alias “GetDriveTypeA” (ByVal nDrive As… Read More »

Obtain Drive Serial Number

Given a drive letter, this function will return the assigned serial number for the given volume. Module Private Declare Function GetVolumeSerialNumber Lib “kernel32.dll” Alias “GetVolumeInformationA” _    (ByVal lpRootPathName As String, _    ByVal lpVolumeNameBuffer As String, _    ByVal nVolumeNameSize As Long, _    lpVolumeSerialNumber As Long, _    lpMaximumComponentLength As Long, _    lpFileSystemFlags As Long, _    ByVal lpFileSystemNameBuffer As String, _    ByVal nFileSystemNameSize As Long _    ) As Long    Public Function… Read More »

Connect and Disconnect a Network Drive

A handy module to connect to and disconnect from network locations. Module ‘Create a Module named ModNetUseOption Explicit Public Declare Function WNetAddConnection2 Lib “mpr.dll” Alias “WNetAddConnection2A” _(lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUsername As String, _ByVal dwFlags As Long) As Long Public Declare Function WNetCancelConnection2 Lib “mpr.dll” _Alias “WNetCancelConnection2A” (ByVal lpName As String, ByVal dwFlags As… Read More »

Check if a File Exists

A simple way of determining if a file exists. Simply pass it a full path and filename, and it will tell you if it exists, and whether or not it is a zero-byte file. Module Function FileExists(strFile As String) As Integer’********************************************************************************’* Name : FileExists’* Date : Feb-17, 2000’* Author : David Costelloe’* Returns : -1 = Does not… Read More »

Extract File or Path

Extract either a filename or path from a fully qualified pathname. Module Option Explicit Public Function ParsePath(strFullPathName As String, ReturnType As Integer, Optional StripLastBackslash) As String” Returns: Either the path or filename of a fully qualified pathname.’ See below for details.” Called with:’ strFullPathName – STRING (REQUIRED) – the full path and file name of interest’ If strFullPathName… Read More »

Determine File Version Number

This module will show you how to get the file version number of an executable file, given a full path and filename, using Windows API. Module Option Explicit Private Declare Function GetLocaleInfoA Lib “kernel32.dll” (ByVal lLCID As Long, ByVal lLCTYPE As Long, ByVal strLCData As String, ByVal lDataLen As Long) As LongPrivate Declare Sub lstrcpyn Lib “kernel32.dll” (ByVal… Read More »

Enumerate Ports

Using the EnumPorts API, you can list the ports on a local or remote PC with this code. Module Option Explicit ‘API callsPrivate Declare Function EnumPorts Lib “winspool.drv” Alias “EnumPortsA” (ByVal pName As String, ByVal Level As Long, ByVal lpbPorts As Long, ByVal cbBuf As Long, pcbNeeded As Long, pcReturned As Long) As LongPrivate Declare Function lstrlenW Lib… Read More »

Find the COM ports

Using API from Kernel32, this code will show you information about the serial or COM ports on the local computer. Module Option Explicit ‘API DeclarationsPublic Declare Function CreateFile Lib “kernel32.dll” Alias “CreateFileA” (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As… Read More »

Get PDC Name

The NetGetDCName function returns the name of the Primary Domain Controller (PDC) or PDC Emulator for the specified domain. Module Option Explicit’API callsPrivate Declare Function NetGetDCName Lib “netapi32.dll” (ServerName As Any, DomainName As Any, lpBuffer As Long) As LongPrivate Declare Function NetApiBufferFree Lib “netapi32.dll” (ByVal pBuffer As Long) As Long Private Declare Sub CopyMem Lib “kernel32.dll” Alias “RtlMoveMemory”… Read More »