简体   繁体   中英

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");
}

无需检查指针大小,您可以仅使用System.Environment.Is64BitOperatingSystem属性来检查您的操作系统版本是否为x64。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM