简体   繁体   中英

Batch Script to check Windows 7 Activation

I am trying to do a batch script to check the Activation status of the workstations of my LAN, so far I have the following code that saves into a .txt the status of the activation.

@echo off
cscript /nologo c:\windows\system32\slmgr.vbs /xpr > ActivatedStatus.txt | findstr /i /c:" will expire "> NUL 2>&1
if [%errorlevel%]==[0] (echo Not permanently activated.) else (echo Permanently activated)
exit /b

An the output ActivatedStatus.txt looks like this:

Windows(R) 7, Professional edition:
The machine is permanently activated.

What I want is to just create a .txt if the workstation is not activated but I can't get to work the if statements.

By both attempting to both redirect and pipe on the same command line, you're only redirecting, nothing is being feed into findstr . So, you'll either need to only pipe the data along:

cscript /nologo c:\windows\system32\slmgr.vbs /xpr | findstr /i /c:" will expire "> NUL 2>&1

Or, if you want to create the text file, you need to create it first, then pipe it's data to findstr :

cscript /nologo c:\windows\system32\slmgr.vbs /xpr > ActivatedStatus.txt
type ActivatedStatus.txt | findstr /i /c:" will expire "> NUL 2>&1

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