[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

NirCmd routine for U2



I've written a U2 routine that provides an all-purpose XyWrite
command-line interface for NirCmd, Nir Sofer's nifty utility for 32-
bit Windows. The U2 frame (NIR*) and a Help screen (for XYWWWEB.INF)
are encoded below.

The (lengthy) excerpt below from the U2 Help screen will give you a
feel for what you can do with NirCmd and U2 frame NIR. It's really
quite powerful.

To use NIR, four files (NirCmd.exe, NirCmdC.exe, NirCmd.chm, and
MyPID.exe) must be present in your XyWrite program directory. For
your convenience, I've collected these files into a self-extracting
archive, which can be downloaded here:
http://users.datarealm.com/ammaze/xfer/nirfiles.exe

Save NIRFILES.EXE to your XyWrite 4 program directory (the directory
that contains Editor.exe). Then, go to the DOS prompt and command
NIRFILES.EXE to extract the files.

Here is the Help screen excerpt:

- - -
NIR* for XyWrite 4 and 32-bit Windows -- C.L.Distefano rev. 12/11/10
Execute NirCmd commands from CMline or DeFined text

NirCmd includes commands to:

- Launch and kill programs
- Restart, power off, or put Windows into standby mode
- Empty the Recycle bin
- Create shortcuts on the Desktop
- Change the created/modified date and time of a file
- Save text and images to the Clipboard
- Save the screen in a variety of graphics file formats
- Control the monitor, speakers, and CD-ROM drives
- Issue keystrokes
- Translate text into speech
- Edit the Windows Registry
- Execute commands and scripts on remote computers
- And more...

Documentation for NirCmd can be found here:
http://www.nirsoft.net/utils/nircmd2.html#using

NirCmd has two variants, NirCmd.exe and NirCmdC.exe. NirCmdC.exe
sends error messages to the DOS console (as opposed to message
boxes on the Desktop), but is otherwise identical to NirCmd.exe.
NirCmd.chm is the help file.

Using NirCmd Within XyWrite
Frame NIR and its variants enable any NirCmd command or script to
be launched from the XyWrite CMline using the U2 .

Basic usage:
NIR command parameters

Help:
NIR opens the NirCmd help file (NirCmd.chm)
NIR HELP displays online help for NirCmd in your default
browser
NIR HELP command displays online help for the specified
command

Full Usage:
NIR[C][/S|X] command parameters

Framename Options
------------------
NIR:	Use NirCmd.exe to execute command
NIRC:	Use NirCmdC.exe to execute command (write error messages to
console)

Framename Switches
------------------
NIR[C]/S: Launch NirCmd.exe or NirCmdC.exe in a separate process.
Use switch /S if the NirCmd operation will take time to finish, so
that you can continue using XyWrite while the command is executing.
NIR[C]/X: Same as switch /S, but additionally waits for user to
QUIT XyWrite before running command.
Use switch /X with shutdown, reboot, poweroff, and other commands
where you want to quit XyWrite before the command executes.

Examples
--------
Put computer in standby (sleep) mode:
NIR standby

Shutdown (force apps to close) when XyWrite stops running (switch
/X):
NIR/X initshutdown "" 0 force

Reboot when XyWrite stops running (switch /X):
NIR/X initshutdown "" 0 reboot

Shut down and power off when XyWrite stops running (switch /X):
NIR/X exitwin poweroff force

Abort system shutdown:
NIR abortshutdown

Launch Firefox and continue working in XyWrite (switch /S):
NIR/S exec d:\path\firefox.exe

Kill Firefox:
NIR killprocess firefox.exe

Empty the Recycle Bin on drive "C:":
NIR emptybin c:

Read file "my.txt" into the Clipboard:
NIR clipboard readfile ["]d:\path\my.txt["]

Write text in the Clipboard to "myclip.txt":
NIR clipboard writefile ["]d:\path\myclip.txt["]

Save image in Clipboard as a JPEG file:
NIR clipboard saveimage ["]d:\path\my.jpg["]

Clear the Clipboard
NIR clipboard clear

Make the computer imitate Hal in "2001":
NIR speak text "Daisy, Daisy" -10

Speak a long text while continuing to work in XyWrite [switch /S]:
NIR/S speak file d:\mybook\chapter2.txt

Mute/Unmute the speakers (toggle):
NIR mutesysvolmue 2

Mute/Unmute headphones (toggle):
NIR mutesysvolmue 2 headphones

The U2 usage includes the following XyWrite-specific amenities:

1) Commands may be DeFined in text and executed with
NIR[C][/S|X].
2) Multiple commands may be included in a single DeFine, one
command to a line. If DeFined text contains more than one line, it
is executed as a NirCmd script. For information about NirCmd
scripts, command:
  NIR help script
