Real'S Howto PDF Version
Real'S Howto PDF Version
Table of Contents
Real's HowTo PDF version (november 2015)..................................................................................................1
i
Real's HowTo PDF version (november 2015).
This is the PDF version of the Real's HowTo Web site ( http://www.rgagnon.com/howto.html ). For
up-to-date content, please refer to the Web site. There are 4 files : Real's Java , Real's Javascript, Real's
Powerbuilder and Real's VBS and Misc Prog HowTo. Please don't make PDF versions available on the
internet (it's ok in intranet). From the PDF, you can't run the examples and the links to other How-to's are not
working.
If you feel that effort has been useful to you, perhaps you will consider giving something back? You can make
a donation through PayPal at https://www.paypal.com , make you donation to [email protected]
Contributions via PayPal are accepted in any amount using a credit card or checking account.
DISCLAIMER
Word2003
Open a new document in word and type without a space
=rand(10,1)
and press [ENTER] and Word will generate 10 paragraphs with one sentence in each one.
The first parameter is for how many paragraphs you want and the second parameter controls the length of a
paragraph.
With Word 2007, the rand function picks random text from the Word help instead. The previous behaviour is
still available with the rand.old().
Starting with Word 2007, a new function is available to generate Lorem Ipsum text filler. The function is
=lorem(paragraphs,sentences)
for example
=lorem(2,5)
generates
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet
commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est.
At the beginning of a line, type 3 special characters and a seperator will be inserted. Depending on the
characters typed, the style of the seperator will change.
Starting with the Windows Vista operating system release, the Windows Help program will not ship as a
component of the Windows operating system. Also, third-party programs that include .hlp files are prohibited
from redistributing the Windows Help program together with their products.
http://support.microsoft.com/?kbid=917607
Users who want to view 32-bit .hlp files must download the program from the Microsoft Download Center,
and then install it on their computers.
In this example, a file with the extension .xox will be defined and associated with a java program (display the
first 10 lines of selected .xox file).
First the java program to be associated with the .xox file type.
import java.io.*;
With Windows, two commands are used to define a file association, assoc and ftype. You need to execute
these commands from an account with Administrator privilege.
The assoc command sets up an association between a file name extension and a file type.
>assoc .xox=Xoxfile
.xox=Xoxfile
Then we specify which program is used to handle the Xoxfile type of file.
The ftype command sets up an association between a file type name, and a string to be used to execute it.
In this example, we specify the Java JVM to be used, the classpath to load the Head.class plus the parameter
(the selected .xox file).
Now, if you double-click on a file with .xox extension, a Dos shell is opened, the Head class is launched with
the clicked filename as a parameter and the first 10 line are displayed.
To make the file association works from a command line, you define the environment variable PATHEXT to
include the .xox extension.
>set pathext=.xox;%pathext%
PATHEXT=.XOX;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
then you will be able, from a Dos shell, to type only the name of .xox file and the associated program will be
launched with that file as a parameter.
explorer /select,c:\windows\win.ini
Simple explorer with the file selected plus the treeview expanded.
scrnsave.scr /s
or
start scrnsave.scr /s
Microsoft Technet
Example:
[InternetShortcut]
URL=http://www.google.com
IconFile=http://www.google.com/favicon.ico
IconIndex=0
You can create it with a regular text editor, just make sure that you give a filename with a .URL extension.
Shortcut to a program locally installed can be created with a VBScript, see this HowTo.
output :
Add a DWORD value with the name "Disabled" and give it the value "1"
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IEDevTools
"Disabled" = 1
WMIC is a powerful Windows utility. You can use to know if a particular process is running or not.
This example detects if a Tomcat instance (can be anything, ex: Apache or Excel) is running from a batch file.
@echo off
wmic process list brief | find /i "tomcat.exe"
set result=%ERRORLEVEL%
if "%result%"=="1" echo "not running"
if "%result%"=="0" echo "running"
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
try {
ProcessBuilder builder = new ProcessBuilder(command);
Process process = builder.start();
is = process.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
String line;
processName = processName.toUpperCase();
while ((line = br.readLine()) != null) {
if (line.toUpperCase().indexOf(processName) > -1) return true;
}
return false;
}
finally {
if (br != null) br.close();
if (isr != null) isr.close();
if (is != null) is.close();
}
}
Detect if running in VM
Current version of this HowTo :
http://www.rgagnon.com/gp/../gp/windows-detect-if-running-in-a-VM.html
Using WMIC.
@echo off
wmic bios list full | find /i "vmware"
set result=%ERRORLEVEL%
if "%result%"=="1" echo "not running in a VM"
if "%result%"=="0" echo "running in a VM"
Skype
When you install the Skype client, a new protocol is created : skype:
The syntax is
skype:[?[add|call|chat|sendfile|userinfo]]
Microsoft Communicator
ex.
Outlook feed
To add a RSS feed to Outlook is not the most easy task. The protocol outlookfeed: can make the process
a little bit easier.
REGEDIT is usually known as a GUI tool to search or edit the Windows registry but we can use it in batch
file too.
REGEDIT.EXE /S importfile.REG
You can use notepad or wordpad to write registry files, you save them with a .reg extension.
REGEDIT4
To create a key
[HKEY_CURRENT_USER\Software\RealHowto]
To create a value
[HKEY_CURRENT_USER\Software\RealHowto]
"MyValue"="howto"
To remove a key
[-HKEY_CURRENT_USER\Software\RealHowto]
To remove a value
[HKEY_CURRENT_USER\Software\RealHowto]
"ValueToBeRemoved"=-
By default, a value is a string. To specify a dword simply use the prefix dword :
[HKEY_CURRENT_USER\Software\RealHowto]
"MyValue"=dword:000001
If a semicolon is in front of any line then it will be ignored, it's the way to comment a REG file.
[HKEY_CURRENT_USER\Software\RealHowto]
; add a value
"MyValue2"=dword:00000001
; delete a value
"MyValue1"=-
In the following examples, we iterate a list of files and use the idiom ~[idiom] to extract certain part of a
given filename.
%~$PATH:i searches the directories listed in the PATH environment variable and expands %I to the fully
qualified name of the first one found. If the environment variable name is not defined or the file is not found
by the search, then this modifier expands to the empty string.
To remove quotes
set BAT_HOME=%~p0
echo %BAT_HOME%
cd %BAT_HOME%
set BAT_DRIVE=%~d0
echo %BAT_DRIVE%
set BAT_PATH=%~s0
echo %BAT_PATH%
The script name only (as called with or without the extension): %0
set BAT_NAME=%0
echo %BAT_NAME%
Each argument passed to BAT (or CMD) file is accessed with %1, %2, ...
Or use %1 every time and when the processing of the current argument is done then use the command shift to
switch the next argument into %1. The following script accepts a list of files and type each one of them on the
standard output:
[view.bat]
@echo off
if "%1" == "" goto error
rem - process each of the named files
:again
rem if %1 is blank, we are finished
if "%1" == "" goto end
echo.
echo Processing file %1...
type %1
rem - shift the arguments and examine %1 again
shift
goto again
:error
echo missing argument!
echo usage view file1.txt view2.txt ...
:end
echo.
echo Done.
With the current date but without the separator "-" (ex. 20081108.dat)
To use the current time we must remove the separator ":" because it's not permitted in a filename. (ex.
20081108220221). Since %time% return also a ",", you can't specified an extension.
set x=%date:-=%%time::,=%.dat
set x=%x:,=%
echo hello > %x%
@echo off
setlocal ENABLEDELAYEDEXPANSION
set today=!date:/=-!
set now=!time::=-!
set millis=!now:*.=!
set now=!now:.%millis%=!
Since Windows use the short format date as defined the regional settings, you can be in trouble if the current
installation sets the short date format to something different than YYYY-MM-DD.
One way to eliminate the risk is to use WMIC to extract the date information and assign the value into our
own environment variable and use to name our log file (ex. log-2011-06-21_17-17-35.txt).
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC ^Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Se
IF %%A GTR 0 (
SET Day=%%A
SET Hour=%%B
SET Min=%%C
SET Month=%%D
SET Sec=%%E
SET Year=%%F
)
)
set now=%year%-%month%-%day%_%hour%-%min%-%sec%
set now=%now%
echo hello world > log-%now%.txt
[howto.txt]
This batch file will read the given file and set the environment variable content with the file content.
[howoto.cmd]
@echo off
SetLocal EnableDelayedExpansion
set content=
for /F "delims=" %%i in (howto.txt) do set content=!content!%%i
echo %content%
EndLocal
> howto.cmd
this is an interesting howto
Since < or > are special characters for the DOS command interpreter, you can't use them directly,
Single file
@echo off
if exist c:\temp\2010.pdf (
echo pdf exists
) else (
echo pdf doesn't exist
)
Using a wildcard
@echo off
if exist c:\temp\*.pdf (
echo pdf exists
) else (
echo pdf doesn't exist
)
Single line
Touch a file
Current version of this HowTo :
http://www.rgagnon.com/gp/../gp/gp-touch-a-file.html
Windows doesn't perform very well with a folder containing several thousands of files, especially on a
network.
A quick way to delete a large amount of files is to open a DOS Shell and type :
to delete all the files in foldername. To remove the empty directory structure, type
To delete from the Windows Explorer, use [shift] + [del] to delete without using the Recycle Bin.
Windows Explorer doesn't perform very well with a folder containing several thousands of files, especially on
a network.
A quick way to get the number of files is to open a DOS Shell and type :
In this HowTo, we saw how to toggle the CAPS state using the Word.appplication object from vbscript. Since
the required scripting is simple, it's easy to integrate it in a batch file.
set BAT_HOME=%~dp0
echo %BAT_HOME%
cd %BAT_HOME%
echo Set objShell = CreateObject("WScript.Shell") > temp.vbs
echo Set objWord = CreateObject( "Word.Application" ) >> temp.vbs
echo if objWord.CapsLock ^<^> 0 then >> temp.vbs
echo objShell.SendKeys "{capslock}" >> temp.vbs
echo end if >> temp.vbs
echo objWord.Quit >> temp.vbs
cscript //nologo temp.vbs
del temp.vbs
echo ... do your thing in the batch file
wrapper.java.classpath.1=../lib/activation.jar
wrapper.java.classpath.2=../lib/commons-digester-rss.jar
wrapper.java.classpath.3=../lib/DirWatch.jar
wrapper.java.classpath.4=../lib/JavaCom.jar
wrapper.java.classpath.5=../lib/mail.jar
wrapper.java.classpath.6=../lib/mydb.jar
wrapper.java.classpath.7=../lib/MyJar.jar
The code :
@echo off
setlocal enabledelayedexpansion
set /A Counter=1
for %%f in (*.jar) do (
echo wrapper.java.classpath.!Counter!=../lib/%%f
set /A Counter+=1
)
explorer.exe shell:Libraries
explorer.exe shell:MusicLibrary
explorer.exe shell:VideosLibrary
explorer.exe shell:PicturesLibrary
From a CMD, we launch a one-liner PowerShell script, capture its output to initialize an environment variable
and we create a textfile on the desktop.
@echo off
SETLOCAL
FOR /F "usebackq" %%f IN (`PowerShell -NoProfile -Command "Write-Host([Environment]::GetFolderP
SET "DESKTOP_FOLDER=%%f"
)
echo Hello World > %DESKTOP_FOLDER%\realhowto.txt
@ECHO %DESKTOP_FOLDER%
The goal is to display a popup, the calling batch file must stop and wait the popup closing.
Using powershell
Using MHTA
Regular CMD
Using JScript
If you need more options, an external utility like WGET for Windows is a good choice.
This document from Adobe describes parameters that allow you to open a PDF file using a URL or command
that specifies both the file to be opened plus actions to be performed once the file is opened.
PDF
Put this CMD into the root of your Ghostscript installation.
[ps2pdf.cmd]
rem
rem Convert a Postscript to a PDF 1.4
rem
rem Usage: ps2pdf.cmd input.ps [output.pdf]
rem
@echo off
rem ___________________________SETUP
set GS_HOME=%~dp0
set GSC="%GS_HOME%bin\gsc.exe"
set fileinput=%1
set cmdfile="%GS_HOME%_%~n1.rsp"
if %2/==/ (set fileoutput="%~dp1%~n1.pdf") else (set fileoutput=%2)
rem ___________________________CONVERT
echo -q -dSAFER -dNOPAUSE -dBATCH > %cmdfile%
echo -sDEVICE#pdfwrite -dCompatibilityLevel#1.4 >> %cmdfile%
echo -sOutputFile#%fileoutput% -f %fileinput% >> %cmdfile%
%GSC% @%cmdfile%
rem ___________________________CLEANUP
if exist %cmdfile% erase %cmdfile%
TIFF
Put this CMD into the root of your Ghostscript installation.
[ps2tif.cmd]
rem
rem Convert a Postscript to a TIFF(s) single-page
rem
rem Usage: ps2tif.cmd input.ps [output.tiff]
rem
rem ___________________________SETUP
set GS_HOME=%~dp0
set GSC="%GS_HOME%bin\gsc.exe"
set fileinput=%1
set cmdfile="%GS_HOME%_%~n1.rsp"
if %2/==/ (set fileoutput="%~dp1%~n1%%d.tiff") else (set fileoutput=%2)
rem ___________________________CONVERT
echo -q -dSAFER -dNOPAUSE -dBATCH > %cmdfile%
echo -sDEVICE#tifflzw -r600 -dTextAlphaBits=4 >> %cmdfile%
echo -dGraphicsAlphaBits=4 >> %cmdfile%
echo -sOutputFile#%fileoutput% -f %fileinput% >> %cmdfile%
%GSC% @%cmdfile%
rem ___________________________CLEANUP
if exist %cmdfile% erase %cmdfile%
Using Ghostscript.
The resulting TIF is a little bit bigger than the original PDF. You play with the "-r" (resolution) to achieve a
better look while keeping the size reasonable!
The above command line will produce a single tiff with multiple pages.
Note : In a Windows command file, you need to double the % , -sOutputFile=test-%03d.tif should be
-sOutputFile=test-%%03d.tif.
To merge all the PDF's in a directory, you need two BAT files : [merge.bat]
@echo off
[merge2.bat]
@echo off
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=merged2.pdf -dBATCH merged.pdf %1
del merged.pdf
ren merged2.pdf merged.pdf
Ghostscript
but the presence of the -tag will tell where your address is coming from!
and if you receive SPAM using that address, you can be sure that the SPAMMER got your address by parsing
Usenet postings!
Enter 40 + 2 and Google will answer 42 !. The Google calculator supports hexadecimal notation with the
prefix 0x, try it here
Google s calculator also handles conversions.To convert 0x2e in decimal. Like to convert 1 metre in feet.
Google is multi lingual system, try it in French!
Google as an online dictionary to look up any word. All you have to do is enter the keywords what is in your
query, followed by the word in question. If you want to know what is architecture. Another way is to use the
Google keyword define.
Google has pre-defined facts and you can get them with the right query :
• Quebec population
• John Wayne birthplace
• John Wayne birthday
• John Wayne death
Google can be used to find and display current weather conditions, mostly for American location like Detroit.
You can substitute the city name for a zip code.
If you have an area code and want to know which city it serves, just enter the area code; Google will return
the city in which that area code resides.
Looking for MP3 ? Try a search like ?intitle:index.of? mp3 bob marley . But beware some returned sites or
files can be fake.