Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
612 views
in Technique[技术] by (71.8m points)

windows - Get path of "Program files" folder that contains 32-bit programs

How do I determine the full path of the folder that contains 32-bit programs using VBA? It's called "Program Files" on 32-bit Windows systems, but on 64-bit systems it's called "Program Files (x86)".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Environ will do the trick:

debug.print Environ("ProgramFiles") 
debug.print Environ("PROGRAMFILES(X86)")

'If you want to check if current PC is x64
debug.print Environ("PROCESSOR_IDENTIFIER")

List of environment variables can be found here.


UPDATE: Based on the conversation I've had with Christian and based on my comments, I looked into this a little more.

I have two machines I tested on:

  • Machine 1: Win 7 Ultimate, 64 Bit, Office 2010 64 Bit
  • Machine 2: Win 7 Ultimate, 32 Bit, Office 2007 32 Bit

I ran the following statements in the immediate window:

? Environ("ProgramFiles") 
? Environ("PROGRAMFILES(X86)")
? Environ("ProgramW6432")

Results

Machine 1:

C:Program Files 
C:Program Files (x86) 
C:Program Files

Machine 2:

C:Program Files
//Blank//
//Blank//

So, based on these limited findings, you may want to see the if ProgramW6432 has a value. If not, assume 32 bit and use ProgramFiles.

IF Environ("ProgramW6432") <> "" THEN
   'I'm 64 bit so check both ProgramW6432 and PROGRAMFILES(X86)
ELSE
   'I'm 32 bit so check ProgramFiles
END IF

Conversely, you could use PROCESSOR_IDENTIFIER to determine x64 vs. x86 and do the same thing.

I wouldn't say either way is foolproof but should get you on the right track.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...