Comment détecter la plate-forme Windows 64 bits with.NET Je ne sais pas.

Dans un .NET 2.0 application en C# j'utilise le code suivant pour détecter le système d'exploitation de la plateforme:

string os_platform = System.Environment.OSVersion.Platform.ToString();

retourne "Win32NT". Le problème est qu'il retourne "Win32NT" même lorsqu'il tourne sur Windows Vista 64-bit.

Existe-t-il une autre méthode pour connaître la bonne plateforme (32 ou 64 bits)?

notez qu'il devrait également détecter 64 bits lorsqu'il est exécuté comme une application 32 bits sur Windows 64 bits.

245
demandé sur John Demetriou 2008-12-03 12:32:38

29 réponses

IntPtr.La taille ne retournera pas la valeur correcte Si vous utilisez 32-bit.Net Framework 2.0 sur les fenêtres 64-bit (il retournera 32-bit).

comme le décrit Raymond Chen de Microsoft, vous devez d'abord vérifier si vous utilisez un processus 64 bits (je pense que dans .NET vous pouvez le faire en vérifiant IntPtr.Si vous utilisez un processus 32 bits, vous devez quand même appeler la fonction API Win IsWow64Process. Si cela retourne true, vous êtes en cours d'exécution dans un processus de 32 bits sur 64 bits Windows.

Raymond Chen de Microsoft: comment détecter programmatiquement si vous utilisez des fenêtres 64 bits

ma solution:

static bool is64BitProcess = (IntPtr.Size == 8);
static bool is64BitOperatingSystem = is64BitProcess || InternalCheckIsWow64();

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWow64Process(
    [In] IntPtr hProcess,
    [Out] out bool wow64Process
);

public static bool InternalCheckIsWow64()
{
    if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) ||
        Environment.OSVersion.Version.Major >= 6)
    {
        using (Process p = Process.GetCurrentProcess())
        {
            bool retVal;
            if (!IsWow64Process(p.Handle, out retVal))
            {
                return false;
            }
            return retVal;
        }
    }
    else
    {
        return false;
    }
}
190
répondu Stefan Schultze 2014-05-14 10:01:18

.NET 4 a deux nouvelles propriétés dans la classe D'environnement, Is64BitProcess et Is64BitOperatingSystem . Fait intéressant, si vous utilisez Reflector, vous pouvez voir qu'ils sont mis en œuvre différemment dans les versions 32-bit et 64-bit de mscorlib. La version 32 bits renvoie false pour Is64BitProcess et appelle IsWow64Process via P / Invoke pour Is64BitOperatingSystem. La version 64 bits ne renvoie que true pour les deux.

223
répondu Phil Devaney 2009-12-16 10:58:54

si vous utilisez .net Framework 4.0, c'est facile:

Environment.Is64BitOperatingSystem

Voir Environnement.Is64BitOperatingSystem Property (MSDN).

85
répondu Peter Vaughan-Williams 2013-03-21 19:57:58

il s'agit juste d'une implémentation de ce qui est suggéré ci-dessus par Bruno Lopez, mais fonctionne sur Win2k + tous les packs de service WinXP. J'ai pensé le poster pour que les autres n'aient pas à le rouler à la main. (aurait posté un commentaire, mais je suis un nouvel utilisateur!)

[DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public extern static IntPtr LoadLibrary(string libraryName);

[DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public extern static IntPtr GetProcAddress(IntPtr hwnd, string procedureName);

private delegate bool IsWow64ProcessDelegate([In] IntPtr handle, [Out] out bool isWow64Process);

public static bool IsOS64Bit()
{
    if (IntPtr.Size == 8 || (IntPtr.Size == 4 && Is32BitProcessOn64BitProcessor()))
    {
        return true;
    }
    else
    {
        return false;
    }
}

private static IsWow64ProcessDelegate GetIsWow64ProcessDelegate()
{
  IntPtr handle = LoadLibrary("kernel32");

  if ( handle != IntPtr.Zero)
  {
    IntPtr fnPtr = GetProcAddress(handle, "IsWow64Process");

    if (fnPtr != IntPtr.Zero)
    {
      return (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)fnPtr, typeof(IsWow64ProcessDelegate));
    }
  }

  return null;
}

private static bool Is32BitProcessOn64BitProcessor()
{
  IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate();

  if (fnDelegate == null)
  {
    return false;
  }

  bool isWow64;
  bool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64);

  if (retVal == false)
  {
    return false;
  }

  return isWow64;
}
50
répondu dwhiteho 2009-12-03 14:44:37

la réponse complète est la suivante (tirée de la réponse de stefan-mg, ripper234 et BobbyShaftoe):

    [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);

    private bool Is64Bit()
    {
        if (IntPtr.Size == 8 || (IntPtr.Size == 4 && Is32BitProcessOn64BitProcessor()))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    private bool Is32BitProcessOn64BitProcessor()
    {
        bool retVal;

        IsWow64Process(Process.GetCurrentProcess().Handle, out retVal);

        return retVal;
    } 

Vérifiez D'abord si vous êtes dans un processus 64 bits. Si vous ne l'êtes pas, vérifiez si le processus 32 bits est un processus WOW64.

48
répondu Bruno Lopes 2009-03-25 13:18:17

Microsoft a mis un échantillon de code pour cela:

http://1code.codeplex.com/SourceControl/changeset/view/39074#842775

il ressemble à ceci:

    /// <summary>
    /// The function determines whether the current operating system is a 
    /// 64-bit operating system.
    /// </summary>
    /// <returns>
    /// The function returns true if the operating system is 64-bit; 
    /// otherwise, it returns false.
    /// </returns>
    public static bool Is64BitOperatingSystem()
    {
        if (IntPtr.Size == 8)  // 64-bit programs run only on Win64
        {
            return true;
        }
        else  // 32-bit programs run on both 32-bit and 64-bit Windows
        {
            // Detect whether the current process is a 32-bit process 
            // running on a 64-bit system.
            bool flag;
            return ((DoesWin32MethodExist("kernel32.dll", "IsWow64Process") &&
                IsWow64Process(GetCurrentProcess(), out flag)) && flag);
        }
    }

    /// <summary>
    /// The function determins whether a method exists in the export 
    /// table of a certain module.
    /// </summary>
    /// <param name="moduleName">The name of the module</param>
    /// <param name="methodName">The name of the method</param>
    /// <returns>
    /// The function returns true if the method specified by methodName 
    /// exists in the export table of the module specified by moduleName.
    /// </returns>
    static bool DoesWin32MethodExist(string moduleName, string methodName)
    {
        IntPtr moduleHandle = GetModuleHandle(moduleName);
        if (moduleHandle == IntPtr.Zero)
        {
            return false;
        }
        return (GetProcAddress(moduleHandle, methodName) != IntPtr.Zero);
    }

    [DllImport("kernel32.dll")]
    static extern IntPtr GetCurrentProcess();

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr GetModuleHandle(string moduleName);

    [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
    static extern IntPtr GetProcAddress(IntPtr hModule,
        [MarshalAs(UnmanagedType.LPStr)]string procName);

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);

il existe également une version WMI (pour tester les machines distantes).

41
répondu synhershko 2010-08-15 20:39:43

vous pouvez également vérifier la variable d'environnement PROCESSOR_ARCHITECTURE .

il n'existe pas ou est défini à" x86 " sous Windows 32 bits.

private int GetOSArchitecture()
{
    string pa = 
        Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
    return ((String.IsNullOrEmpty(pa) || 
             String.Compare(pa, 0, "x86", 0, 3, true) == 0) ? 32 : 64);
}
16
répondu Andrew Ensley 2009-06-24 19:38:07

du blog Chriz Yuen

C# .Net 4.0 a Introduit deux nouveaux propriété d'environnement Environnement.Is64BitOperatingSystem; Environnement.Is64BitProcess;

soyez prudent lorsque vous utilisez ces deux propriétés. Test sur Windows 7 64bits Machine

//Workspace: Target Platform x86
Environment.Is64BitOperatingSystem True
Environment.Is64BitProcess False

//Workspace: Target Platform x64
Environment.Is64BitOperatingSystem True
Environment.Is64BitProcess True

//Workspace: Target Platform Any
Environment.Is64BitOperatingSystem True
Environment.Is64BitProcess True
12
répondu electricalbah 2014-06-03 02:37:07

essayez ceci:

Environment.Is64BitOperatingSystem

Environment.Is64BitProcess
10
répondu user2235582 2013-07-16 02:47:19

@foobar: Vous avez raison, c'est trop facile ;)

dans 99% des cas, les développeurs avec des fonds d'administrateur système faibles ne parviennent finalement pas à se rendre compte de la puissance Microsoft a toujours prévu pour quiconque d'énumérer Windows.

les administrateurs de système écriront toujours un code meilleur et plus simple quand il s'agit d'un tel point.

néanmoins, une chose à noter, la configuration de construction doit être AnyCPU pour cette variable d'environnement pour retourner les valeurs correctes sur les bons systèmes:

System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")

renvoie" X86 "sous Windows 32 bits, et" AMD64 " sous Windows 64 bits.

9
répondu SomeSysadmin 2013-07-16 02:46:49

chemin le plus rapide:

if(IntPtr.Size == 8) {
    // 64 bit machine
} else if(IntPtr.Size == 4)  {
    // 32 bit machine
} 

Note: c'est très direct.

8
répondu BobbyShaftoe 2017-02-04 15:44:59

utilisez ces deux variables d'environnement (pseudo-code):

if (PROCESSOR_ARCHITECTURE = x86 &&
    isDefined(PROCESSOR_ARCHITEW6432) &&
    PROCESSOR_ARCHITEW6432 = AMD64) {

    //64 bit OS
}
else
    if (PROCESSOR_ARCHITECTURE = AMD64) {
        //64 bit OS
    }
    else
        if (PROCESSOR_ARCHITECTURE = x86) {
            //32 bit OS
        }

se Reporter à l'article du blog HOWTO: Processus de détection du nombre de bits .

6
répondu Santhosh 2013-03-21 19:29:40

L'utilisation de dotPeek aide à voir comment le cadre le fait effectivement. Avec cela à l'esprit, voici ce que j'ai trouvé:

public static class EnvironmentHelper
{
    [DllImport("kernel32.dll")]
    static extern IntPtr GetCurrentProcess();

    [DllImport("kernel32.dll")]
    static extern IntPtr GetModuleHandle(string moduleName);

    [DllImport("kernel32")]
    static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

    [DllImport("kernel32.dll")]
    static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);

    public static bool Is64BitOperatingSystem()
    {
        // Check if this process is natively an x64 process. If it is, it will only run on x64 environments, thus, the environment must be x64.
        if (IntPtr.Size == 8)
            return true;
        // Check if this process is an x86 process running on an x64 environment.
        IntPtr moduleHandle = GetModuleHandle("kernel32");
        if (moduleHandle != IntPtr.Zero)
        {
            IntPtr processAddress = GetProcAddress(moduleHandle, "IsWow64Process");
            if (processAddress != IntPtr.Zero)
            {
                bool result;
                if (IsWow64Process(GetCurrentProcess(), out result) && result)
                    return true;
            }
        }
        // The environment must be an x86 environment.
        return false;
    }
}

