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.

Open command windows here without holding shift key, open terminal here in windows

This is tested and works in Windows 7. Delete these three keys to enable "Open command windows here" by right click in every folder
reg delete "HKCR\Drive\shell\cmd" /v "Extended" /f
reg delete "HKCR\Directory\shell\cmd" /v "Extended" /f
reg delete "HKCR\Directory\Background\shell\cmd" /v "Extended" /f
To set back defaults use
reg add "HKCR\Drive\shell\cmd" /v "Extended" /t REG_SZ /d "" /f
reg add "HKCR\Directory\shell\cmd" /v "Extended" /t REG_SZ /d "" /f
reg add "HKCR\Directory\Background\shell\cmd" /v "Extended" /t REG_SZ /d "" /f

Source:
http://superuser.com/questions/240279/windows-open-command-prompt-window-without-holding-shift
http://darrenyates.com.au/2010/12/quick-tip-windows-7s-open-command-prompt-here/2061
http://superuser.com/questions/98322/windows-xp-open-terminal-here-shell-extension

Friday, April 26, 2013

sed.exe multiple string substitution with one string, OR replacement

Use \| to make multiple substitution with one string. \| works like OR.
sed "s/\d034\|\d039\|(\|)/\n/g" input.txt > output.txt
This example will replace ", ', ( and ) with new line character \n.
\n works like html tag <br /> - brake rule.

Related links:
http://members.efn.org/~gjb/asciidec.html
http://www-rohan.sdsu.edu/doc/sed.html
Related files:
http://gnu.catonrug.net/sed.7z

sed query linked http files

This is basic query to search all classic file links in html file.
sed "s/\d034/\n/g;s/\d039/\n/g;s/\d040/\n/g;s/\d041/\n/g;" index.html | sed -n "/http/p" > out.log
\d034 stands for " character.
\d039 stands for ' character.
\d040 stands for ( character.
\d041 stands for ) character.

I test this on java archive download pages from
http://www.oracle.com/technetwork/java/javase/archive-139210.html

Need to run:
http://gnu.catonrug.net/sed.7z

Related:
http://members.efn.org/~gjb/asciidec.html
http://www-rohan.sdsu.edu/doc/sed.html

Thursday, April 25, 2013

Office 2010 silent install-uninstall together with language pack and proofing tools

Create office silent install config file proplus.xml:
<Configuration Product="ProPlus">
<Display Level="none" CompletionNotice="no" SuppressModal="yes" AcceptEula="yes" />
<Setting Id="SETUP_REBOOT" Value="Never" />
</Configuration>
Create all necessary language packs silent install config files. For example de-de.xml with content:
<Configuration Product="OMUI.de-de">
<Display Level="none" CompletionNotice="no" SuppressModal="yes" AcceptEula="yes" />
<Setting Id="SETUP_REBOOT" Value="Never" />
</Configuration>
For another language file you must change the inside OMUI.xx-yy and name it like xx-yy.xml

Into the office root folder create two sub-folders x86 and x64 and extract booth office versions.

Into each subfolder create all language pack sub-folders.
For example de-de, ru-ru, lv-lv.

Extract language pack with command X16-12345.exe /extract:de-de

You can found it
Office 2010 language packs, proofing tools included

When all installation source is prepared make install.cmd that contains:
@echo off
setlocal EnableDelayedExpansion
set src=%~dp0
set proplus=PROPLUS
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set OMUI=Office14.OMUI
set o14=Office14.%proplus%
set lang=de-de ru-ru lv-lv
set i=/config "%src%\%proplus%.xml"
set l=/config "%src%\%%l.xml"

if "%ProgramFiles(x86)%"=="" (
:x86
reg query %sw%\%u%\%o14% > nul 2>&1
if not !errorlevel!==0 (
start /wait "" "%src%\x86\setup.exe" %i%
for %%l in (%lang%) do (
reg query %sw%\%u%\%OMUI%.%%l > nul 2>&1
if not !errorlevel!==0 start /wait "" "%src%\x86\%%l\setup.exe" %l%
)
goto exit
)
)

reg query %sw%\Wow6432Node\%u%\%o14% > nul 2>&1
if !errorlevel!==0 goto exit
reg query %sw%\%u%\%o14% > nul 2>&1
if not !errorlevel!==0 (
start /wait "" "%src%\x64\setup.exe" %i%
for %%l in (%lang%) do (
reg query %sw%\%u%\%OMUI%.%%l > nul 2>&1
if not !errorlevel!==0 start /wait "" "%src%\x64\%%l\setup.exe" %l%
)
)
:exit
endlocal
And uninstall.bat:
@echo off
setlocal EnableDelayedExpansion
set src=%~dp0
set proplus=PROPLUS
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set OMUI=Office14.OMUI
set o14=Office14.%proplus%
set lang=de-de ru-ru lv-lv
set x=/uninstall %proplus% /config "%src%\%proplus%.xml"
set l=/uninstall OMUI.%%l /config "%src%\%%l.xml"

