[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

WWindows Directory

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
  • 3
  • 2
1 Solution
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,

hisham1Author Commented:
Thank u my friend, I'll try it
Good, and you can strip off what you don't need and stock it for later use. :O)
hisham1Author Commented:
Maybe I'm missing something in ur code,  It doesnt work
can u explain More?
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now