exemple d'usage:

EnvironmentHelper.Is64BitOperatingSystem();
6
répondu Alexandru 2015-03-04 22:27:06

j'ai besoin de faire cela, mais j'ai aussi besoin d'être capable en tant qu'administrateur de le faire à distance, dans tous les cas cela semble fonctionner assez bien pour moi:

    public static bool is64bit(String host)
    {
        using (var reg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, host))
        using (var key = reg.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\"))
        {
            return key.GetValue("ProgramFilesDir (x86)") !=null;
        }
    }
4
répondu Julian Hall 2011-09-29 21:26:01

il s'agit d'une solution basée sur le code de Microsoft à http://1code.codeplex.com/SourceControl/changeset/view/39074#842775 . Il utilise des méthodes d'extension pour une réutilisation facile du code.

certaines utilisations possibles sont indiquées ci-dessous:

bool bIs64BitOS = System.Environment.OSVersion.IsWin64BitOS();

bool bIs64BitProc = System.Diagnostics.Process.GetCurrentProcess().Is64BitProc();

//Hosts the extension methods  
public static class OSHelperTools  
{  
    /// <summary>     
    /// The function determines whether the current operating system is a      
    /// 64-bit operating system.     
    /// </summary>     
    /// <returns>     
    /// The function returns true if the operating system is 64-bit;      
    /// otherwise, it returns false.     
    /// </returns>    
    public static bool IsWin64BitOS(this OperatingSystem os)  
    {  
        if (IntPtr.Size == 8)  
        // 64-bit programs run only on Win64           
            return true;   
        else// 32-bit programs run on both 32-bit and 64-bit Windows     
        {   // Detect whether the current process is a 32-bit process                
            // running on a 64-bit system.               
            return Process.GetCurrentProcess().Is64BitProc();  
        }  
    }  

