Good day all,
So I wrote a simple .bat file I was going to call on user startup to get the MS Office versions. Tested fine for admins but unfortuatnely not so with standard users. I suspect this is because we have: Prevent access to registry editing tools setup in the GPO, though disable regedit from running silenty is set to 'no'.
So my questions is a) is that the likely reason why my script isn't working and b) if so is there a regedit alternative. Trying to keep it nice and simple.
Code below:
@echo off
reg query HKEY_CLASSES_ROOT\Access.Application\CurVer
if errorlevel 1 goto five
for /f "tokens=3" %%i in ('reg query HKEY_CLASSES_ROOT\Access.Application\CurVer') do (
if %%i equ Access.Application.15 goto one
if %%i equ Access.Application.14 goto two
if %%i equ Access.Application.12 goto three
if %%i equ Access.Application.11 goto four
goto five
)
:one REM 2013 Pro
echo %computername%,Office 2013 Pro" >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:two REM 2010 Pro
echo %computername%,Office 2010 Pro >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:three REM 2007 Pro
echo %computername%,Office 2007 Pro" >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:four REM 2003 Pro
echo %computername%,Office 2003 Pro" >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:five REM Not Pro Verion
reg query HKEY_CLASSES_ROOT\Word.Application\CurVer
if errorlevel 1 goto ten
for /f "tokens=3" %%i in ('reg query HKEY_CLASSES_ROOT\Word.Application\CurVer') do (
if %%i equ Word.Application.15 goto six
if %%i equ Word.Application.14 goto seven
if %%i equ Word.Application.12 goto eight
if %%i equ Word.Application.11 goto nine
goto ten
)
:six REM 2013 STD
echo %computername%,Office 2013 Std" >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:seven REM 2010 STD
echo %computername%,Office 2010 Std" >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:eight REM 2007 STD
echo %computername%,Office 2007 Std" >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:nine REM 2003 STD
echo %computername%,Office 2003 Std" >>\\SERVERNAME\bslogs$\officeVersions.csv
exit
:ten REM no idea
echo %computername%,????" >>\\SERVERNAME\bslogs$\officeVersions.csv exit
Many thanks, Martin
I dunno. Sounds plausible.
You can query registry values with WMI and the StdRegProv class.
Sorry. It is neither nice nor simple.
I've had to simulate
reg.exe
using WMI queries in the past to query remote registries. I hacked together a:getRegValue
function that automates much of this. Run this and see whether it will work for what you have in mind.As additional food for thought,
wmic.exe
supports remote queries with the following syntax:Rather than having each user run your script at logon, you could use the remote switches to query all machines in batch.
Partly as an academic exercise and partly to head off anyone who might be thinking "You should use PowerShell", I rewrote the
:getRegValue
function to invoke PowerShell hybrid code. Unfortunately, querying the registry via WMI with PowerShell is still complicated. Although the string operations and object retrieval are easier, the marginally more economical code doesn't quite justify the added execution time.Just because I felt like a challenge, I decided to try a third version employing JScript hybrid code this time. Believe it or not, this is the fastest of all three methods.