Jump to content

problems working with variables


Recommended Posts

Hello,

i have an problem by an variable.

thats the code:

for /f "tokens=*" %%g in ('dir/b ^"%cddrive%\hotfixes\%osv%\%lang%\^"') do reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\%%g" /v Installed | find "0x1" > nul
if errorlevel 1 start /wait .....

the batch looking the files on my share, then he looks for the installed hotfixes and when an hotfix was not installed, but in the directory exist the script goes to install... thats the idea.,

the problem is the %%g variable, if i run before reg query the echo command, the script told me all hotfixes in the directory, but not in the reg query command.

any solutions, ideas ?

Link to comment
Share on other sites


Why not using WSUS for this purposes (I suppose it is for LAN, right?)...

But for your problem, I am sorry I didnt understand - what echo command??? Easier error-prone way would be to redirect registry to file and then make file content/FS compare...

Link to comment
Share on other sites

I think you main problem is that the variable %g is returning a filename with path and extension, whereas the queried subkey has no extension will be the filename only.

  • You would therefore need to use %%~ng in your reg query command.

Here is a modified version of what you gave us

for /f "delims=" %%g in ('dir /b/a-d "%cddrive%\hotfixes\%osv%\%lang%\*.exe"') do (
 reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\%%~ng" /v Installed|find "0x1">nul||start "" /wait .....
)

Link to comment
Share on other sites

@Yzöwl

thanks, thats what i need... some modifications and it works....

but i forgot to build an loop, now i must run the batch xx of hotfixes are in the folder.

any solutions again ?

heres my working code:

if exist "c:\programme\" set lang=DEU
if exist "c:\program files\" set lang=ENU

ver | find /i "3790" > nul
if not errorlevel 1 set osv=ws2k3
ver | find /i "2600" > nul
if not errorlevel 1 set osv=WindowsXP

for /f "delims=" %%g in ('dir /b ^"%cddrive%\hotfixes\%osv%\%lang%\^"') do (reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\%%~g" /v Installed | find "0x1" > nul||start /wait %cddrive%\hotfixes\%osv%\%lang%\%%g\%osv%-%%~g-x86-%lang%.exe /quiet /norestart)

/BR

Edited by melnib00ne
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...