Posts

Showing posts from March, 2017

[Batch file] - Output of a command to variable

If you want to set the output of a command to a value you have to capture it in a  for  statement like this: for /f "tokens=2 delims=:" %%a in ('systeminfo ^| find "OS Name"') do set OS_Name=%%a Then remove the leading spaces like this: (there is probably a better way to do this) for /f "tokens=* delims= " %%a in ("%OS_Name%") do set OS_Name=%%a A few things to note here: 1.)  "tokens=2 delims=:"  is setting the delimiter to  :  and it is selecting the second section only, which will pull only the part you want.  2.) the  |  is escaped with a  ^ , this needs to be done in  for  loops or anything after that will attempt to execute as seperate commands.  3.)  "tokens=* delims= "  The token here is * which is all tokens. ======================= Examples of WMIC output to variables: echo WMIC output to variables for /f "usebackq tokens=1,2 delims==|" %%I in (`wmic os get name^,version /format:l

Batch Script to find the version of .Net framework installed on the PC

Method1: @echo off   setlocal   set alias=Reg query "HKLM\Software\Microsoft\NET Framework Setup\NDP"   FOR /F "TOKENS=6 DELIMS=\." %%A IN ('%alias%') DO set .NetVer=%%A   ECHO The most current version of Net in use is %.NetVer% Method2: dir %windir%\Microsoft.Net\framework\v* Output: C:\>dir %windir%\Microsoft.Net\framework\v*  Volume in drive C has no label.  Volume Serial Number is 60F4-4F6D  Directory of C:\Windows\Microsoft.Net\framework 02/25/2016  04:56 AM              v1.0.3705 07/14/2009  10:37 AM              v1.1.4322 02/14/2017  09:27 AM              v2.0.50727 11/21/2010  08:26 AM              v3.0 10/14/2013  09:28 PM              v3.5 03/16/2017  09:37 AM              v4.0.30319 04/05/2016  02:03 PM              VJSharp                0 File(s)              0 bytes                7 Dir(s)  31,032,090,624 bytes free C:\>

Getting values using wmic

wmic computersystem get /value Displays all computer system values as list ================================= The below wmi command gives the OS and the service pack version. wmic os get Caption,CSDVersion /value Output: Caption=Microsoft Windows 7 Enterprise CSDVersion=Service Pack 1 ========================== Filtering with "where": wmic logicaldisk where drivetype=3 get description,name Ref: http://www.cryer.co.uk/brian/windows/batch_files/how_to_list_drive_letters.htm https://ss64.com/nt/wmic.html In a batch file: @echo off for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value') do echo %%d

[Windows driver store] Add/remove driver package to the driver store using PnPUtil

PnPUtil (PnPUtil.exe) is a command line tool that lets an administrator perform the following actions on  driver packages : Adds a driver package to the  driver store . Deletes a driver package from the driver store. Enumerates the driver packages that are currently in the driver store. Only driver packages that are not in-box packages are listed. An  in-box  driver package is one which is included in the default installation of Windows or its service packs. Usage: ------ pnputil.exe [-f | -i] [ -? | -a | -d | -e ] Examples: pnputil.exe -a a:\usbcam\USBCAM.INF      -  Add package specified by USBCAM.INF pnputil.exe -a c:\drivers\*.inf                       - Add all packages in c:\drivers\ pnputil.exe -i -a a:\usbcam\USBCAM.INF   -  Add and install driver package pnputil.exe -e                                              - Enumerate all 3rd party packages pnputil.exe -d oem0.inf                               - Delete package oem0.inf pnputil.exe