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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now