Microsoft KB Archive/213267: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
(One intermediate revision by the same user not shown) | |||
Line 122: | Line 122: | ||
'line. | 'line. | ||
Declare Function GetVersionEx Lib | Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _ | ||
(LpVersionInformation As OSVERSIONINFO) As Long | (LpVersionInformation As OSVERSIONINFO) As Long | ||
Declare Sub GlobalMemoryStatus Lib | Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As _ | ||
MEMORYSTATUS) | MEMORYSTATUS) | ||
Declare Sub GetSystemInfo Lib | Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As _ | ||
SYSTEM_INFO) | SYSTEM_INFO) | ||
Line 149: | Line 149: | ||
ret = GetVersionEx(verinfo) | ret = GetVersionEx(verinfo) | ||
If ret = 0 Then | If ret = 0 Then | ||
MsgBox | MsgBox "Error Getting Version Information" | ||
End | End | ||
End If | End If | ||
Line 155: | Line 155: | ||
Select Case verinfo.dwPlatformId | Select Case verinfo.dwPlatformId | ||
Case 0 | Case 0 | ||
msg = msg + | msg = msg + "Windows 32s " | ||
Case 1 | Case 1 | ||
msg = msg + | msg = msg + "Windows 95/98 " | ||
Case 2 | Case 2 | ||
msg = msg + | msg = msg + "Windows NT/2000 " | ||
End Select | End Select | ||
Line 165: | Line 165: | ||
ver_minor = verinfo.dwMinorVersion | ver_minor = verinfo.dwMinorVersion | ||
Build = verinfo.dwBuildNumber | Build = verinfo.dwBuildNumber | ||
msg = msg & | msg = msg & ver_major & "." & ver_minor | ||
msg = msg & | msg = msg & " (Build " & Build & ")" & NewLine & NewLine | ||
' Get CPU type and operating mode. | ' Get CPU type and operating mode. | ||
Dim sysinfo As SYSTEM_INFO | Dim sysinfo As SYSTEM_INFO | ||
GetSystemInfo sysinfo | GetSystemInfo sysinfo | ||
msg = msg + | msg = msg + "CPU: " | ||
Select Case sysinfo.dwProcessorType | Select Case sysinfo.dwProcessorType | ||
Case PROCESSOR_INTEL_386 | Case PROCESSOR_INTEL_386 | ||
msg = msg + | msg = msg + "Intel 386" + NewLine | ||
Case PROCESSOR_INTEL_486 | Case PROCESSOR_INTEL_486 | ||
msg = msg + | msg = msg + "Intel 486" + NewLine | ||
Case PROCESSOR_INTEL_PENTIUM | Case PROCESSOR_INTEL_PENTIUM | ||
msg = msg + | msg = msg + "Intel Pentium" + NewLine | ||
Case PROCESSOR_MIPS_R4000 | Case PROCESSOR_MIPS_R4000 | ||
msg = msg + | msg = msg + "MIPS R4000" + NewLine | ||
Case PROCESSOR_ALPHA_21064 | Case PROCESSOR_ALPHA_21064 | ||
msg = msg + | msg = msg + "DEC Alpha 21064" + NewLine | ||
Case Else | Case Else | ||
msg = msg + | msg = msg + "(unknown)" + NewLine | ||
End Select | End Select | ||
Line 194: | Line 194: | ||
GlobalMemoryStatus memsts | GlobalMemoryStatus memsts | ||
memory = memsts.dwTotalPhys | memory = memsts.dwTotalPhys | ||
msg = msg + | msg = msg + "Total Physical Memory: " | ||
msg = msg + Format(memory \ 1024, | msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine | ||
memory = memsts.dwAvailPhys | memory = memsts.dwAvailPhys | ||
msg = msg + | msg = msg + "Available Physical Memory: " | ||
msg = msg + Format(memory \ 1024, | msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine | ||
memory = memsts.dwTotalVirtual | memory = memsts.dwTotalVirtual | ||
msg = msg + | msg = msg + "Total Virtual Memory: " | ||
msg = msg + Format(memory \ 1024, | msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine | ||
memory = memsts.dwAvailVirtual | memory = memsts.dwAvailVirtual | ||
msg = msg + | msg = msg + "Available Virtual Memory: " | ||
msg = msg + Format(memory \ 1024, | msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine | ||
MsgBox msg, vbOKOnly, | MsgBox msg, vbOKOnly, "System Info" | ||
End Sub | End Sub | ||
</pre></li> | </pre></li> |
Latest revision as of 12:50, 21 July 2020
Article ID: 213267
Article Last Modified on 8/22/2007
APPLIES TO
- Microsoft Excel 2000 Standard Edition
This article was previously published under Q213267
For a Microsoft Excel 97 and earlier version of this article, see 152601.
IN THIS TASK
SUMMARY
In Microsoft Excel you can programmatically obtain system status information and display it in a worksheet. This step-by-step article provides a sample Microsoft Visual Basic for Applications Sub procedure that displays the following information by using Windows API functions:
- The Windows version number with the GetVersionEx API function.
- The CPU processor type with the GetSystemInfo API function.
- The amount of free memory with the GlobalMemoryStatus API function.
Sample Code to Get Windows Status Information
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
To get Windows status information by using Windows API calls, follow these steps:
- Start Microsoft Excel, and then create a new workbook.
- On the Tools menu, point to Macro, and then click Visual Basic Editor (or press ALT+F11).
- On the Insert menu, click Module.
On the module sheet, type the following code:
Option Explicit Type SYSTEM_INFO dwOemID As Long dwPageSize As Long lpMinimumApplicationAddress As Long lpMaximumApplicationAddress As Long dwActiveProcessorMask As Long dwNumberOrfProcessors As Long dwProcessorType As Long dwAllocationGranularity As Long dwReserved As Long End Type Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Type MEMORYSTATUS dwLength As Long dwMemoryLoad As Long dwTotalPhys As Long dwAvailPhys As Long dwTotalPageFile As Long dwAvailPageFile As Long dwTotalVirtual As Long dwAvailVirtual As Long End Type 'The following three Declare lines must be each entered on a single 'line. Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _ (LpVersionInformation As OSVERSIONINFO) As Long Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As _ MEMORYSTATUS) Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As _ SYSTEM_INFO) Public Const PROCESSOR_INTEL_386 = 386 Public Const PROCESSOR_INTEL_486 = 486 Public Const PROCESSOR_INTEL_PENTIUM = 586 Public Const PROCESSOR_MIPS_R4000 = 4000 Public Const PROCESSOR_ALPHA_21064 = 21064 Sub SystemInformation() Dim msg As String ' Status information. Dim NewLine As String ' New-line. Dim ret As Integer ' OS Information Dim ver_major As Integer ' OS Version Dim ver_minor As Integer ' Minor Os Version Dim Build As Long ' OS Build NewLine = Chr(13) + Chr(10) ' New-line. ' Get operating system and version. Dim verinfo As OSVERSIONINFO 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/98 " Case 2 msg = msg + "Windows NT/2000 " End Select ver_major = verinfo.dwMajorVersion ver_minor = verinfo.dwMinorVersion Build = verinfo.dwBuildNumber msg = msg & ver_major & "." & ver_minor msg = msg & " (Build " & Build & ")" & NewLine & NewLine ' Get CPU type and operating mode. Dim sysinfo As SYSTEM_INFO GetSystemInfo sysinfo msg = msg + "CPU: " Select Case sysinfo.dwProcessorType Case PROCESSOR_INTEL_386 msg = msg + "Intel 386" + NewLine Case PROCESSOR_INTEL_486 msg = msg + "Intel 486" + NewLine Case PROCESSOR_INTEL_PENTIUM msg = msg + "Intel Pentium" + NewLine Case PROCESSOR_MIPS_R4000 msg = msg + "MIPS R4000" + NewLine Case PROCESSOR_ALPHA_21064 msg = msg + "DEC Alpha 21064" + NewLine Case Else msg = msg + "(unknown)" + NewLine End Select msg = msg + NewLine ' Get free memory. Dim memsts As MEMORYSTATUS Dim memory As Long GlobalMemoryStatus memsts memory = memsts.dwTotalPhys msg = msg + "Total Physical Memory: " msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine memory = memsts.dwAvailPhys msg = msg + "Available Physical Memory: " msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine memory = memsts.dwTotalVirtual msg = msg + "Total Virtual Memory: " msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine memory = memsts.dwAvailVirtual msg = msg + "Available Virtual Memory: " msg = msg + Format(memory \ 1024, "###,###,###") + "K" + NewLine MsgBox msg, vbOKOnly, "System Info" End Sub
- On the Tools menu, point to Macro, and then click Macros.
- Click SystemInformation, and then click Run.
The macro returns a message box that shows your system information.
back to the top
REFERENCES
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
212536 OFF2000: How to Run Sample Code from Knowledge Base Articles
For additional information about how to use Windows APIs in Microsoft Visual Basic, click the article numbers below to view the articles in the Microsoft Knowledge Base:
161151 HOWTO: Get Windows Status Information via API Calls
189249 HOWTO: Determine Which 32-Bit Windows Version Is Being Used
Keywords: kbdtacode kbhowtomaster kbprogramming KB213267