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:
http://gnu.catonrug.net/sed.exe
http://gnu.catonrug.net/libiconv2.dll
http://gnu.catonrug.net/libintl3.dll
http://gnu.catonrug.net/regex2.dll
http://gnu.catonrug.net/awk.exe
http://gnu.catonrug.net/ls.exe
http://gnu.catonrug.net/grep.exe

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:
http://gnu.catonrug.net/ls.exe
http://gnu.catonrug.net/grep.exe

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

echo Checking for JRE..

if "%ProgramFiles(x86)%"=="" (
: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
)

:x64
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


:end

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

endlocal

Printer driver prompt UAC, driver update needed, Windows 7

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

Add printer ID
{4d36e979-e325-11ce-bfc1-08002be10318}

Install administrative template pack
http://download.microsoft.com/download/7/1/2/712B8123-5867-4A6E-9DF2-C164B227FCBE/Win7-2008R2-admx.msi
Copy
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

Source:
http://msdn.microsoft.com/en-us/library/windows/hardware/ff553426(v=vs.85).aspx
http://answers.microsoft.com/en-us/windows/forum/windows_7-hardware/install-network-printers-without-local-admin/b21aa72b-5a7f-485d-999e-f844e7d4a550
http://community.spiceworks.com/how_to/show/1269-stop-the-windows-7-prompts-for-printer-install

Sunday, April 28, 2013

Fluffy

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 :)

Note:
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