    /// <summary>  
    /// Checks if the process is 64 bit  
    /// </summary>  
    /// <param name="os"></param>  
    /// <returns>  
    /// The function returns true if the process is 64-bit;        
    /// otherwise, it returns false.  
    /// </returns>    
    public static bool Is64BitProc(this System.Diagnostics.Process p)  
    {  
        // 32-bit programs run on both 32-bit and 64-bit Windows           
        // Detect whether the current process is a 32-bit process                
        // running on a 64-bit system.               
        bool result;  
        return ((DoesWin32MethodExist("kernel32.dll", "IsWow64Process") && IsWow64Process(p.Handle, out result)) && result);  
    }  

    /// <summary>     
    /// The function determins whether a method exists in the export      
    /// table of a certain module.     
    /// </summary>     
    /// <param name="moduleName">The name of the module</param>     
    /// <param name="methodName">The name of the method</param>     
    /// <returns>     
    /// The function returns true if the method specified by methodName      
    /// exists in the export table of the module specified by moduleName.     
    /// </returns>       
    static bool DoesWin32MethodExist(string moduleName, string methodName)  
    {  
        IntPtr moduleHandle = GetModuleHandle(moduleName);  
        if (moduleHandle == IntPtr.Zero)  
            return false;    
        return (GetProcAddress(moduleHandle, methodName) != IntPtr.Zero);   
    }  
    [DllImport("kernel32.dll")]  
    static extern IntPtr GetCurrentProcess();  

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]  
    static extern IntPtr GetModuleHandle(string moduleName);  

    [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]  
    static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)]string procName);  

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]  
    [return: MarshalAs(UnmanagedType.Bool)]  
    static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);  
}
4
répondu dmihailescu 2013-03-21 19:36:55

Voici l'approche directe en C# en utilisant DllImport de cette page .

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] 
[return: MarshalAs(UnmanagedType.Bool)] 
public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo); 

public static bool Is64Bit() 
{ 
    bool retVal; 

    IsWow64Process(Process.GetCurrentProcess().Handle, out retVal); 

    return retVal; 
} 
3
répondu ripper234 2009-01-15 15:05:06

