Introduction
The utility helps you to understand how to return computer system name/Windows system path and system information from a Windows system (95, 98, NT and XP).
System Library Files
You have to include the following system DLL files into your application.
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32.dll" _
Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
GetTheComputerName Function
The following GetTheComputerName
function returns the computer name from your system. See how the code works with System DLL file.
Public Function GetTheComputerName() As String
Dim strComputerName As String
strComputerName = Space(250) GetComputerName strComputerName, Len(strComputerName)
strComputerName = Mid(Trim$(strComputerName), 1, Len(Trim$(strComputerName)) - 1)
GetTheComputerName = strComputerName
End Function
GetTheWindowsDirectory Function
The following GetTheWindowsDirectory
function returns the Windows system path from your system. See how the code works with System DLL file.
Public Function GetTheWindowsDirectory() As String
Dim strWindowsDir As String Dim lngWindowsDirLength As Long
strWindowsDir = Space(250) lngWindowsDirLength = GetWindowsDirectory
(strWindowsDir, 250) strWindowsDir = Left(strWindowsDir,
lngWindowsDirLength)
GetTheWindowsDirectory = strWindowsDir
Displaying the System Information
The following lines of code will display all the system environment variables in a textbox
.
Dim intInc As Integer
Dim strDisplay As String
Text1 = ""
For intInc = 1 To 35
strDisplay = strDisplay & Environ(intInc)
strDisplay = strDisplay & Space(5)
Next intInc
Text1 = strDisplay
Conclusion
This small program demonstrates how to call the system functions from the Windows DLL file and implement into your system. From this program, you found how to call GetComputerName
and GetWindowsSystemDirectoryPath
information. Also, you identified the importance of System information using Environ
variables. I hope this will help you if you don't have any prior knowledge of system handle functions.
History
- 17th May, 2004: Initial post