3) 3-byte tildes (FF+37+45h) are accepted in place of 1-byte tildes
on the CMline and in DeFined text. (In XyWrite, 1-byte tildes are
often used as hyphenation aids and, when so used, are not visible
in formatted views and do not print; 3-byte tildes are always
visible and printable.)
4) The tilde can be omitted from variable names (e.g.,
"$clipboard$" instead of "~$clipboard$"). Note, however, that this
must be done consistently within a command or script: do NOT omit
the tilde from one variable name while including it in another
variable name within the same command or script.
- - -

To add frame NIR* to your U2 setup:

Frame NIR* and related documentation are encoded below. In XyWrite,
with U2 installed, command DECODE to decode. Then, 1) paste
the Help screen into XYWWWEB.INF, and 2) DeFine frame NIR* in its
entirety and issue ADD2U2 to add it to your U2 file.

Enjoy!

XPLeNCODE v2.0
b-gin [UNTITLED]
1) Help screen (copy down to "[End of Help Screen]" and paste
 into XYWWWEB.INF):[cr|lf][cr|lf]{nir,nirc,nir/s,nirc/s,nir/x
,nirc/x}[cr|lf][cr|lf]NIR* for XyWrite 4 and 32-bit Windows -
- C.L.Distefano rev. 12/11/10[cr|lf]Execute NirCmd commands f
rom CMline or DeFined text[cr|lf][cr|lf]{<}MDUL{>}Required Ex
ternal Programs (2){<}MDNM{>}[cr|lf]1) MyPID.EXE -- R.J.Holmg
ren's utility to obtain the Process ID (PID) of the running X
yWrite session. Download it (3 KB ZIP file) {<}MDSO{>}{<}LBLi
nk{<}SV50,http://users.datarealm.com/xywwweb/MYPID.ZIP{}[JM_
]2.ViewURL[Q2_]{>}here:[cr|lf]http://users.datarealm.com/xyww
web/MYPID.ZIP{<}MDNM{>}[cr|lf]Unzip MYPID.EXE into the direct
ory that contains Editor.exe.[cr|lf][cr|lf]2) NirCmd -- Nir S
ofer's nifty command-line utility that allows you to control{032}
32-bit Windows and your hardware from the DOS command prompt.
 [cr|lf]Download NIRCMD.ZIP at{<}MDSO{>}[cr|lf]{<}LBLink{<}SV
50,http://www.nirsoft.net/utils/nircmd.html{}[JM_]2.ViewURL[
Q2_]{>}www.nirsoft.net/utils/nircmd.html{<}MDNM{>}[cr|lf]Unzi
p the contents of NIRCMD.ZIP (NirCmd.exe, NirCmdC.exe, NirCmd
{046}chm) into the directory that contains Editor.exe.[cr|lf][cr|
lf]NirCmd includes commands to:[cr|lf][cr|lf]- Launch and kil
l programs[cr|lf]- Restart, power off, or put Windows into st
andby mode[cr|lf]- Empty the Recycle bin[cr|lf]- Create short
cuts on the Desktop[cr|lf]- Change the created/modified date{032}
and time of a file[cr|lf]- Save text and images to the Clipbo
ard[cr|lf]- Save the screen in a variety of graphics file for
mats[cr|lf]- Control the monitor, speakers, and CD-ROM drives
[cr|lf]- Issue keystrokes[cr|lf]- Translate text into speech[
cr|lf]- Edit the Windows Registry[cr|lf]- Execute commands an
d scripts on remote computers[cr|lf]- And more...[cr|lf][cr|l
f]Documentation for NirCmd can be found {<}MDSO{>}{<}LBLink{
<}SV50,http://www.nirsoft.net/utils/nircmd2.html#using{}[JM_
]2.ViewURL[Q2_]{>}here: www.nirsoft.net/utils/nircmd2.html#us
ing{<}
MDNM{>}.[cr|lf][cr|lf]NirCmd has two variants, NirCmd.exe and
 NirCmdC.exe. NirCmdC.exe sends error messages to the DOS con
