jason88
jason88

Reputation: 109

C# Check if system is 64bit from Windows Service

I created a windows service that wants to check if the system is 64bit or 32bit and after checking this downloads the appropriate files from my server .But the code i have now is not working.

I am using.

int system = IntPtr.Size;
if (system == 4)
{
    //the system is 32 bit
    WebClient webClient = new WebClient();
    webClient.DownloadFile("http://www.myserver.com/updates/dll/bin.dll", "C:\bin.dll");    
}
if (system == 8)
{
    //the system is 64bit
    WebClient webClient = new WebClient();
    webClient.DownloadFile("http://www.myserver.com/updates/dll/64/bin.dll", "C:\bin.dll");
}

Upvotes: 1

Views: 93

Answers (2)

user3094087
user3094087

Reputation:

Instead of using IntPtr.Size use the built in function instead. MSDN says https://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem(VS.100).aspx It can be called through Environment

Upvotes: 1

Andrey Korneyev
Andrey Korneyev

Reputation: 26886

Instead of checking pointer size you can just use System.Environment.Is64BitOperatingSystem property to check if your operation system version is x64.

Upvotes: 1

Related Questions