if "%ProgramFiles(x86)%"=="" (
:x86
reg query %sw%\%u%\%o14% > nul 2>&1
if !errorlevel!==0 start /wait "" "%src%\x86\setup.exe" %x%
for %%l in (%lang%) do (
reg query %sw%\%u%\%OMUI%.%%l > nul 2>&1
if !errorlevel!==0 start /wait "" "%src%\x86\%%l\setup.exe" %l%
)
goto exit
)

:x64
reg query %sw%\Wow6432Node\%u%\%o14% > nul 2>&1
if !errorlevel!==0 start /wait "" "%src%\x86\setup.exe" %x%
for %%l in (%lang%) do (
reg query %sw%\Wow6432Node\%u%\%OMUI%.%%l > nul 2>&1
if !errorlevel!==0 start /wait "" "%src%\x86\%%l\setup.exe" %l%
)
reg query %sw%\%u%\%o14% > nul 2>&1
if !errorlevel!==0 start /wait "" "%src%\x64\setup.exe" %x%
for %%l in (%lang%) do (
reg query %sw%\%u%\%OMUI%.%%l > nul 2>&1
if !errorlevel!==0 start /wait "" "%src%\x64\%%l\setup.exe" %l%
)
:exit
endlocal

Tuesday, April 23, 2013

Integrate Picasa settings

Picasa registry keys always stands in HKCU registry hive.
The idea is place this file in directory where Picasa is installed.
Then change shortcut to this file so the settings will be integrated before run the program at first time:
$p="HKCU\Software\Google\Picasa\Picasa2\Preferences"
RegWrite($p ,"AutoUpgradeAsk","REG_DWORD","0")
RegWrite($p ,"AutoUpgradeCheck","REG_DWORD","0")
RegWrite($p ,"ReportStats","REG_DWORD","0")
RegWrite($p ,"showfeatureslink","REG_DWORD","39")
Run("Picasa3.exe")
Compile it with AutoIt:
http://www.autoitscript.com/files/autoit3/autoit-v3-setup.exe

I got inspired to make another solution reading method that also is very good:
http://micksmix.wordpress.com/2012/01/13/update-a-registry-key-for-all-users-on-a-system/

List all registry hives that contains software key

@echo off
setlocal EnableDelayedExpansion
for /f %%a in ('reg query hku') do (
for /f "tokens=3 delims=\" %%b in ('reg query %%a') do (
if %%b==Software echo %%a
)
)
endlocal
pause

RegShot, RegFromApp

This is Classic RegShot application:
http://sourceforge.net/projects/regshot/

You have two shots and then you compare two files and look for changed keys.

There are also another application called RegFromApp.
RegFromApp is totally awesome and must have application.
To work perfectly wit RegFromApp you must create shortcut to run in Windows XP mode

With RegFromApp you can capture registry changes for specified application.
Click new button:

Choose application which you want to capture:

Make a change you need to know in registry:

And you get just exact key what happened in registry:

http://www.nirsoft.net/utils/regfromapp.zip
http://www.nirsoft.net/utils/regfromapp-x64.zip

Home:
http://www.nirsoft.net/utils/reg_file_from_application.html

Monday, April 22, 2013

Add new menu entry to all files


This will add new menu entry.
This example will let you try to play all files with MPlayer media player.
reg add "HKCU\Software\Classes\*\shell\Play with MPlayer\command" /ve /t REG_SZ /d "\"%~dp0mplayer.exe\" -fs \"%%1\"" /f
You need to place this batch file in same location where mplayer.exe is having a good time. Run it with current user rights.

if not JRE at all

This will install JRE for fresh computer. Place boot x86 and x64 installers in same directory where this batch file is located.
@echo off
setlocal EnableDelayedExpansion
set sw=HKLM\SOFTWARE
set s=%~dp0
set o=/s ADDLOCAL=ALL IEXPLORER=1 JAVAUPDATE=0 REBOOT=Suppress

if "%ProgramFiles(x86)%"=="" (
:x86
reg query "%sw%\JavaSoft" > nul 2>&1
if not !errorlevel!==0 (
for /f "delims=" %%f in ('dir /b "%s%\jre-7u*i586.exe"') DO (
start /wait "" "%s%\%%f" %o%
)
)
reg query "%sw%\JavaSoft\Java Runtime Environment" > nul 2>&1
if not !errorlevel!==0 (
for /f "delims=" %%f in ('dir /b "%s%\jre-7u*i586.exe"') DO (
start /wait "" "%s%\%%f" %o%
)
)
start /wait "" msiexec /x {4A03706F-666A-4037-7777-5F2748764D10} /qn
goto end
)

:x64
reg query "%sw%\Wow6432Node\JavaSoft" > nul 2>&1
if not !errorlevel!==0 (
for /f "delims=" %%f in ('dir /b "%s%\jre-7u*i586.exe"') DO (
start /wait "" "%s%\%%f" %o%
)
)
reg query "%sw%\Wow6432Node\JavaSoft\Java Runtime Environment" > nul 2>&1
if not !errorlevel!==0 (
for /f "delims=" %%f in ('dir /b "%s%\jre-7u*i586.exe"') DO (
start /wait "" "%s%\%%f" %o%
)
)

