Solved

WWindows Directory

Posted on 1999-01-24
5
153 Views
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
0
Comment
Question by:hisham1
  • 3
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
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
        Case DRIVE_TYPE_UNDTERMINED
        Lbldrvtype = "Unrecognized"
        Case DRIVE_ROOT_NOT_EXIST
        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."
         Case DRIVE_REMOVABLE
        Lbldrvtype= "I.E. Floppy Disk."
    End Select

        windirec = GetWindowsDirectory(buffer$, 500)
        Lblwindirec=buffer$
        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

         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"
             Case PROCESSOR_INTEL_PENTIUM
             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,
:O)
brUINTje.

0
 

Author Comment

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

Expert Comment

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

Author Comment

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

Expert Comment

by:bruintje
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!
:O)

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

747 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

13 Experts available now in Live!

Get 1:1 Help Now