j'utilise le code suivant. Note: il est fait pour un projet AnyCPU.

    public static bool Is32bitProcess(Process proc) {
        if (!IsThis64bitProcess()) return true; // We're in 32-bit mode, so all are 32-bit.

        foreach (ProcessModule module in proc.Modules) {
            try {
                string fname = Path.GetFileName(module.FileName).ToLowerInvariant();
                if (fname.Contains("wow64")) {
                    return true;
                }
            } catch {
                // What on earth is going on here?
            }
        }
        return false;
    }

    public static bool Is64bitProcess(Process proc) {
        return !Is32bitProcess(proc);
    }

    public static bool IsThis64bitProcess() {
        return (IntPtr.Size == 8);
    }
3
répondu blez 2013-03-21 19:41:06

j'ai utilisé ce contrôle avec succès sur de nombreux systèmes d'exploitation:

private bool Is64BitSystem
{
   get
   {
      return Directory.Exists(Environment.ExpandEnvironmentVariables(@"%windir%\SysWOW64"));
   }
}

ce dossier est toujours appelé" SysWOW64", quelle que soit la langue du système d'exploitation. Cela fonctionne pour .net Framework 1.1 ou supérieur.

3
répondu Alexandru Dicu 2016-11-29 10:39:52

j'ai trouvé que c'était la meilleure façon de vérifier la plate-forme du système et le processus:

bool 64BitSystem = Environment.Is64BitOperatingSystem;
bool 64BitProcess = Environment.Is64BitProcess;

la première propriété retourne true pour le système 64 bits, et false pour le système 32 bits. La seconde propriété renvoie true pour le processus 64 bits, et false pour le processus 32 bits.

la nécessité de ces deux propriétés est parce que vous pouvez exécuter des processus 32 bits sur le système 64 bits, donc vous aurez besoin de vérifier à la fois le système et le processus.

2
répondu OmarElsherif 2012-10-06 10:41:32

très bien, mais cela devrait aussi fonctionner de env :

PROCESSOR_ARCHITECTURE=x86

..

PROCESSOR_ARCHITECTURE=AMD64

trop facile, peut-être; -)

2
répondu Peter Mortensen 2013-03-21 19:26:56

Voici une Windows Management Instrumentation (WMI) approche:

string _osVersion = "";
string _osServicePack = "";
string _osArchitecture = "";

ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
ManagementObjectCollection collection = searcher.Get();

foreach (ManagementObject mbo in collection)
{
    _osVersion = mbo.GetPropertyValue("Caption").ToString();
    _osServicePack = string.Format("{0}.{1}", mbo.GetPropertyValue("ServicePackMajorVersion").ToString(), mbo.GetPropertyValue("ServicePackMinorVersion").ToString());

    try
    {
        _osArchitecture = mbo.GetPropertyValue("OSArchitecture").ToString();
    }
    catch
    {
        // OSArchitecture only supported on Windows 7/Windows Server 2008
    }
}

Console.WriteLine("osVersion     : " + _osVersion);
Console.WriteLine("osServicePack : " + _osServicePack);
Console.WriteLine("osArchitecture: " + _osArchitecture);

/////////////////////////////////////////
// Test on Windows 7 64-bit
//
// osVersion     : Microsoft Windows 7 Professional
// osservicePack : 1.0
// osArchitecture: 64-bit

/////////////////////////////////////////
// Test on Windows Server 2008 64-bit
//    --The extra r's come from the registered trademark
//
// osVersion     : Microsoftr Windows Serverr 2008 Standard
// osServicePack : 1.0
// osArchitecture: 64-bit

/////////////////////////////////////////
// Test on Windows Server 2003 32-bit
//    --OSArchitecture property not supported on W2K3
//
// osVersion     : Microsoft(R) Windows(R) Server 2003, Standard Edition
// osServicePack : 2.0
// osArchitecture:
2
répondu user1054695 2013-03-21 19:44:06

OSInfo.Bits