reg query "%sw%\JavaSoft" > nul 2>&1
if not !errorlevel!==0 (
for /f "delims=" %%f in ('dir /b "%s%\jre-7u*x64.exe"') DO (
start /wait "" "%s%\%%f" %o%
)
)
reg query "%sw%\JavaSoft\Java Runtime Environment" > nul 2>&1
if not !errorlevel!==0 (
for /f "delims=" %%f in ('dir /b "%s%\jre-7u*x64.exe"') DO (
start /wait "" "%s%\%%f" %o%
)
)
start /wait "" msiexec /x {4A03706F-666A-4037-7777-5F2748764D10} /qn

:end

endlocal

Sunday, April 21, 2013

Friday, April 19, 2013

PDF Architect silent uninstall

You can uninstall pdf architect using msi source file
msiexec /x PDF_Architect_Setup_1.2.97.14551.msi /qn
Also can uninstall using product code key
msiexec /x {86D8A96B-1911-4C3F-AA16-0B47E053E492} /qn
For remote uninstall use psexec
psexec /accepteula \\%1 msiexec /x {86D8A96B-1911-4C3F-AA16-0B47E053E492} /qn
Replace %1 with remote computer name.

Silent uninstall with detection rule:
uninstall-pdf-architect.cmd
@echo off
setlocal EnableDelayedExpansion
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set k={86D8A96B-1911-4C3F-AA16-0B47E053E492}
if not "%ProgramFiles(x86)%"=="" set x=Wow6432Node\
reg query "%sw%\%x%%u%\%k%" > nul 2>&1
if !errorlevel!==0 (
echo Found PDF Architect. Uninstalling..
msiexec /x %k% /qn
)
endlocal
http://download.pdfforge.org/download/pdfarchitect/PDFArchitect-stable?download

Check out:
PDFCreator silent install without PDFArchitect

What is logged on remote machine

Simple command that displays locally logged users on remote machine:
psloggedon -l \\%1
This will show only locally users without any cached account:
psloggedon -l \\%1 | find /v "unknown"
This will output just the domain-name\username
for /f "tokens=3" %%a in ('%~dp0psloggedon.exe /accepteula -l \\%1 ^| find /v "unknown"') do (
echo %%a
)

Replace %1 with remote computername.

Related files:
http://download.sysinternals.com/files/PSTools.zip

Detect Connected over a slow link?: Yes

This will report computers with slow link connection:
@echo off
setlocal EnableDelayedExpansion
set d=\\Log_server\log\Slow.link.detect
if not exist "%d%" md "%d%"
for /f "tokens=3" %%a in ('%~dp0psloggedon.exe /accepteula -l ^| find /v "unknown"') do set u=%%a
systeminfo | find "Windows XP" > nul 2>&1
if not !errorlevel!==0 set r=/R
gpresult %r% /user %u% | find "Connected over a slow link?: Yes"
if !errorlevel!==0 gpresult %r% /user %u% > %d%\%computername%.log
endlocal
Related files:
http://download.sysinternals.com/files/PSTools.zip

Remote gpresult

For remote gpresult you need to know username who is working on remote machine.
remote.gpresult.cmd
psexec \\%1 gpresult /user %2\%3
%1 stands for Remote Computer name
%2 stands for Domain Name
%3 stands for username who is using this computer

Next one is advanced. You only need to specify remote computer name in %1
for /f "tokens=3" %%a in ('psloggedon -l \\%1 ^| find /v "unknown"') do set u=%%a
psexec \\%1 gpresult /user %u%

Related files:
http://download.sysinternals.com/files/PSTools.zip

slipstream two commands, for in do array

Use ^| to query specific text in text array.
for /f "tokens=3" %%i in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup /v "SourcePath" ^| findstr "REG_SZ"') do set SOURCE=%%i
%SOURCE%\FirstRun\FirstRun.bat
EXIT

Thursday, April 18, 2013

Paint.NET silent install and uninstall

This is tested and works on paint.NET version 4.0.13.

Download .NET 4.6.2:
NDP462-KB3151800-x86-x64-AllOS-ENU.exe
9a5d647ee710af2b1aede329c40bbe1a
a70f856bda33d45ad0a8ad035f73092441715431

Donwload and extract paint.net.4.0.13.install.exe from:
http://www.dotpdn.com/files/paint.net.4.0.13.install.zip
40c6b1f9b8f76c278109307ec1808561
e9d74db790b77c84290676adbe9231554aa5d6c0

silent-install.cmd
@echo off
setlocal EnableDelayedExpansion
set u=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
reg query "%u%" /s | find "paint.net" > nul 2>&1
if not !errorlevel!==0 (
:CheckForDotNet462
reg query "HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.6.2" > nul 2>&1
if not !errorlevel!==0 (
echo installing .NET Framework 4.6.2
start /wait "" "%~dp0NDP462-KB3151800-x86-x64-AllOS-ENU.exe" /passive /norestart
echo installation ended with errorcode !errorlevel!
if !errorlevel!==3010 echo computer restart is needed to complete installation
if not !errorlevel!==0 goto exit
)
for /f "tokens=*" %%a in ('dir /b "%~dp0paint.net*install.exe"') do (
echo paint.NET
start /wait "" "%~dp0%%a" /auto
rem http://www.getpaint.net/doc/latest/UnattendedInstallation.html
)
) else echo paint.NET already installed!
:exit
endlocal

