0

我在另一个站点上找到了这个脚本,但我无法让它工作,而且我不太了解批处理脚本

Set objWshShell = WScript.CreateObject("WScript.Shell")

strOSVersion = objWshShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\CurrentVersion")

If strOSVersion = "5.1" Then
    Debug.WriteLine("Windows XP")
    Rem Insert Windows XP Statements
ElseIf strOSVersion = "6.0" Then
    Debug.WriteLine("Windows Vista")
    Rem Insert Windows Vista Statements
ElseIf strOSVersion = "6.1" Then
    Debug.WriteLine("Windows 7")
    Rem Insert Windows 7 Statements
End If

现在如果我运行它,我会在第二行得到错误

'strOSVersion' is not recognized as an internal or external command
operable program or batch file.
= was unexpected at this time.

我不知道为什么

4

3 回答 3

2

这是我整理并经常用于确定操作系统的批处理脚本 (.bat)。

@ECHO OFF
SetLocal

REM --------> EDIT BELOW <--------

REM Edit below if you would like to audit the pc's you run this on and store the information in a file, either T or F (for True or False)
set storeValue=T

REM Edit below the location on a network drive that you can write to
set sharePath=\\servername\sharepath

REM -----> DO NOT EDIT BELOW <-----

IF NOT EXIST C:\Temp MD C:\Temp
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr ProductName>C:\temp\osver.txt
set osver=
set tempLoc=C:\Temp
FOR /F "tokens=3* delims= " %%I IN (%tempLoc%\OSver.txt) DO SET osVer=%%I %%J
echo.-----------------------------------------
echo.  You are running: %osVer%
echo.-----------------------------------------

IF '%storeValue%'=='F' goto end
IF '%storeValue%'=='T' goto storeValue

:storeValue
ipconfig |findstr IPv4>c:\temp\ipadd.txt
REM FOR /F "tokens=12* delims=." %%A IN (%tempLoc%\IPAdd.txt) DO SET IPAdd=%%A.%%B
FOR /F "tokens=2* delims=:" %%A IN (%tempLoc%\IPAdd.txt) DO SET IPAdd=%%A
IF EXIST %sharePath%\PC_Audit_List.txt goto audit
echo.PC Audit List>%sharePath%\PC_Audit_List.txt
echo.------------------------------------------------------------->>%sharePath%\PC_Audit_List.txt
goto audit

:audit
echo.%computername%  -  %IPAdd%  -  %osVer%>>%sharePath%\PC_Audit_List.txt
goto end

:end
IF EXIST %tempLoc%\OSver.txt del %tempLoc%\OSver.txt /f /q
IF EXIST %tempLoc%\IPAdd.txt del %tempLoc%\IPAdd.txt /f /q
EndLocal
pause
exit

我相信这会满足您的需求,我已经包含了一个选项供您将 IP、名称和版本写入文件。

于 2013-04-30T16:37:54.067 回答
2

这是一个VB脚本。您可以保存在名为 test.vbs 的文件中

然后打开命令提示符,将目录更改为保存文件的位置。在提示符下键入cscript test.vbs

在此之前,我将Debug.WriteLine调用改为WScript.Echo改为。

于 2013-04-30T14:50:11.087 回答
0
@echo off
setlocal EnableDelayedExpansion

::Identify OS
for /F "delims=" %%a in ('ver') do set ver=%%a
set Version=
for %%a in (95=95 98=98 ME=ME NT=NT 2000=2000 5.1.=XP 5.2.=2003 6.0.=Vista 6.1.=7 6.2.=8 6.3=8.1) do (
   if "!Version!" equ "this" (
      set Version=Windows %%a
   ) else if "!ver: %%a=!" neq "%ver%" (
      set Version=this
   )
)

::Identify bit
if exist "%SYSTEMDRIVE%\Program Files (x86)" (
   set Type=64 bit
) else (
   set Type=32 bit
)

::Display result
echo %Version% %Type%
echo/
pause

复制自:http ://www.dostips.com/forum/viewtopic.php?f=3&t=4387

于 2013-04-30T16:52:06.483 回答