bool is64BitProcess =(IntPtr.Size==8);bool is64BitOperatingSystem = is64BitProcess ||InternalCheckIsWow64();[DllImport("kernel32.dll",SetLastError=true,CallingConvention=CallingConvention.Winapi)][return:MarshalAs(UnmanagedType.Bool)]privatestaticexternboolIsWow64Process([In]IntPtr hProcess,[Out]outbool wow64Process
);publicstaticboolInternalCheckIsWow64(){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)){returnfalse;}return retVal;}}else{returnfalse;}}
1
J'ai cette codé pour un de mes projets C# VS 2005).
//DLL Imports
using System.Runtime.InteropServices;///<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>publicstaticboolIs64BitOperatingSystem(){if(IntPtr.Size==8)//64-bit programs run only on Win64{returntrue;}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>staticboolDoesWin32MethodExist(string moduleName,string methodName){IntPtr moduleHandle =GetModuleHandle(moduleName);if(moduleHandle ==IntPtr.Zero){returnfalse;}return(GetProcAddress(moduleHandle, methodName)!=IntPtr.Zero);}[DllImport("kernel32.dll")]staticexternIntPtrGetCurrentProcess();[DllImport("kernel32.dll",CharSet=CharSet.Auto)]staticexternIntPtrGetModuleHandle(string moduleName);[DllImport("kernel32",CharSet=CharSet.Auto,SetLastError=true)]staticexternIntPtrGetProcAddress(IntPtr hModule,[MarshalAs(UnmanagedType.LPStr)]string procName);[DllImport("kernel32.dll",CharSet=CharSet.Auto,SetLastError=true)][return:MarshalAs(UnmanagedType.Bool)]staticexternboolIsWow64Process(IntPtr hProcess,outbool wow64Process);
1
publicstaticstring t2or64(){string t2s4;bool os =System.Environment.Is64BitOperatingSystem;int x =0;if(os ==true){
x =64;}else{
x =32;}
t2s4 =Convert.ToString(x);return t2s4;}
0
Vous pouvez vérifier à l'aide de IntPtr taille. IntPtr taille est de 4 pour les OS 32 bits et 8 pour la version 64 bits de l'OS
///<summary>Is64s the bit operating system.</summary>///<returns></returns>if(IntPtr.Size==8)//64Bitelse//32bit
Type: System.Int32
La taille d'un pointeur ou traiter dans ce processus, mesurée en octets. La valeur de cette propriété est 4 dans un processus 32 bitset 8 dans un processus 64 bits. Vous pouvez définir le type de processus par la mise en au /platform commutateur lorsque vous compilez votre code avec le C# et Visual Basic compilateurs.
Système.De l'environnement.Is64BitOperatingSystem
voir cette question.
Ici, il est:
Comment détecter Windows plate-forme 64 bits .NET?
Citation:
J'ai cette codé pour un de mes projets C# VS 2005).
Vous pouvez vérifier à l'aide de IntPtr taille. IntPtr taille est de 4 pour les OS 32 bits et 8 pour la version 64 bits de l'OS
Type: System.Int32
La taille d'un pointeur ou traiter dans ce processus, mesurée en octets. La valeur de cette propriété est 4 dans un processus 32 bitset 8 dans un processus 64 bits. Vous pouvez définir le type de processus par la mise en au
/platform
commutateur lorsque vous compilez votre code avec leC#
etVisual Basic
compilateurs.