silent-uninstall.cmd
@echo off
setlocal EnableDelayedExpansion
set u=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

rem list all uninstall keys under native hive
for /f "tokens=7 delims=\" %%a in ('^
reg query "%u%" /s ^|
find "\Uninstall\"') do (

rem dig deeper
reg query "%u%\%%a" /v DisplayName | find "paint.net" > nul 2>&1
if !errorlevel!==0 (
echo paint.net found under %%a
%systemroot%\system32\msiexec.exe /X %%a /qb
)

)

endlocal

Here is video how it happens to install on Windows 8.1 where .NET 4.6.2 is not installed:

PDFCreator silent install, no update

This will search for PDFCreator*.exe installer in directory.

Place only one installer.

At the end it will set do not update option for in local machine hive.
@echo off
for /f %%a in ('dir /b "%~dp0PDFCreator*.exe"') do (
"%~dp0%%a" /ForceInstall /VERYSILENT /LANG=English /COMPONENTS="program,ghostscript" /NORESTART
)
if not "%programfiles(x86)%"=="" set x=Wow6432Node\
reg add "HKLM\SOFTWARE\%x%PDFCreator\Program" /v "UpdateInterval" /t REG_SZ /d "0" /f

Wednesday, April 17, 2013

sed.exe mastering substitution, Windows

This is input of the file and now lets play with it.
Sunset
Awesome
Together
Hello
Inserts Meow at the start of each line. ^ means the start of line.
sed "s/^/Meow/"
Output
MeowSunset
MeowAwesome
MeowTogether
MeowHello
Inserts Meow at the end of each line. $ means end of line.
sed "s/$/Meow/"
Output
SunsetMeow
AwesomeMeow
TogetherMeow
HelloMeow
This will delete the last three symbols and insert Meow
sed "s/...$/Meow/"
SunMeow
AwesMeow
TogetMeow
HeMeow
This will crop all letters r, t, s, e form right side at the end of each line
sed "s/[rtse]*$//" in.txt
For example input Output will be
Sun
Awesom
Togeth
Hello
This will replace first s or S with Meow
sed "s/[sS]/Meow/"
Output will be
Meowunset
AweMeowome
Together
Hello
Source:
http://www-rohan.sdsu.edu/doc/sed.html

Tuesday, April 16, 2013

Monday, April 15, 2013

Report service status to log file

@echo off
setlocal EnableDelayedExpansion
set n=Spooler
set d=\\log_server\services\%n%
if not exist "%d%" md "%d%"
sc query %n% | find "STATE              : 4  RUNNING"
if not !errorlevel!==0 (
echo %n% is not running at %date% %time% >> %d%\bad_%computername%.log
) else echo %n% is running at %date% %time% >> %d%\ok_%computername%.log
endlocal

Sunday, April 14, 2013

System restore off, autounattend.xml

<settings pass="specialize">
<component name="Microsoft-Windows-SystemRestore-Main" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DisableSR>1</DisableSR>
</component>
</settings>
Source:
http://forums.mydigitallife.info/archive/index.php/t-10274.html
http://support.microsoft.com/kb/283073

Saturday, April 13, 2013

Always show all icons and notifications on the taskbar, command line, EnableAutoTray


This will show all icons for current user:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer" /v EnableAutoTray /t REG_DWORD /d 0 /f

This will hide all icons for current user:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer" /v EnableAutoTray /t REG_DWORD /d 1 /f

To restore default settings use:
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer" /v EnableAutoTray /f

This will show all icons for all new users on local machine:
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer" /v EnableAutoTray /t REG_DWORD /d 0 /f

The recommended settings can be to delete settings in current user and take global setting from local machine:
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer" /v EnableAutoTray /f
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer" /v EnableAutoTray /t REG_DWORD /d 0 /f

Flexible silent JRE installer

Copy all needed JRE6 and JRE7 offline installers in directory and run the code
@echo off
for /f "delims=" %%f in ('dir /b "%~dp0jre-6u*x64.exe"') DO (
echo %%f
start /w "" "%~dp0\%%f" /s ADDLOCAL=ALL IEXPLORER=1 JAVAUPDATE=0 REBOOT=Suppress
)

for /f "delims=" %%f in ('dir /b "%~dp0jre-6u*i586.exe"') DO (
echo %%f
start /w "" "%~dp0\%%f" /s ADDLOCAL=ALL IEXPLORER=1 JAVAUPDATE=0 REBOOT=Suppress
)

for /f "delims=" %%f in ('dir /b "%~dp0jre-7u*x64.exe"') DO (
echo %%f
start /w "" "%~dp0\%%f" /s ADDLOCAL=ALL IEXPLORER=1 JAVAUPDATE=0 REBOOT=Suppress
)

for /f "delims=" %%f in ('dir /b "%~dp0jre-7u*i586.exe"') DO (
echo %%f
start /w "" "%~dp0\%%f" /s ADDLOCAL=ALL IEXPLORER=1 JAVAUPDATE=0 REBOOT=Suppress
)

msiexec /x {4A03706F-666A-4037-7777-5F2748764D10} /qn

Related:
https://www.java.com/en/download/help/silent_install.xml

Silent uninstall JRE and all Java products