using System;
namespace CSharp411
{
    class Program
    {
        static void Main( string[] args )
        {
           Console.WriteLine( "Operation System Information" );
           Console.WriteLine( "----------------------------" );
           Console.WriteLine( "Name = {0}", OSInfo.Name );
           Console.WriteLine( "Edition = {0}", OSInfo.Edition );
           Console.WriteLine( "Service Pack = {0}", OSInfo.ServicePack );
           Console.WriteLine( "Version = {0}", OSInfo.VersionString );
           Console.WriteLine( "Bits = {0}", OSInfo.Bits );
           Console.ReadLine();
        }
    }
}
1
répondu Greg 2010-05-09 04:44:38

inclure le code suivant dans une classe de votre projet:

    [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool wow64Process);

    public static int GetBit()
    {
        int MethodResult = "";
        try
        {
            int Architecture = 32;

            if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) || Environment.OSVersion.Version.Major >= 6)
            {
                using (Process p = Process.GetCurrentProcess())
                {
                    bool Is64Bit;

                    if (IsWow64Process(p.Handle, out Is64Bit))
                    {
                        if (Is64Bit)
                        {
                            Architecture = 64;

                        }

                    }

                }

            }

            MethodResult = Architecture;

        }
        catch //(Exception ex)
        {
            //ex.HandleException();
        }
        return MethodResult;
    }

utilisez - le comme ceci:

string Architecture = "This is a " + GetBit() + "bit machine";
1
répondu Knickerless-Noggins 2016-03-27 23:30:58

utilisez ceci pour obtenir l'architecture Windows installée:

string getOSArchitecture()
{
    string architectureStr;
    if (Directory.Exists(Environment.GetFolderPath(
                           Environment.SpecialFolder.ProgramFilesX86))) {
        architectureStr ="64-bit";
    }
    else {
        architectureStr = "32-bit";
    }
    return architectureStr;
}
0
répondu user885959 2013-03-21 19:56:33

étant donné que la réponse acceptée est très complexe. Il y a des moyens plus simples. Le mien est une variante de l'anaswer d'alexandrudicu. Étant donné que windows 64-bit installer des applications 32-bit dans les fichiers de programme (x86), Vous pouvez vérifier si ce dossier existe, en utilisant des variables d'environnement (pour compenser différentes localisations)

p.ex.

private bool Is64BitSystem
{
   get
   {
      return Directory.Exists(Environment.ExpandEnvironmentVariables(@"%PROGRAMFILES(X86)%"));
   }
}

pour moi, c'est plus rapide et plus simple. Étant donné que je souhaite également accéder à un chemin spécifique sous ce dossier basé sur la version de l'OS.

0
répondu John Demetriou 2017-11-03 08:35:09

vient de voir si l' "C:\Program Files (x86)" existe. Si non, alors vous êtes sur un OS 32 bits. Si c'est le cas, alors l'OS est 64 bits (Windows Vista ou Windows 7). Il semble assez simple...

-2
répondu John 2013-03-21 19:33:38

Profiter ;-)

Function Is64Bit() As Boolean

    Return My.Computer.FileSystem.SpecialDirectories.ProgramFiles.Contains("Program Files (x86)")

End Function
-2
répondu Majid95 2013-11-27 17:47:04

j'utilise:

Dim drivelet As String = Application.StartupPath.ToString
If Directory.Exists(drivelet(0) & ":\Program Files (x86)") Then
    MsgBox("64bit")
Else
    MsgBox("32bit")
End if

cela obtient le chemin où votre application est lancée au cas où vous l'avez installé à différents endroits sur l'ordinateur. En outre, vous pouvez simplement faire le chemin général C:\ puisque 99,9% des ordinateurs là-bas ont Windows installé dans C:\ .

-3
répondu Ben G 2013-03-21 19:38:52

j'utilise une version du suivant:

    public static bool Is64BitSystem()
    {
        if (Directory.Exists(Environment.GetEnvironmentVariable("Program Files (x86)"))) return true;
        else return false;
    }
-7
répondu Josh 2011-07-25 16:32:13