Access VBA: Is there any way to get computer specs

2019-05-26 16:47发布

问题:

I'm creating a form in Access that processes millions of lines of data, and takes several hours (depending on your computer). I want to implement a feature that will read the computer specs, such as CPU speed and amount of RAM, and determine how long the process will take.

Is it possible to get the computer specs using VBA?

回答1:

1) There is this "environ" function that can give you informations on the "computer" environment. It is usually used to get things such as user name or temp folder, but it is said to return the following values:

environ(x): value returned
1 : ALLUSERSPROFILE
2 : APPDATA
3 : CLIENTNAME
4 : CommonProgramFiles
5 : COMPUTERNAME
6 : ComSpec
7 : HOMEDRIVE
8 : HOMEPATH
9 : LOGONSERVER
10 : NUMBER_OF_PROCESSORS
11 : OS
12 : Path
13 : PATHEXT
14 : PROCESSOR_ARCHITECTURE
15 : PROCESSOR_IDENTIFIER
16 : PROCESSOR_LEVEL
17 : PROCESSOR_REVISION
18 : ProgramFiles
19 : SESSIONNAME
20 : SystemDrive
21 : SystemRoot
22 : TEMP
23 : TMP
24 : USERDOMAIN
25 : USERNAME
26 : USERPROFILE
27 : windir 

2) you have some shell functions that can be used to launch external programs and get a value back. In addition to the standard VBA shell function, you also have some interesting things such as this "shell and wait" function.

3) Of course, you can always declare functions from the windows API in your VBA code and use them to get needed values ...



回答2:

You should be able to retrieve System Information by calling WMI Service Object.

WMI Tasks: Computer Hardware

WMI Accounts and Computer Information

Using the Power of VBScripts and WMI in Microsoft Access VBA