次の方法で共有


Sample – Detecting installed Outlook and its bitness

Here is a sample which detects the installed Outlook versions and their bitness.

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;

using System.Runtime.InteropServices;

using Microsoft.Win32;

 

namespace DetectOutlook

{

class Program

{

public enum BinaryType : uint

{

SCS_32BIT_BINARY = 0, // A 32-bit Windows-based application

SCS_64BIT_BINARY = 6, // A 64-bit Windows-based application.

SCS_DOS_BINARY = 1, // An MS-DOS – based application

SCS_OS216_BINARY = 5, // A 16-bit OS/2-based application

SCS_PIF_BINARY = 3, // A PIF file that executes an MS-DOS – based application

SCS_POSIX_BINARY = 4, // A POSIX – based application

SCS_WOW_BINARY = 2 // A 16-bit Windows-based application

}

 

[DllImport("kernel32.dll")]

static extern bool GetBinaryType(string lpApplicationName, out BinaryType lpBinaryType);

 

 

static void Main(string[] args)

{

string sLine = string.Empty;

 

Console.WriteLine(sLine);

 

if (Environment.Is64BitOperatingSystem)

Console.WriteLine("OS Bitness is 64 bit");

else

Console.WriteLine("OS Bitness is 32 bit");

 

if (Environment.Is64BitProcess)

Console.WriteLine("This Application's process Bitness is 64 bit");

else

Console.WriteLine("This Application's process Bitness is 32 bit");

 

DetectbyFilePath();

 

string x;

x = "";

}

 

 

 

static void DetectbyFilePath()

{

 

List<string> filePaths = new List<string>();

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\root\Office16\outlook.exe"); // 64-bit OS, 32-bit Outlook (C2R)

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\Office16\outlook.exe"); // 64-bit OS, 32-bit Outlook (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\Office16\outlook.exe"); // OS == Outlook bitness (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\root\Office16\outlook.exe"); // OS == Outlook bitness (C2R)

 

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\root\Office15\outlook.exe"); // 64-bit OS, 32-bit Outlook (C2R)

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\Office15\outlook.exe"); // 64-bit OS, 32-bit Outlook (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\Office15\outlook.exe"); // OS == Outlook bitness (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\root\Office15\outlook.exe"); // OS == Outlook bitness (C2R)

 

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\root\Office14\outlook.exe"); // 64-bit OS, 32-bit Outlook (C2R)

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\Office14\outlook.exe"); // 64-bit OS, 32-bit Outlook (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\Office14\outlook.exe"); // OS == Outlook bitness (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\root\Office14\outlook.exe"); // OS == Outlook bitness (C2R)

 

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\root\Office12\outlook.exe"); // 64-bit OS, 32-bit Outlook (C2R)

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\Office12\outlook.exe"); // 64-bit OS, 32-bit Outlook (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\Office12\outlook.exe"); // OS == Outlook bitness (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\root\Office12\outlook.exe"); // OS == Outlook bitness (C2R)

 

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\root\Office11\outlook.exe"); // 64-bit OS, 32-bit Outlook (C2R)

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\Office11\outlook.exe"); // 64-bit OS, 32-bit Outlook (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\Office11\outlook.exe"); // OS == Outlook bitness (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\root\Office11\outlook.exe"); // OS == Outlook bitness (C2R)

 

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\root\Office10\outlook.exe"); // 64-bit OS, 32-bit Outlook (C2R)

filePaths.Add(@"C:\Program Files (x86)\Microsoft Office\Office10\outlook.exe"); // 64-bit OS, 32-bit Outlook (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\Office10\outlook.exe"); // OS == Outlook bitness (MSI)

filePaths.Add(@"C:\Program Files\Microsoft Office\root\Office10\outlook.exe"); // OS == Outlook bitness (C2R)

 

string sLine = string.Empty;

foreach (string sFile in filePaths)

{

if (File.Exists(sFile))

{

BinaryType type;

GetBinaryType(sFile, out type);

sLine = string.Format("Outlook Bitness: {0} File Path: {1}", type, sFile);

Console.WriteLine(sLine);

System.Diagnostics.Debug.WriteLine(sLine);

}

}

 

}

}

}