This will search all "Java" names in registry in uninstall hive.
If the "Java" name were found then uninstall the product.
Basically it is designed to uninstall all Java Runtime Environment's.
@echo off
setlocal EnableDelayedExpansion
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set n=DisplayName
set q=%sw%\%u%

for /f "tokens=7 delims=\" %%a in ('reg query "%q%"') do (
reg query "%q%\%%a" /v %n% > nul 2>&1
if !errorlevel!==0 (
reg query "%q%\%%a" /v %n% | find "Java" > nul 2>&1
if !errorlevel!==0 (
echo Uninstalling..
reg query "%q%\%%a" /v %n% | find "Java"
msiexec /x %%a /qn
echo.
)
)
)

set q=%sw%\Wow6432Node\%u%
if not "%ProgramFiles(x86)%"=="" (
for /f "tokens=8 delims=\" %%a in ('reg query "%q%"') do (
reg query "%q%\%%a" /v %n% > nul 2>&1
if !errorlevel!==0 (
reg query "%q%\%%a" /v %n% | find "Java" > nul 2>&1
if !errorlevel!==0 (
echo Uninstalling..
reg query "%q%\%%a" /v %n% | find "Java"
msiexec /x %%a /qn
echo.
)
)
)
)
endlocal

FirstLogonCommands, RunOnce, autounattend.xml, Windows 7

This is the second edition of "Mastering Windows 7 zero touch installation".
Read fist one at
Mastering Windows 7 zero touch installation.

For faster productivity I use Universal-USB-Installer from
http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/
to create a flexible USB media.

This second edition will introduce how to install Windows 7 in unattended mode together with additional applications like .NET 4, Word, Excel and PowerPoint Viewer.
Also, this will install service packs for WordViewer, ExcelViewer and PowerPointViwer.

Let's begin.

For this example I use Windows 7 SP1 x64 iso file.
Download X17-59186.iso
ed15956fe33c13642a6d2cb2c7aa9749
0bcfc54019ea175b1ee51f6d2b207a3d14dd2b58

Open Universal-USB-Installer-1.9.5.2.exe to create Windows 7 USB installation media.

Open USB root drive and go to sources

Create a sub-folders $OEM$\$$\Setup\Scripts

Go to scripts directory and create FirstRun.cmd that contains:
for %%i in (b c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist %%i:\FirstRun\FirstRun.bat %%i:\FirstRun\FirstRun.bat
)

Go to USB root and create Folder FirstRun

Create bat file FirstRun.bat that contains your first run command for example:
"%~dp0dotNetFx40_Full_x86_x64.exe" /q /norestart
"%~dp0wordview_en-us.exe" /quiet /norestart
"%~dp0WordViewer2003SP3-KB934736-FullFile-ENU.exe" /Q
"%~dp0PowerPointViewer.exe" /quiet /norestart
"%~dp0ppviewersp2010-kb2687456-fullfile-x86-en-us.exe" /quiet /norestart
"%~dp0ExcelViewer.exe" /quiet /norestart
"%~dp0excelviewer2007sp3-kb2526302-fullfile-en-us.exe" /quiet /norestart
"%~dp0FileFormatConverters.exe" /quiet /norestart
"%~dp0compatibilitypacksp3-kb2526297-fullfile-en-us.exe" /quiet /norestart

