I am trying to create a batch file that will create a simple text report on a machine, that lists both hardware and software installed. I have attached the code that does the hardware report but there is a loop that I think might be coming from how I am trying to report on the freediskspace. If you run the below code it appears to run 3 times and I think this is due to the code trying to report on all local hard drives on my test machine.
Once this problem is fixed I need to add to the report a list of installed software I tried different methods and find a report on why different methods don't always capture all installed programs. The work around is a VBS file but I am not sure how to call the VBS file from the batch file. If someone has a better method then please let me know.
Thank you to all that can help
Code: Select all
@echo off & setlocal
if %os%==Windows_NT goto WINNT
goto NOCON
:WINNT
echo .Using a Windows NT based system
REM set variables
set system=
set manufacturer=
set model=
set serialnumber=
set osname=
set sp=
setlocal ENABLEDELAYEDEXPANSION
set totalMem=
set availableMem=
set usedMem=
Set IP=
echo Getting data [Computer: %computername%]
echo Please Wait....
REM Get Computer Name
FOR /F "tokens=2 delims='='" %%A in ('wmic OS Get csname /value') do SET system=%%A
REM Get Computer Manufacturer
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Manufacturer /value') do SET manufacturer=%%A
REM Get Computer Model
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A
REM Get Computer Serial Number
FOR /F "tokens=2 delims='='" %%A in ('wmic Bios Get SerialNumber /value') do SET serialnumber=%%A
REM Get Computer OS
FOR /F "tokens=2 delims='='" %%A in ('wmic os get Name /value') do SET osname=%%A
FOR /F "tokens=1 delims='|'" %%A in ("%osname%") do SET osname=%%A
REM Get Computer OS SP
FOR /F "tokens=2 delims='='" %%A in ('wmic os get ServicePackMajorVersion /value') do SET sp=%%A
REM Get Memory
FOR /F "tokens=4" %%a in ('systeminfo ^| findstr Physical') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a)
set totalMem=%totalMem:,=%
set availableMem=%availableMem:,=%
set /a usedMem=totalMem-availableMem
REM Get IP Address
FOR /f "tokens=2 delims=:" %%a in ('ipconfig^|find "IPv4 Address"') do (
set IP=%%a
)
:REM Get driveInfo method from 'viewtopic.php?t=5555#p34130'
set "freeB=" & set "sizeB="
for /f "usebackq skip=1 tokens=1,2" %%X in (`
wmic logicaldisk where "DeviceID='C:'" get freespace^,size
`) do if not defined freeB (set "freeB=%%X" & set "sizeB=%%Y")
set/a freeMB = %freeB:~0,-6% & set/a sizeMB = %sizeB:~0,-6%
set/a freePCT = (100 * freeMB + sizeMB / 2) / sizeMB
call :mb2gib freeMB freeGiB & call :mb2gib sizeMB sizeGiB
goto :Report
:mb2gib
@rem double 1000/1024 mb->mib correction
set/a %2 = (125 * ((125 * %1 + 64) / 128) + 64) / 128
@rem 1/1024 mib->gib conversion
set/a %2 = (%2 + 512) / 1024
echo Summary of report
:Report
echo --------------------------------------------
echo System Name: %system%
echo Report Run by: %userdomain%\%username%
echo System IP Address: %IP%
echo Manufacturer: %manufacturer%
echo Model: %model%
echo Serial Number: %serialnumber%
echo Operating System: %osname%
echo Total Memory: %totalMem%
echo Used Memory: %usedMem%
echo Computer Processor: %processor_architecture%
echo Service Pack: %sp%
echo Drive C: %freeGiB% GB free / %sizeGiB% GB size = %freePCT%%% available (= %freeB% / %sizeB%)
echo --------------------------------------------
REM Generate Report file
SET file="%~dp0%computername%.txt"
echo -------------------------------------------- >> %file%
echo Details For: %system% >> %file%
echo Report Run by: %userdomain%\%username% >> %file%
echo IP Address: %IP% >> %file%
echo Manufacturer: %manufacturer% >> %file%
echo Model: %model% >> %file%
echo Serial Number: %serialnumber% >> %file%
echo Operating System: %osname% >> %file%
echo Total Memory: %totalMem% >> %file%
echo Used Memory: %usedMem% >> %file%
echo Computer Processor: %processor_architecture% >> %file%
echo Service Pack: %sp% >> %file%
echo Drive C: %freeGiB% GB free / %sizeGiB% GB size = %freePCT%%% available (= %freeB% / %sizeB%) >> %file%
echo -------------------------------------------- >> %file%
echo wmic /output:C:\InstallList.txt product get name,version >> %file%
REM request user to push any key to continue
pause
goto END
:NOCON
echo Error...Invalid Operating System...
echo Error...No actions were made...
goto END
:END
VBS code for getting a list of installed programs from a windows based machine
Code: Select all
taken from stackoverflow.com/questions/673233/wmi-installed-query-different-from-add-remove-programs-list
Const HKLM = &H80000002
Set objReg = GetObject("winmgmts://" & "." & "/root/default:StdRegProv")
Set objFSO = CreateObject("Scripting.FileSystemObject")
outFile="programms.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
writeList "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", objReg, objFile
writeList "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", objReg, objFile
objFile.Close
Function writeList(strBaseKey, objReg, objFile)
objReg.EnumKey HKLM, strBaseKey, arrSubKeys
For Each strSubKey In arrSubKeys
intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "DisplayName", strValue)
If intRet <> 0 Then
intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "QuietDisplayName", strValue)
End If
objReg.GetStringValue HKLM, strBaseKey & strSubKey, "DisplayVersion", version
objReg.GetStringValue HKLM, strBaseKey & strSubKey, "InstallDate", insDate
If (strValue <> "") and (intRet = 0) Then
objFile.Write strValue & "," & version & "," & insDate & vbCrLf
End If
Next
End Function