dcsimg
Results 1 to 14 of 14

Thread: Determining OS and Processor Problem!

  1. #1

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Question Determining OS and Processor Problem!

    I made a small project which is a part of a bigger one, this project is a form of one button with two textboxes.

    This code works when user clicks on the button:

    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If System.Environment.Is64BitOperatingSystem = True Then
                TextBox1.Text = "64-bit Operating System"
            Else
                TextBox1.Text = "32-bit Operating System"
    
            End If
    
            If System.Environment.Is64BitProcess = True Then
                TextBox2.Text = "64-bit processor"
            Else
                TextBox2.Text = "32-bit processor"
            End If
        End Sub
    With that code I wanted to tell the user (or the bigger project) what operating system and type of processor he has on his PC?

    I tried the program on many devices and was fine until one day it showed me a x64 Operating System on a 32-bit Processor, and I know it's impossible.

    So I knew that there is a problem with determining the right Processor.

    I need to correct this code to determine and tell the exact OS and Processor type.

    Thank you

  2. #2
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,169

    Re: Determining OS and Processor Problem!

    System.Environment.Is64BitProcess isn't telling you if the processor is 32 or 64 bit just if the current Process is. Then again if they are running on anything made in the last 10 years or so it will probably be 64bit anyway as Intel haven't made 32bit desktop cpus for over ten years and I imagine AMD are the same.
    Last edited by PlausiblyDamp; Oct 6th, 2018 at 01:15 PM.

  3. #3

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Re: Determining OS and Processor Problem!

    Quote Originally Posted by PlausiblyDamp View Post
    System.Environment.Is64BitProcess isn't telling you if the processor is 32 or 64 bit just if the current Process is.
    Then what tells?



    Then again if they are running on anything made in the last 10 years or so it will probably be 64bit anyway as Intel haven't made 32bit desktop cpus for over ten years and I imagine AMD are the same.
    I know but I have targeted users with Xp too

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,329

    Re: Determining OS and Processor Problem!

    Environment.Is64BitOperatingSystem does exactly what you ask.

  5. #5
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,169

    Re: Determining OS and Processor Problem!

    Is there a reason you need to know the CPU architecture if you know the OS architecture?

    The easiest way I can think of might be to check the environment variable PROCESSOR_ARCHITECTURE using https://docs.microsoft.com/en-us/dot...ramework-4.7.2 and see what it says, on my laptop it reports AMD64 so it is a 64 bit architecture.

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,329

    Re: Determining OS and Processor Problem!

    Please everyone stop editing posts, its getting confusing replying. lol

  7. #7

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Re: Determining OS and Processor Problem!

    Quote Originally Posted by ident View Post
    Environment.Is64BitOperatingSystem does exactly what you ask.
    Then what Exactly I need??

  8. #8

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Re: Determining OS and Processor Problem!

    Quote Originally Posted by ident View Post
    Environment.Is64BitOperatingSystem does exactly what you ask.
    Then what Exactly I need??

  9. #9

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Re: Determining OS and Processor Problem!

    Quote Originally Posted by PlausiblyDamp View Post
    Is there a reason you need to know the CPU architecture if you know the OS architecture?

    The easiest way I can think of might be to check the environment variable PROCESSOR_ARCHITECTURE using https://docs.microsoft.com/en-us/dot...ramework-4.7.2 and see what it says, on my laptop it reports AMD64 so it is a 64 bit architecture.
    The reason is I want to determine what Active solution I should use with the user like If i should use:
    x86?
    x64?
    Any CPU (prefer 32 Checked)?
    Any CPU (prefer 32 Unchecked)?

    and then know what Microsoft.ACE.OLEDB.12.0' provider should be installed?

  10. #10
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,329

    Re: Determining OS and Processor Problem!

    The code posted is correct. Only thing I can thinkof was a VM in play but then still....

  11. #11
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    934

    Re: Determining OS and Processor Problem!

    Joye, you seem to be confusing a process with a processor. Process = program, Processor = CPU

    System.Environment.Is64BitProcess will return true if your program is a 64-bit program. If you run a 32-bit program under a 64-bit OS, System.Environment.Is64BitProcess will return False, because the program is a 32-bit program.

    Unless I'm missing something, the CPU type is not the relevant value for your needs.

    Suppose, for a moment, that a user had a 64-bit capable CPU but were running a 32-bit version of Windows. You are still limited to running 32-bit code in that case, since the OS is 32-bit.

    Now, suppose for a moment that a user had only a 32-bit capable CPU but were running a 64-bit version of Windows. Hmm...is that possible?

    So, the bit value of the OS should be all you care about.

    Quote Originally Posted by Joye View Post
    The reason is I want to determine what Active solution I should use with the user like If i should use:
    x86?
    x64?
    Any CPU (prefer 32 Checked)?
    Any CPU (prefer 32 Unchecked)?

    and then know what Microsoft.ACE.OLEDB.12.0' provider should be installed?
    And with your most recent post, I'm guessing all this back and forth wasn't necessary to begin with if the above is all you are wondering about...

  12. #12
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,169

    Re: Determining OS and Processor Problem!

    Quote Originally Posted by Joye View Post
    The reason is I want to determine what Active solution I should use with the user like If i should use:
    x86?
    x64?
    Any CPU (prefer 32 Checked)?
    Any CPU (prefer 32 Unchecked)?

    and then know what Microsoft.ACE.OLEDB.12.0' provider should be installed?
    Unless you really need to run as a 64 bit process then you could go for AnyCPU prefer 32 bit. That way you will run as a 32 bit process on a 32 bit OS or a 64 bit OS that has support for 32 bit code. The only time it will run as a 64 bit process is if you are running on a 64bit OS that doesn't support 32 bit code (which is pretty unusual for a desktop these days anyway).

    The actual CPU shouldn't really make a difference, in fact neither should the OS - just check the value of System.Environment.Is64BitProcess to discover if you are running as 32bit or 64bit and act accordingly.
    Last edited by PlausiblyDamp; Oct 9th, 2018 at 02:04 PM.

  13. #13

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Re: Determining OS and Processor Problem!

    Quote Originally Posted by OptionBase1 View Post
    Joye, you seem to be confusing a process with a processor. Process = program, Processor = CPU

    System.Environment.Is64BitProcess will return true if your program is a 64-bit program. If you run a 32-bit program under a 64-bit OS, System.Environment.Is64BitProcess will return False, because the program is a 32-bit program.

    Unless I'm missing something, the CPU type is not the relevant value for your needs.

    Suppose, for a moment, that a user had a 64-bit capable CPU but were running a 32-bit version of Windows. You are still limited to running 32-bit code in that case, since the OS is 32-bit.

    Now, suppose for a moment that a user had only a 32-bit capable CPU but were running a 64-bit version of Windows. Hmm...is that possible?

    So, the bit value of the OS should be all you care about.



    And with your most recent post, I'm guessing all this back and forth wasn't necessary to begin with if the above is all you are wondering about...
    So your suggestion is if (System.Environment.Is64BitProcess = true) I handle the user a x64 version of my program and if not I just handle him x86?

    Is it that easy??

    Because I was so confused about this decision.

  14. #14

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Re: Determining OS and Processor Problem!

    Quote Originally Posted by PlausiblyDamp View Post
    Unless you really need to run as a 64 bit process then you could go for AnyCPU prefer 32 bit. That way you will run as a 32 bit process on a 32 bit OS or a 64 bit OS that has support for 32 bit code. The only time it will run as a 64 bit process is if you are running on a 64bit OS that does support 32 bit code (which is pretty unusual for a desktop these days anyway).

    The actual CPU shouldn't really make a difference, in fact neither should the OS - just check the value of System.Environment.Is64BitProcess to discover if you are running as 32bit or 64bit and act accordingly.

    Such A Relieve
    I'm going to try that out on many devices
    Thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width