简体   繁体   English

C#从Windows Service检查系统是否为64位

[英]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. 我创建了一个Windows服务,该服务想检查系统是64位还是32位,并在检查之后从我的服务器上下载了适当的文件。但是我现在使用的代码无法正常工作。

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. 代替使用IntPtr.Size,而是使用内置函数。 MSDN says https://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem(VS.100).aspx It can be called through Environment MSDN说https://msdn.microsoft.com/zh-cn/library/system.environment.is64bitoperatingsystem(VS.100).aspx可以通过环境调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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