WWindows Directory

Posted on 1999-01-24
Last Modified: 2012-05-04
how can I define the windows directory, if its "win95" or "windows" or if its in drive C: or D: or......
and how can I show the Path of windows, Ex. "C:\win95" or "D:\windows" or.....,,,  in Visual Basic.   Thank u
Question by:hisham1
  • 3
  • 2
LVL 44

Accepted Solution

bruintje earned 10 total points
ID: 1470355
This does more then you asked for but hey, it's free.......

' Name: Displayresults
' Description:Gives windows and system information
'      . windows version,system directory,windows direct
'     ory, memory, disk information
' By: Siddiqui
' Inputs:None
' Returns:disk space, windows directory, version,
' Assumes:Basically it ueses windows api to get system information and users needs to create labels for the particular spaces

' Side Effects:none
'Code provided by Planet Source Code(tm) 'as is', without
'     warranties as to performance, fitness, merchantability,
'     and any other warranty (whether expressed or implied).

Dim dl&, windirec&, winsystem&
Dim s$, sysbuffer$, drivetype&, drivebuffer$
Dim spaceloc%
Dim FreeBytes&, TotalBytes&
Dim buffer As String, size As Long
buffer$ = Space(500)
sysbuffer$ = Space(500)
drivebuffer$ = Space(500)
s$ = Drive1.Drive
' Is there a space? Strip off the volume name if s
'     o
spaceloc = InStr(s$, " ")

If spaceloc > 0 Then
    s$ = left$(s$, spaceloc - 1)
End If

    If right$(s$, 1) <> "\" Then s$ = s$ & "\"
        dl& = GetDiskFreeSpace(s$, SectorsPerCluster, BytesPerSector, NumberOfFreeClustors, TotalNumberOfClustors)
        lblSectors = Format(SectorsPerCluster, "#,0")
        lblBytes = Format(BytesPerSector, "#,0")
        lblFree = Format(NumberOfFreeClustors, "#,0")
        lblClusters = Format(TotalNumberOfClustors, "#,0")
        TotalBytes = TotalNumberOfClustors * SectorsPerCluster * BytesPerSector
        lblTotalBytes = Format(TotalBytes, "#,0")
        FreeBytes = NumberOfFreeClustors * SectorsPerCluster * BytesPerSector
        lblTotalFree = Format(FreeBytes, "#,0")
        lblPercent = Format(FreeBytes / TotalBytes, "Percent")
        drivetype = GetDriveType(s$)
        Select Case drivetype
        Lbldrvtype = "Unrecognized"
        Lbldrvtype = "doesn't exist"
        Case DRIVE_CDROM
        Lbldrvtype= "CD-ROM"
        Case DRIVE_FIXED
        Lbldrvtype= "I.E. Hard Disk"
        Case DRIVE_RAMDISK
        Lbldrvtype = "RAM disk"
         Case DRIVE_REMOTE
        Lbldrvtype= "I.E Network drive."
        Lbldrvtype= "I.E. Floppy Disk."
    End Select

        windirec = GetWindowsDirectory(buffer$, 500)
        winsystem = GetSystemDirectory(sysbuffer$, 500)
        Lblsystemdirec = sysbuffer$
        '     'windows info with system memory status
         Dim verinfo As OSVERSIONINFO
         Dim build As String, ver_major As String, ver_minor As String
         Dim ret As Long
         Dim MSG As String
         verinfo.dwOSVersionInfoSize = Len(verinfo)
         ret = GetVersionEx(verinfo)

         If ret = 0 Then
             MsgBox "Error Getting Version Information"

         End If

             Select Case verinfo.dwPlatformId
             Case 0
             MSG = MSG & "Windows 32s "
             Case 1
             MSG = MSG & "Windows 95 "
             Case 2
             MSG = MSG & "Windows NT "
         End Select

             ver_major = verinfo.dwMajorVersion
             ver_minor = verinfo.dwMinorVersion
             build = msg & verinfo.dwBuildNumber
             Lblwindows = MSG & ver_major & "." & ver_minor
            '      ' Get CPU type and operating mode.
             Dim sysinfo As SYSTEM_INFO
             GetSystemInfo sysinfo
            Select Case sysinfo.dwProcessorType
             Case PROCESSOR_INTEL_386
             MSG = "Intel 386"
             Case PROCESSOR_INTEL_486
             MSG = "Intel 486"
             MSG = "Intel Pentium"
             Case PROCESSOR_MIPS_R4000
             MSG = "MIPS R4000"
             Case PROCESSOR_ALPHA_21064
             MSG = "DEC Alpha 21064"
             Case Else
             MSG = "(unknown)"
         End Select

             Lblcputype = MSG
            '      ' Get free memory.
             Dim memsts As MEMORYSTATUS
             Dim memory As Long
             GlobalMemoryStatus memsts
             memory = memsts.dwTotalPhys
             Lblphysicaltotal = Format$(memory \ 1024, "###,###,###") & "K"
             memory& = memsts.dwAvailPhys
             Lblphysicalavial = Format$(memory \ 1024, "###,###,###") & "K"
             memory& = memsts.dwTotalVirtual
             LblVirutaltotal = Format$(memory \ 1024, "###,###,###") & "K"
             memory& = memsts.dwAvailVirtual
             LblVirtualavial = Format$(memory \ 1024, "###,###,###") & "K"

As you see it's not my source but it worked for me
Hope this helps,


Author Comment

ID: 1470356
Thank u my friend, I'll try it
LVL 44

Expert Comment

ID: 1470357
Good, and you can strip off what you don't need and stock it for later use. :O)

Author Comment

ID: 1470358
Maybe I'm missing something in ur code,  It doesnt work
can u explain More?
LVL 44

Expert Comment

ID: 1470359
Well we try it with only the windows directory

Put a commandbutton and textfield on a form and put this code in

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Function GetWinDir() As String

    Dim Temp As String * 256
    Dim x As Integer
    x = GetWindowsDirectory(Temp, Len(Temp)) ' Make API Call (Temp will hold return value)
    GetWinDir = Left$(Temp, x) ' Trim Buffer and return string
End Function

Private Sub Command1_Click()
   Text1.Text = GetWinDir
End Sub

Now the text contains the return value which should be the windows directory.

Good Luck!


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question