如果OS是64位

时间:2014-12-13 05:15:00

标签: batch-file command-line vbscript

我正在尝试写入文件,并且我有一个if语句来检测用户是使用64位还是32位操作系统。我试过这个,

write.bat (它在appdata文件夹中生成一个vbs文件)

if defined ProgramFiles(x86) (
color 2
) else (
color 3
)

完美无缺。但是,当谈到写一个文件时,它奇怪地试图写两个!

if defined ProgramFiles(x86) (

find "lnk.targetpath = ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe""" %APPDATA%\System.vbs || echo lnk.targetpath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe">>%APPDATA%\System.vbs

    ) else (

find "lnk.targetpath = ""C:\Program Files\Google\Chrome\Application\chrome.exe""" %APPDATA%\System.vbs || echo lnk.targetpath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe">>%APPDATA%\System.vbs

    )

如何解决此问题?

1 个答案:

答案 0 :(得分:2)

尝试使用此vbscript检查用户是否使用64位或32位操作系统。

'un vbscript qui détermine automatiquement le type de votre système d'exploitation
Copyright = " © Hackoo © 2014"
MsgFr = "Le type de votre système d'exploitation " 
MsgAr = ChrW(1606)&ChrW(1608)&ChrW(1593)&ChrW(32)&ChrW(1606)&ChrW(1592)&ChrW(1575)&ChrW(1605)&ChrW(32)&_
ChrW(1575)&ChrW(1604)&ChrW(1578)&ChrW(1588)&ChrW(1594)&ChrW(1610)&ChrW(1604)&ChrW(32)&ChrW(1575)&ChrW(1604)&_
ChrW(1582)&ChrW(1575)&ChrW(1589)&ChrW(32)&ChrW(1576)&ChrW(1603)
If Is64Bit = False then
    MsgBox MsgFr & MsgAr & VbCrLF & "32 bits" ,Vbinformation,MsgFr & MsgAr & Copyright
else
    Msgbox MsgFr & MsgAr & VbCrLF & "64 bits",Vbinformation,MsgFr & MsgAr & Copyright
End if
'**************************************************************************************************************
Function Is64Bit() 
    Is64Bit = False 
    Dim colOS : Set colOS = GetObject("WinMGMTS://").ExecQuery("SELECT AddressWidth FROM Win32_Processor",, 48) 
    Dim objOS 
    For Each objOS In colOS 
        If objOS.AddressWidth = 64 Then Is64Bit = True 
    Next 
End Function
'***************************************************************************************************************

在批处理中,您可以尝试这样:

@echo off
wmic cpu get addresswidth | find "32" >nul  && echo systeme 32 bit || echo systeme 64 bit
pause
相关问题