Solved

Looking for a program to detect office 64bit

Posted on 2015-02-03
7
92 Views
Last Modified: 2016-02-10
I use VBA to detect if 'Office 64 bit' is installed by using the code in the below link.
But I need this in an executable file so I can give it to users to run on their system.

I have an old copy of VB express that I use on occasion to create exe files to do simple things like this, but having issues. But VB Express is really old and would rather have it in something like vb.net.

Anyone have anything like this. Or can someone create it for me?

Here is the VBA code I use and it works without any issues.
http://officeone.mvps.org/vba/bitness.html

Thanks,

John
0
Comment
Question by:askolits
  • 4
  • 3
7 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 40586172
Use this code to adjust to what you need (c# code):

private void button1_Click(object sender, EventArgs e)
{
	openFileDialog1.ShowDialog();
	Stream fs = openFileDialog1.OpenFile();

	BinaryReader br = new BinaryReader(fs);

	UInt16 mz = br.ReadUInt16();
	if (mz == 0x5a4d) // check if it's a valid image ("MZ")
	{
		fs.Position = 60; // this location contains the offset for the PE header
		UInt32 peoffset = br.ReadUInt32();

		fs.Position = peoffset + 4; // contains the architecture
		UInt16 machine = br.ReadUInt16();

		if (machine == 0x8664) // IMAGE_FILE_MACHINE_AMD64
			textBox1.Text = "AMD64";
		else if (machine == 0x014c) // IMAGE_FILE_MACHINE_I386
			textBox1.Text = "i386";
		else if (machine == 0x0200) // IMAGE_FILE_MACHINE_IA64
			textBox1.Text = "IA64";
		else
			textBox1.Text = "Unknown";
	}
	else
		textBox1.Text = "Invalid image";

	br.Close();
}

Open in new window


Probably use a scan function to find the office files too (only word or excel should be sufficient).

If you already know the systems are all 64 bits, you could easily check if the office files are in the folder "Program Files" or in "Program Files (x86)". The latter is of course 32 bits.
0
 

Author Comment

by:askolits
ID: 40586202
I am going to assume that I can just plug this into my VB Express program and it would work?
Well, even though I would consider myself a very experienced VBA programmer, when it comes to VB,? Uhmmm... not so good.
I know it's very similar and have been able to hack out some code now and then, but I'll need a bit more help here.

For example, to use OpenDialog1, do I need a particular library reference added?
Also. not really familiar with the curly bracket "{ }" symbols. I put that in VB and it has no idea what that is.
Also, the event function created when I add a button is:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

which doesn't resemble your code.
0
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40586322
As I mentioned, it was C# code. Here it is again in VB:

Imports System.IO
Imports System.Globalization

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim fs As Stream
        OpenFileDialog1.ShowDialog()
        fs = New FileStream(OpenFileDialog1.FileName.ToString, FileMode.Open, FileAccess.Read)
        Dim br As New BinaryReader(fs)
        Dim mz As UInt16 = br.ReadUInt16()
        If mz = 23117 Then

            fs.Position = 60 '// this location contains the offset for the PE header
            Dim peoffset As UInt32 = br.ReadUInt32()
            fs.Position = peoffset + 4 '// contains the architecture
            Dim machine As UInt16 = br.ReadUInt16()

            If (machine = 34404) Then ' // IMAGE_FILE_MACHINE_AMD64
                TextBox1.Text = "AMD64"
            ElseIf (machine = 332) Then
                TextBox1.Text = "i386"
            ElseIf (machine = 512) Then
                TextBox1.Text = "IA64"
            Else
                TextBox1.Text = "Unknown"
            End If

        Else
            TextBox1.Text = "Invalid image"
        End If
        fs.Close()
        br.Close()

    End Sub
End Class

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:askolits
ID: 40586633
OK.

I got it to work. Although it seems odd that the responses in your code are , AMD64, i386 and IA64?
Does that mean the program is using those types of processing architectures? Or something like that?
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 40586680
Basically, AMD64 is ALWAYS 64 bits.
i386 is ALWAYS 32 bits.
IA64 you probably won't see around (unless you delve into special server software), it's written for the Intel Itanium CPU.
Just rename the string to whatever you want, just 32 or 64 bits is accurate enough.
0
 

Author Comment

by:askolits
ID: 40586699
Well, it works for me.
Thanks for your help and quick responses.
0
 

Author Closing Comment

by:askolits
ID: 40586701
Thanks!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

772 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