Go to USB root and make a autounattend.xml file.
This autounattend.xml destroy all hdd data without prompting!
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="windowsPE">
        
 <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SetupUILanguage>
                <UILanguage>en-US</UILanguage>
            </SetupUILanguage>
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
        </component>
  
 <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SetupUILanguage>
                <UILanguage>en-US</UILanguage>
            </SetupUILanguage>
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
        </component>
  
        <component name="Microsoft-Windows-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <DiskConfiguration>
                <Disk wcm:action="add">
                    <CreatePartitions>
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Type>Primary</Type>
                            <Extend>true</Extend>
                        </CreatePartition>
                    </CreatePartitions>
                    <ModifyPartitions>
                        <ModifyPartition wcm:action="add">
                            <Extend>false</Extend>
                            <Format>NTFS</Format>
                            <Letter>C</Letter>
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                            <Label>System</Label>
                        </ModifyPartition>
                    </ModifyPartitions>
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>
                </Disk>
                <WillShowUI>OnError</WillShowUI>
            </DiskConfiguration>
            <ImageInstall>
                <OSImage>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>1</PartitionID>
                    </InstallTo>
                    <WillShowUI>OnError</WillShowUI>
                    <InstallFrom>
                        <MetaData wcm:action="add">
                            <Key>/IMAGE/NAME</Key>
                            <Value>Windows 7 PROFESSIONAL</Value>
                        </MetaData>
                    </InstallFrom>
                </OSImage>
            </ImageInstall>
            <UserData>
                <AcceptEula>true</AcceptEula>
                <FullName></FullName>
                <Organization></Organization>
                <ProductKey>
                    <WillShowUI>OnError</WillShowUI>
                    <Key>HYF8J-CVRMY-CM74G-RPHKF-PW487</Key>
                </ProductKey>
            </UserData>
        </component>
  
 <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <DiskConfiguration>
                <Disk wcm:action="add">
                    <CreatePartitions>
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Type>Primary</Type>
                            <Extend>true</Extend>
                        </CreatePartition>
                    </CreatePartitions>
                    <ModifyPartitions>
                        <ModifyPartition wcm:action="add">
                            <Extend>false</Extend>
                            <Format>NTFS</Format>
                            <Letter>C</Letter>
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                            <Label>System</Label>
                        </ModifyPartition>
                    </ModifyPartitions>
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>
                </Disk>
                <WillShowUI>OnError</WillShowUI>
            </DiskConfiguration>
            <ImageInstall>
                <OSImage>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>1</PartitionID>
                    </InstallTo>
                    <WillShowUI>OnError</WillShowUI>
                    <InstallFrom>
                        <MetaData wcm:action="add">
                            <Key>/IMAGE/NAME</Key>
                            <Value>Windows 7 PROFESSIONAL</Value>
                        </MetaData>
                    </InstallFrom>
                </OSImage>
            </ImageInstall>
            <UserData>
                <AcceptEula>true</AcceptEula>
                <FullName></FullName>
                <Organization></Organization>
                <ProductKey>
                    <WillShowUI>OnError</WillShowUI>
                    <Key>HYF8J-CVRMY-CM74G-RPHKF-PW487</Key>
                </ProductKey>
            </UserData>
        </component>  
  
    </settings>
 
    <settings pass="specialize">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <RegisteredOrganization></RegisteredOrganization>
            <TimeZone>Pacific Standard Time</TimeZone>
            <RegisteredOwner></RegisteredOwner>
            <AutoLogon>
                <Password>
                    <Value></Value>
                    <PlainText>true</PlainText>
                </Password>
                <Username>administrator</Username>
                <LogonCount>3</LogonCount>
                <Enabled>true</Enabled>
            </AutoLogon>
            <ProductKey>HYF8J-CVRMY-CM74G-RPHKF-PW487</ProductKey>
            <ComputerName />
        </component>
  
 <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <RegisteredOrganization></RegisteredOrganization>
            <TimeZone>Pacific Standard Time</TimeZone>
            <RegisteredOwner></RegisteredOwner>
            <AutoLogon>
                <Password>
                    <Value></Value>
                    <PlainText>true</PlainText>
                </Password>
                <Username>administrator</Username>
                <LogonCount>3</LogonCount>
                <Enabled>true</Enabled>
            </AutoLogon>
            <ProductKey>HYF8J-CVRMY-CM74G-RPHKF-PW487</ProductKey>
            <ComputerName />
        </component>
  
    </settings>
 
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <OOBE>
                <ProtectYourPC>1</ProtectYourPC>
                <NetworkLocation>Work</NetworkLocation>
            </OOBE>
            <UserAccounts>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Password>
                            <Value></Value>
                            <PlainText>true</PlainText>
                        </Password>
                        <Name>administrator</Name>
                        <Group>Administrators</Group>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <AutoLogon>
                <Enabled>true</Enabled>
                <Username>Administrator</Username>
                <LogonCount>3</LogonCount>
            </AutoLogon>
            <RegisteredOrganization></RegisteredOrganization>
            <RegisteredOwner></RegisteredOwner>
   <FirstLogonCommands>
            <SynchronousCommand wcm:action="add">
            <Order>1</Order>
            <Description>Run FirstRun.cmd</Description>
            <CommandLine>%WINDIR%\Setup\Scripts\FirstRun.cmd</CommandLine>
            </SynchronousCommand>
   </FirstLogonCommands>
        </component>
  
 <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <OOBE>
                <ProtectYourPC>1</ProtectYourPC>
                <NetworkLocation>Work</NetworkLocation>
            </OOBE>
            <UserAccounts>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Password>
                            <Value></Value>
                            <PlainText>true</PlainText>
                        </Password>
                        <Name>administrator</Name>
                        <Group>Administrators</Group>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <AutoLogon>
                <Enabled>true</Enabled>
                <Username>Administrator</Username>
                <LogonCount>3</LogonCount>
            </AutoLogon>
            <RegisteredOrganization></RegisteredOrganization>
            <RegisteredOwner></RegisteredOwner>
   <FirstLogonCommands>
            <SynchronousCommand wcm:action="add">
            <Order>1</Order>
            <Description>Run FirstRun.cmd</Description>
            <CommandLine>%WINDIR%\Setup\Scripts\FirstRun.cmd</CommandLine>
            </SynchronousCommand>
   </FirstLogonCommands>
        </component>  
  
    </settings>
</unattend>
That's it :)

