Tuesday, April 30, 2013

manually install notepad++

set path=%path%;%~dp0
7z xy "%~dp0npp*.7z" -o"c:\npp"
for %%a in (cmd reg xml vbs bat html htm) do ^
reg add HKCU\Software\Classes\%%afile\shell\edit\command ^
/ve /t reg_expand_sz /d "c:\npp\notepad++.exe %%1" /f

for %%a in (txt ini inf) do ^
reg add HKCU\Software\Classes\%%afile\shell\open\command ^
/ve /t reg_expand_sz /d "c:\npp\notepad++.exe %%1" /f

Integrate sed, awk, ls, grep in windows command prompt session

set path=%path%;%~dp0
This is such a great way to integrate sed, awk, ls, grep support in Run Once (First Run) scripts.
Just place sed.exe, libiconv2.dll, libintl3.dll, regex2.dll, awk.exe, grep.exe, ls.exe together with batch file.

This method will integrate just in session.
That is good - just in session :)

Somehow sed.exe will not work out of the box if just copy to %systemroot%\system32 or sed will not work from UNC path running from XP operating system.

Files related:

Monday, April 29, 2013

Flexible JRE msi silent installer

This will use default JRE msi folders. located in JRE root folder JRE.
@echo off
for /f %%a in ('ls -d "%~dp0JRE\*" ^| grep -v "x64"') do (
echo 32-bit %%a
for /f %%b in ('dir /b "%%a\*.msi"') do msiexec /i %%a\%%b /qn
for /f %%a in ('ls -d "%~dp0JRE\*" ^| grep "x64"') do (
echo 64-bit %%a
for /f %%b in ('dir /b "%%a\*.msi"') do msiexec /i %%a\%%b /qn

Related files:

Another not flexible way
@echo off
setlocal EnableDelayedExpansion
set v=jre1.7.0_51

echo Checking for JRE..

if "%ProgramFiles(x86)%"=="" (
reg query "%sw%\JavaSoft" > nul 2>&1
if not !errorlevel!==0 msiexec /i "%~dp0%v%\%v%.msi" /qb

reg query "%sw%\JavaSoft\Java Runtime Environment" > nul 2>&1
if not !errorlevel!==0 msiexec /i "%~dp0%v%\%v%.msi" /qb

goto end

reg query "%sw%\Wow6432Node\JavaSoft" > nul 2>&1
if not !errorlevel!==0 msiexec /i "%~dp0%v%\%v%.msi" /qb

reg query "%sw%\Wow6432Node\JavaSoft\Java Runtime Environment" > nul 2>&1
if not !errorlevel!==0 msiexec /i "%~dp0%v%\%v%.msi" /qb

reg query "%sw%\JavaSoft" > nul 2>&1
if not !errorlevel!==0 msiexec /i "%~dp0%v%_x64\%v%.msi" /qb

reg query "%sw%\JavaSoft\Java Runtime Environment" > nul 2>&1
if not !errorlevel!==0 msiexec /i "%~dp0%v%_x64\%v%.msi" /qb


set u=Microsoft\Windows\CurrentVersion\Uninstall
set k={4A03706F-666A-4037-7777-5F2748764D10}
if not "%ProgramFiles(x86)%"=="" set x=Wow6432Node\
reg query "%sw%\%x%%u%\%k%" > nul 2>&1
if !errorlevel!==0 msiexec /x %k% /qb


Printer driver prompt UAC, driver update needed, Windows 7

Enable "Allow non-administrator to install drivers for these device setup classes"

Add printer ID

Install administrative template pack
C:\Program Files (x86)\Microsoft Group Policy\win72008r2\PolicyDefinitions to C:\Windows\SYSVOL\domain\Policies\PolicyDefinitions

Enable "Point and Print Restrictions" under Computer Configuration

Set "Do not show warnings or elevation prompt"

Open user configuration and also enable

Update client policy with gpupdate /force

For remote update using psexec. Replace %1 with remote computername
psexec /accepteula \\%1 gpupdate /force


Sunday, April 28, 2013


Saturday, April 27, 2013

add windows system %path% variable, commad line

The idea is update the path environment via command line.

I can not use %path% variable cause it reports %systemroot% as c:\windows Like this code. It do the trick but it is wrong:
set add=c:\tools
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ^
/v Path /t REG_EXPAND_SZ /d "%path%;%add%" /f
I have to play with:
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

When i query from XP it reports:

When i query Windows 7 it reports:

I start to make work around with reg query.
This solution included finding duplicate entry and do not let you add existing path variable
@echo off
set p=c:\\portable
for /f "tokens=*" %%a in ('^
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path ^|
sed "s/! REG.EXE VERSION 3.0//I" ^|
sed "s/Path//I" ^|
sed "s/REG_EXPAND_SZ//I" ^|
sed "s/HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment//I" ^|
sed "s/^[ \t]*//g" ^|
sed "/./!d" ^|
sed "$a;%p%" ^|
sed "s/;/\n/g" ^|
awk "!a[$0]++" ^|
sed "/./!d" ^|
sed ":a;N;$!ba;s/\n/;/g"') do (
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ^
/v Path /t REG_EXPAND_SZ /d "%%a" /f
Some explanations:
sed "s/! REG.EXE VERSION 3.0//I" deletes first founded "! REG.EXE VERSION 3.0". This is needed to support Windows XP. I - means not case sensitive

sed "s/Path//I" deletes first founded "path"

sed "s/REG_EXPAND_SZ//I" deletes first founded "REG_EXPAND_SZ"

sed "s/HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment//I" deletes first founded
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

sed s/^[ \t]*//g" deletes all tabs and white spaces at the start of the line

sed "/./!d" removes all empty lines.

sed "$a;%p%" finally adds new variable

sed "s/;/\n/g" substitute semicolon with new line character. It splits all variables into colon

awk "!a[$0]++" since the is each variable on single line we can check for duplicate entry and remove it.

sed "/./!d" - if something was found dublicated then now it is removed and there is one line witch contains nothing and this line must me removed.

sed ":a;N;$!ba;s/\n/;/g" finally we substitute back again new line character with semicolon :)

The set p= variable must contains path with double backslashes like
C:\\Program Files (x86)\\GnuWin32\\bin

You need sed and awk to run the code.

Blog Archive