Determining OS version via Scripting

你。 提交于 2019-12-11 21:09:03

问题


I found this script on another site but I can not get it to work and I don't know batch scripting that well

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

now if I run this I get the error on the second line

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

I do not know why


回答1:


It's a VB script. You can save in a file named like test.vbs

Then open a command prompt, change directory to where you saved the file. At the prompt type cscript test.vbs.

Before that, I changed the Debug.WriteLine calls to WScript.Echo instead.




回答2:


This is a Batch Script (.bat) that I've put together and use often for determining OS.

@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

I'm sure this will suit your needs, I've included an option for you to write the IP, Name and then the Version into a file.




回答3:


@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

Copied from: http://www.dostips.com/forum/viewtopic.php?f=3&t=4387



来源:https://stackoverflow.com/questions/16302466/determining-os-version-via-scripting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!