Related files:
http://download.microsoft.com/download/6/a/6/6a689355-b155-4fa7-ad8a-dfe150fe7ac6/wordview_en-us.exe
http://download.microsoft.com/download/2/e/5/2e5b8726-017f-4b2a-9f71-de6dba53025a/WordViewer2003SP3-KB934736-FullFile-ENU.exe
http://download.microsoft.com/download/E/6/7/E675FFFC-2A6D-4AB0-B3EB-27C9F8C8F696/PowerPointViewer.exe
http://download.microsoft.com/download/B/4/A/B4AAC00B-E1D8-4DEB-AF7A-844BF59E464A/ppviewersp2010-kb2687456-fullfile-x86-en-us.exe
http://download.microsoft.com/download/e/a/9/ea913c8b-51a7-41b7-8697-9f0d0a7274aa/ExcelViewer.exe
http://download.microsoft.com/download/7/1/F/71F3318A-3D88-447C-8AFB-9C3DDEEEB3FE/excelviewer2007sp3-kb2526302-fullfile-en-us.exe
http://download.microsoft.com/download/9/2/2/9222D67F-7630-4F49-BD26-476B51517FC1/FileFormatConverters.exe
http://download.microsoft.com/download/D/2/9/D2906267-82B7-4F8C-B1D8-B24C461A5653/compatibilitypacksp3-kb2526297-fullfile-en-us.exe
http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe

Read next:

Slipstream Internet Explorer 11 into Windows 7 SP1 source

sed case insensitive, windows

Use I in substitute mode.

This is insensitive mode. Substitute all ".iso" with nothing
sed.exe s/.iso//gI
This is sensitive mode
sed.exe s/.iso//g
g - stands for global. You can use it without this switch to replace only first condition.

Thursday, April 11, 2013

Compress all iso's in directory to 7z's

This batch will compress all iso's in directory
@echo off
set path=%path%;%~dp0
set l=%~dp0list.log
if exist "%l%" del "%l%"
dir /b "%~dp0*.iso" | sed s/.iso//gI; >> "%l%"
for /f "tokens=*" %%a in ('type "%l%"') do (
if exist "%%a.7z" del "%%a.7z"
7z a -t7z -mx9 "%%a.7z" "%%a.iso"
)
http://gnu.catonrug.net/7z.exe
http://gnu.catonrug.net/7z.dll
http://gnu.catonrug.net/libiconv2.dll
http://gnu.catonrug.net/libintl3.dll
http://gnu.catonrug.net/regex2.dll
http://gnu.catonrug.net/sed.exe

autoit computername

Use & @computername & for computername insert in text
MsgBox(0, "Error", "Your computername is " & @computername & ".")

Or just @computername for variable
$cn=@computername
MsgBox(0, "Error", "Your computername is " & $cn & ".")

autoit write file

Basic:
Local $file = FileOpen("\\log_server\log1\test.log", 1)

FileWrite($file, "this is text. CRLF means [press enter]" & @CRLF)
FileClose($file)

This is advanced:
Local $file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, "Line1")
FileWrite($file, "Still Line1" & @CRLF)
FileWrite($file, "Line2")

FileClose($file)

autoit if exist directory

$f1="C:\Users\user1"
$f2="C:\documents and settings\user1"
If (FileExists($f1) or FileExists($f2)) Then
   MsgBox(4096, $f1, "Exists")
Else
   RunAsWait("user1", "domain-com", "sdfJUFE6e3!dfs", 1, "","")
EndIf

The point of this program is to cache user profile for future use if computer has no network connection.

Wednesday, April 10, 2013

cdg and mp3 together into one zip file

This will compress cdg and mp3 file together in one zip file.

To run the code you need to save
http://gnu.catonrug.net/7z.exe
http://gnu.catonrug.net/7z.dll
http://gnu.catonrug.net/libiconv2.dll
http://gnu.catonrug.net/libintl3.dll
http://gnu.catonrug.net/regex2.dll
http://gnu.catonrug.net/sed.exe
@echo off
set l=%~dp0list.log
set s=%~dp0sed.exe
set z=%~dp07z.exe
if exist "%l%" del "%l%"

dir /b "%~dp0*.cdg" | "%s%" s/.cdg//gI; >> "%l%"

for /f "tokens=*" %%a in ('type "%l%"') do (
if exist "%%a.zip" del "%%a.zip"
"%z%" a -tzip -mx9 "%%a.zip" "%%a.cdg" "%%a.mp3"
)
To save maximum space you can convert to 7z format
@echo off
set l=%~dp0list.log
set s=%~dp0sed.exe
set z=%~dp07z.exe
if exist "%l%" del "%l%"

dir /b "%~dp0*.cdg" | "%s%" s/.cdg//gI; >> "%l%"

for /f "tokens=*" %%a in ('type "%l%"') do (
if exist "%%a.7z" del "%%a.7z"
"%z%" a -t7z -mx9 "%%a.7z" "%%a.cdg" "%%a.mp3"
)
Convert zip to 7z
@echo off
set l=%~dp0list.log
set s=%~dp0sed.exe
set z=%~dp07z.exe
if exist "%l%" del "%l%"

"%z%" x "%~dp0*.zip"

dir /b "%~dp0*.cdg" | "%s%" s/.cdg//gI; >> "%l%"

for /f "tokens=*" %%a in ('type "%l%"') do (
if exist "%%a.7z" del "%%a.7z"
"%z%" a -t7z -mx9 "%%a.7z" "%%a.cdg" "%%a.mp3"
)

del *.zip
del *.cdg
del *.mp3
To extract 7z use:
@echo off
set z=%~dp07z.exe
"%z%" x "%~dp0*.7z"
Related links:
http://www.dotnetperls.com/7-zip-examples

Tuesday, April 9, 2013

WinRAR native silent install-uninstall

