Título: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: raul338 en 7 Octubre 2010, 19:01 pm
Buenas :D Tengo una aplicacion que se cuando se inicia se lanza el servidor mysql, el problema es que hay un servidor para cada tipo de SO (32 y 64 bits) entonces.... buscando (luego de intentos fallidos a mano) logre dar con esta funcion :) En un modulo (o en un form como quieran :xD) Option Explicit ' Extracto ' http://www.vbmonster.com/Uwe/Forum.aspx/vb-winapi/5690/API-to-determine-if-OS-is-32bit-or-64-bit Private Declare Function GetVersion Lib "kernel32" () As Long Private Declare Sub GetNativeSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO) Private Type SYSTEM_INFO wProcessorArchitecture As Integer wReserved As Integer dwPageSize As Long lpMinimumApplicationAddress As Long lpMaximumApplicationAddress As Long dwActiveProcessorMask As Long dwNumberOfProcessors As Long dwProcessorType As Long dwAllocationGranularity As Long wProcessorLevel As Integer wProcessorRevision As Integer End Type Private Const PROCESSOR_ARCHITECTURE_IA64 = 6 Private Const PROCESSOR_ARCHITECTURE_AMD64 = 9 Public Function IsOS64Bit() As Boolean ' Llamar desde Win2k en adelante ' La verdad dudo de la existencia de Win2k 64 bits... ' pero en el msdn decia que a partir de win2k se puede llamar a la funcion xD If LoByte(LoWord(GetVersion())) >= 5 Then Dim si As SYSTEM_INFO Call GetNativeSystemInfo(si) IsOS64Bit = _ (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) Or _ (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64) End If End Function Private Function LoWord(ByVal Numero As Long) As Long ' Devuelve el LoWord del número pasado como parámetro LoWord = Numero And &HFFFF& End Function Private Function LoByte(ByVal Numero As Integer) As Integer ' Devuelve el LoByte del número pasado como parámetro LoByte = Numero And &HFF End Function
Y para probarlo en el form load Private Sub Form_Load() If IsOS64Bit Then MsgBox "Tienes un SO de 64 bits" Else MsgBox "Tienes un SO de 32 bits" End If End Sub
No me habia dado cuenta que 0 representaba un procesador de 32bit.... y yo decia que no me devolvia nada :xD Alguien que tenga un so de 64 bits que lo pruebe por favor :) Saludos! ::) Mi mensaje 888 ._.
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: ssccaann43 © en 7 Octubre 2010, 22:27 pm
Creeme que estuve mucho tiempo preguntandome esto...! Gracias
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: Dessa en 7 Octubre 2010, 22:42 pm
No me habia dado cuenta que 0 representaba un procesador de 32bit.... y yo decia que no me devolvia nada :xD
Si, cero para 32 Bits y cuando el retorno de "si.wProcessorArchitecture" es (-1) el procesador es "Unknown architecture" Alguien que tenga un S.O de 64 bits que lo pruebe por favor :)
+1
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: Karcrack en 7 Octubre 2010, 23:13 pm
'KERNEL32 Private Declare Function IsWow64Process Lib "KERNEL32" (ByVal hProcess As Long, ByRef Wow64Process As Boolean) As Long Private Const CurrentProcess As Long = -1 Public Function Is64() As Boolean On Error Resume Next Call IsWow64Process(CurrentProcess, Is64) End Function
Esto deberia funcionar...
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: raul338 en 7 Octubre 2010, 23:58 pm
Wow.... Karcrack dicen los rumores (lei por ahi) que si pones en modo compatibilidad se puede "saltar" eso :xD pero creo que ahi lo evitas con current Process
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: Karcrack en 8 Octubre 2010, 16:01 pm
Dejo una version mas molona :xD Private Type SYSTEM_PROCESSOR_INFORMATION ProcessorArchitecture As Integer ProcessorLevel As Integer ProcessorRevision As Integer Unknown As Integer FeatureBits As Long End Type Private Const SystemProcessorInformation As Long = 1 'NTDLL Private Declare Function NtQuerySystemInformation Lib "NTDLL" (ByVal SystemInformationClass As Long, ByRef SystemInformation As Any, ByVal SystemInformationLength As Long, ByRef ReturnLength As Long) As Long Public Function x64() As Boolean Dim tSPI As SYSTEM_PROCESSOR_INFORMATION If NtQuerySystemInformation(SystemProcessorInformation, tSPI, &HC, ByVal 0&) >= 0 Then x64 = ((tSPI.ProcessorArchitecture = 6) Or (tSPI.ProcessorArchitecture = 9)) End If End Function
Reducido: 'NTDLL Private Declare Function NtQuerySystemInformation Lib "NTDLL" (ByVal SystemInformationClass As Long, ByRef SystemInformation As Any, ByVal SystemInformationLength As Long, ByRef ReturnLength As Long) As Long
Public Function x64() As Boolean Dim wProcArch As Integer If NtQuerySystemInformation(1, wProcArch, &HC, ByVal 0&) >= 0 Then x64 = ((wProcArch = 6) Or (wProcArch = 9)) End If End Function
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: raul338 en 8 Octubre 2010, 16:11 pm
[OFFTOPIC] Porque siempre que posteo algo siempre encuentran una forma de optimizarlo? :rolleyes:
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: Karcrack en 8 Octubre 2010, 16:42 pm
Todo se puede mejorar :)
Por cierto, el codigo de Wow permite saber si estamos en un SO de 64 bits, en cambio el resto simplemente miran si el procesador lo es... es decir, yo puedo tener instalado un W$ de 32bits con un procesador de 64bits...
Título: Re: [SNIPPET] IsOS64bit - Saber si un sistema es de 64 bit
Publicado por: raul338 en 8 Octubre 2010, 18:56 pm
Por cierto, el codigo de Wow permite saber si estamos en un SO de 64 bits, en cambio el resto simplemente miran si el procesador lo es... es decir, yo puedo tener instalado un W$ de 32bits con un procesador de 64bits...
Igual me sirve, ya que necesito lanzar cosas de 32 o 64 bits segun sea el caso :xD
|