sole (as opposed to message boxes on the Desktop), but is oth
erwise identical to NirCmd.exe. NirCmd.chm is the help file.[
cr|lf][cr|lf]{<}MDUL{>}Using NirCmd Within XyWrite{<}MDNM{>}[
cr|lf]Frame NIR and its variants enable any NirCmd command or
 script to be launched from the XyWrite CMline using the U2 <
Helpkey>.[cr|lf][cr|lf]Basic usage:[cr|lf]NIR command paramet
ers[cr|lf][cr|lf]Help:[cr|lf]NIR opens the{032}
NirCmd help file (NirCmd.chm)[cr|lf]NIR HELP display
s online help for NirCmd in your default browser[cr|lf]NIR HE
LP command displays online help for the specified co
mmand[cr|lf][cr|lf]Full Usage:[cr|lf]NIR[C][/S|X] command par
ameters[cr|lf][cr|lf]Framename Options[cr|lf]-------
-----------[cr|lf]NIR:{tab}Use NirCmd.exe to execute command[
cr|lf]NIRC:{tab}Use NirCmdC.exe to execute command (write err
or messages to console)[cr|lf][cr|lf]Framename Switches[cr|lf
]------------------[cr|lf]NIR[C]/S: Launch NirCmd.exe or NirC
mdC.exe in a separate process.[cr|lf]Use switch /S if the Nir
Cmd operation will take time to finish, so that you can conti
nue using XyWrite while the command is executing.[cr|lf]NIR[C
]/X: Same as switch /S, but additionally waits for user to QU
IT XyWrite before running command.[cr|lf]Use switch /X with s
hutdown, reboot, poweroff, and other commands where you want{032}
to quit XyWrite before the command executes.[cr|lf][cr|lf]Exa
mples[cr|lf]--------[cr|lf]Put computer in standby (sleep) mo
de:[cr|lf]NIR standby[cr|lf][cr|lf]Shutdown (force a
pps to close) when XyWrite stops running (switch /X):[cr|lf]N
IR/X initshutdown "" 0 force[cr|lf][cr|lf]Reboot whe
n XyWrite stops running (switch /X):[cr|lf]NIR/X initshutdown
 "" 0 reboot[cr|lf][cr|lf]Shut down and power off wh