This code is supposed to use in microsoft system center application install.
This will also uninstall 32-bit winrar on 64-bit system and install native version.
silent.native.install.cmd
@echo off
setlocal EnableDelayedExpansion
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set k=WinRAR archiver
if not "%ProgramFiles(x86)%"=="" (
:x64
reg query "%sw%\%u%\%k%" > nul 2>&1
if not !errorlevel!==0 (
reg query "%sw%\Wow6432Node\%u%\%k%" > nul 2>&1
if !errorlevel!==0 (
"%programfiles(x86)%\WinRAR\Uninstall.exe" /S
:CheckUninstallKey
reg query "%sw%\Wow6432Node\%u%\%k%" > nul 2>&1
if !errorlevel!==0 goto CheckUninstallKey
rd "%programfiles(x86)%\WinRAR" /Q /S
)
for /f "tokens=*" %%a in ('dir /b "%~dp0*rar*.exe" ^| find "x64"') do (
echo WinRAR
start /wait "" "%~dp0%%a" /S
)
) else echo WinRAR already exists!
goto exit
)
:x86
reg query "%sw%\%u%\%k%" > nul 2>&1
if not !errorlevel!==0 (
for /f "tokens=*" %%a in ('dir /b "%~dp0*rar*.exe" ^| find /v "x64"') do (
echo WinRAR
start /wait "" "%~dp0%%a" /S
)
) else echo WinRAR already exists!
:exit
endlocal

silent.uninstall.cmd
@echo off
setlocal EnableDelayedExpansion
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set k=WinRAR archiver
if not "%ProgramFiles(x86)%"=="" (
:x64
reg query "%sw%\%u%\%k%" > nul 2>&1
if !errorlevel!==0 (
"%programfiles%\WinRAR\Uninstall.exe" /S
:x64key64
reg query "%sw%\%u%\%k%" > nul 2>&1
if !errorlevel!==0 (
"%~dp0sleep.exe" 1
goto x64key64
)
rd "%programfiles%\WinRAR" /Q /S
)
reg query "%sw%\Wow6432Node\%u%\%k%" > nul 2>&1
if !errorlevel!==0 (
"%programfiles(x86)%\WinRAR\Uninstall.exe" /S
:x64key86
reg query "%sw%\Wow6432Node\%u%\%k%" > nul 2>&1
if !errorlevel!==0 goto x64key86
rd "%programfiles(x86)%\WinRAR" /Q /S
)
goto exit
)
:x86
reg query "%sw%\%u%\%k%" > nul 2>&1
if !errorlevel!==0 (
"%programfiles%\WinRAR\Uninstall.exe" /S
:CheckUninstallKey
reg query "%sw%\%u%\%k%" > nul 2>&1
if !errorlevel!==0 goto CheckUninstallKey
rd "%programfiles%\WinRAR" /Q /S
)
:exit
endlocal

Related files:
http://rarlab.com/rar/wrar540.exe
5d930fa790eed4b6c7dd22262a015723
211a19ca4ec3c7562c9844fe6c42e66a521b8bd4
http://rarlab.com/rar/winrar-x64-540.exe
2191cf9563cfc67efb45b8aff90c649e
22ac3a032f37ce5dabd0673f401f3d0307f21b74

Monday, April 8, 2013

Critical sms_ad_system_discovery_agent

Active Directory System Discovery Agent failed to bind to container.
Possible cause: The AD container specified earlier might be invalid now.
The Domain Controller is inaccessible.
Solution: Please verify that the AD container paths specified are valid.
Confirm accessibility of the site server to the Domain Controller to be queried.

This can happen on System Center Configuration manager 2012.

I found out that i recently make a new organization unit with name blah blah 5\4.
And the \ or , is the reason why this error occurs.

Solution is to rename organization unit in active directory and
remaster again Active Directory System Discovery.

PDFSaM detection rule, System Center 2012

This will detect PDFSaM native version 2.2.2:
SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C91B24F6-1629-11E2-B696-21676188709B}
DisplayVersion

PDFSaM silent uninstall

This is tested on PDFSam version 3.2.5 and it looks in registry for application named "PDFsam Basic"

silent-uninstall.cmd
@echo off
setlocal EnableDelayedExpansion
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
if not "%ProgramFiles(x86)%"=="" (
echo 64-bit windows detected
for /f "tokens=8 delims=\" %%a in ('reg query "%sw%\Wow6432Node\%u%" /s ^| find "\Uninstall\"') do (
reg query "%sw%\Wow6432Node\%u%\%%a" /v DisplayName | find "PDFsam Basic" > nul 2>&1
if !errorlevel!==0 (
echo PDFSaM found under %%a
%systemroot%\system32\msiexec.exe /X %%a /qb
)
)
)
if "%ProgramFiles(x86)%"=="" (
echo 32-bit windows detected
for /f "tokens=7 delims=\" %%a in ('reg query "%sw%\%u%" /s ^| find "\Uninstall\"') do (
reg query "%sw%\%u%\%%a" /v DisplayName | find "PDFsam Basic" > nul 2>&1
if !errorlevel!==0 (
echo PDFSaM found under %%a
%systemroot%\system32\msiexec.exe /X %%a /qb
)
)
)
endlocal