Click here to Skip to main content
6,634,665 members and growing! (20,101 online)
Email Password   helpLost your password?
Languages » VBScript » General     Intermediate

How to get Windows Directory, Computer Name and System Information details

By benoyraj

This small program demonstrates to how to get the windows directory path name, Computer Name, and System information details
VBScript, VB 6, .NET, Win2K, WinXP, Win2003, Dev
Posted:17 May 2004
Views:150,515
Bookmarked:17 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
15 votes for this article.
Popularity: 2.79 Rating: 2.37 out of 5
7 votes, 46.7%
1
4 votes, 26.7%
2
2 votes, 13.3%
3
1 vote, 6.7%
4
1 vote, 6.7%
5

Sample Image - SystemUtility.jpg

Introduction

The utiltity 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 ' Variable to return the path of computer name

strComputerName = Space(250) '
Initilize the buffer to receive the string
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 ' Variable to return the path of Windows Directory
Dim lngWindowsDirLength As Long '
Variable to return the the lenght of the path

strWindowsDir = Space(250) ' Initilize the buffer to receive the string
lngWindowsDirLength = GetWindowsDirectory(strWindowsDir, 250) '
Read the path of the windows directory
strWindowsDir = Left(strWindowsDir, lngWindowsDirLength) ' Extract the windows path from the buffer

GetTheWindowsDirectory = strWindowsDir

Displaying the System Information

The following lines of code will display all the system environment variables in a text box.


Dim intInc As Integer
Dim strDisplay As String

Text1 = ""
' Here we start printing
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 informations.  Also, you identified the importance of System information using Environ variables.  I hope this will helps you if you dont have any prior knowledge of system handle functions.

Benoyraj B

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

benoyraj


Member
Benoyraj is a software developer of Information Technology Division in Memphis,TN.
Location: United States United States

Other popular VBScript articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
GeneralMy vote of 1 PinmemberYazeed Hamdan14:16 12 Sep '09  
GeneralPrinter Utilities PinmemberThangaDharma8:01 6 Oct '05  
GeneralPrinter Utilities PinmemberThangaDharma8:00 6 Oct '05  
GeneralWhy? Pinmemberrexxxa16:16 28 Mar '05  
GeneralVbscript get Computer Name and Windows Path name Pinsusskornniwat@gmail.com23:11 22 Mar '05  
GeneralWhy not.. PinmemberKlaus Weisser7:10 18 May '04  
GeneralRe: Why not.. Pinmembereagleboy14:48 18 May '04  
GeneralRe: Why not.. PinmemberKlaus Weisser20:53 18 May '04  
GeneralRe: Why not.. PinsussAnonymous5:44 24 Sep '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 May 2004
Editor:
Copyright 2004 by benoyraj
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project