en XyWrite stops running (switch /X):[cr|lf]NIR/X exitwin pow
eroff force[cr|lf]
[cr|lf]Abort system shutdown:[cr|lf]NIR abortshutdown[c
r|lf][cr|lf]Empty the Recycle Bin on drive "C:":[cr|lf]NIR em
ptybin c:[cr|lf][cr|lf]Read file "my.txt" into the C
lipboard:[cr|lf]NIR clipboard readfile ["]d:\path\my.txt["][cr|lf][cr|lf]Write text in the Clipboard to "myclip.t
xt":[cr|lf]NIR clipboard writefile ["]d:\path\myclip.txt["][cr|lf][cr|lf]Save image in Clipboard as a JPEG file:[
cr|lf]NIR clipboard saveimage ["]d:\path\my.jpg["][c
r|lf][cr|lf]Clear the Clipboard[cr|lf]NIR clipboard clear[cr|lf][cr|lf]Make the computer imitate Hal in "2001":[c
r|lf]NIR speak text "Daisy, Daisy" -10[cr|lf][cr|lf]
Speak a long text while continuing to work in XyWrite [switch
 /S]:[cr|lf]NIR/S speak file d:\mybook\chapter2.txt[
cr|lf][cr|lf]Mute/Unmute the speakers (toggle):[cr|lf]NIR mut
esysvolmue 2[cr|lf][cr|lf]Mute/Unmute headphones (to
ggle):[cr|lf]NIR mutesysvolmue 2 headphones[cr|lf][c
r|lf]The U2 usage includes the following XyWrite-specific ame
nities:[cr|lf]{<}IP0DI,3DI{>}[cr|lf]1) Commands may be DeFine
d in text and executed with NIR[C][/S|X].[cr|lf]2) M
ultiple commands may be included in a single DeFine, one comm
and to a line. If DeFined text contains more than one line, i
t is executed as a NirCmd script. For information about NirCm
d scripts, command:[cr|lf]  NIR help script[cr|lf]3
) 3-byte tildes ("[255+055+069]" = FF+37+45h) are accepted in
 place of 1-byte tildes on the CMline and in DeFined text. (I
n XyWrite, 1-byte tildes are often used as hyphenation aids a
nd, when so used, are not visible in formatted views and do n
ot print; 3-byte tildes are always visible and printable.)[cr
|lf]4) The tilde can be omitted from variable names (e.g., "$
clipboard$" instead of "[255+055+069]
$clipboard$"). Note, however, that this must be done consiste
ntly within a command or script: do NOT omit the tilde from o
ne variable name while including it in another variable name{032}
within the same command or script.[cr|lf][cr|lf][cr|lf]{<}FC{
{062}}[cr|lf]Renumber NIR,NIRC in PACK mode[cr|lf]Default Save/Ge
t Range = 48-55[cr|lf]OPTIONs (2):[cr|lf]FREEZE 50-55[cr|lf]L
EFT$ (1): %[cr|lf]{<}FL{>}[cr|lf]-{tab}-{tab}-{tab}-{tab}-{t
ab}-{tab}-{tab}-{tab}-{tab}-[cr|lf][cr|lf][End of Help Screen
][cr|lf][cr|lf]2) U2 frame: (DeFine in its entirety and issue
 ADD2U2 to add it to your U2 file)[cr|lf][cr|lf]{{;5
nir*}} Execute NirCmd commands and scripts on the CMline or f
rom DeFined text [CLD rev.12/11/10][cr|lf]{002}{<}SX48,@upr({
<}VA$FR{>}){>}{<}IF{<}VA|50{>}<0{>}{<}SV50,{>}{<}EI{>}{<}IF{<
}VA|50{>}<1&{<}VA$DF{>}>0{>}[DZ_]{<}SV50{>}{<}EI{>}{<}SU51,{<
}LBa{>}{<}IF{<}IS50{>}{240}{<}IS52{>}{>}{<}SV53,{>}{<}XS50,52
,54,,53{>}{<}SX50,{<}IS54{>}+{<}IS55{>}+{<}IS53{>}{>}{<}GLa{>
}{<}EI{>}{>}{<}SV52,[255+055+069]{>}{<}SV55,~{>}{<}GT51{>}{<}
IF"~"{238}{<}IS50{>}<0&{<}IS50{>}{240}" $"!{<}IS50{>}{240}"""
$"""{>}{<}SV52, ${>}{<}SV55, ~${>}{<}GT51{>}{<}SV52,"${>}{<}S
V55,"~${>}{<}GT51{>}{<}EI{>}{<}SX49,{<}IS50{>}{>}{<}SX50,{<}V
A$ED{>}{>}[JM_]2.GetPath[Q2_]{<}IF{<}IS48{>}{240}"/X"{>}{<}SX
51,{<}IS50{>}+"\MyPID."{>}{<}SV52,{>}[BX_]dos/nv/x/z /c {<}PV
51{>}exe[Q2_]{<}SX52,"{<}VA="+{<}IS51{>}+"DAT,MyPID={>}"{>}{<
}SX52,{<}PV52{>}{>}{<}EI{>}{<}IF{<}VA|49{>}>0{>}{<}IF{<}IS49{
{062}}{240}"[cr|lf]"{>}{<}SX51,{<}IS50{>}+"\nircmd.ncl"{>}[BX_]sa
 %49,{<}PV51{>}[Q2_][BX_]wt[Q2_]{<}SX49,"script "+{<}IS51{>}{
{062}}{<}EI{>}[BX_]dos/nv/x/z /c {<}IF{<}IS48{>}{240}"/"{>}cmd.ex
e /c start {<}EI{>}{<}PV50{>}\nircmd{<}IF{<}IS48{>}{240}"C"{>
}c{<}EI{>}.exe {<}IF{<}IS48{>}{240}
"/X"{>}{<}SX49,"waitprocess /"+{<}IS52{>}+" "+{<}IS49{>}{>}{<
}EI{>}{<}PV49{>}[Q2_]{<}EX{>}{<}EI{>}[BX_]dos/nv/x/z /c cmd.e
xe /c start {<}PV50{>}\nircmd.chm[Q2_]{002}[cr|lf][cr|lf]
-nd
XPLeNCODE

--
Carl Distefano
cld@xxxxxxxx