WMI on Win98, the end of Batch as we knew it

D

D F

I recently discovered WMI - The Windows Management Instrumentation.

This is a bit tech'y ... but it's all Free Software (well, free if
you've already purchased Windows, and don't mind browsing the MDSN.)
According to M$, "Windows Management Instrumentation (WMI) makes
Windows extremely manageable using a single consistent,
standards-based, extensible and object-orientated interface." (I
always HATED the word 'orientated' ... had to find something to hate
about that :)

Anyway, if you are running Windows 2000 or XP, you already have this
installed. (If you work in a network-heavy workplace, undoubtedly
your IT people ... ummm... the Saavyy ones, anyway... are already into
this big time.)

However, MS has also made a package available that provides this
capability on Win95 and Win98-level machines. (I am currently running
Win98 ... NOT SE, and using WMI with success.)

The page to Read about this capability is:
(the following is ONE line...)

http://www.microsoft.com/downloads/...BA-337B-4E92-8C18-A63847760EA5&displaylang=en

AND, the download link for the WMI Core 1.5 (you only need this if you
have Win95 or Win98) is:

http://download.microsoft.com/download/platformsdk/wmi9x/1.5/W9X/EN-US/wmi9x.exe

(Download is 3029K)

The link (today, anyway) to learn more about this is:

http://msdn.microsoft.com/library/en-us/dnanchor/html/anch_wmi.asp

Windows 95 and 98 users will also want to upgrade their Windows
Scripting Host (WSH)! Again, according to Microsoft: "If you are
currently using Windows 2000 or Windows ME, you have version 2.0 of
WSH installed on your computer system. If you are running Windows 95,
98, or Windows NT 4.0, you have version 1.0. To upgrade to WSH 5.6,
visit the Microsoft Windows Script Technologies Web site at
(http://msdn.microsoft.com/scripting/)."

The WSH 5.6 download for Win95,98 is discussed at:
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

and the Win9X, ME, NT4 download for WSH 5.6 is at:
(Link must be one line...)
http://download.microsoft.com/download/4/c/9/4c9e63f1-617f-4c6d-8faf-c2868f670c1c/scr56en.exe

(Download is 664K)

So, if you get all that installed, then you can really have fun... (It
is easy to install these packages, but you will want to READ a lot of
the material to get started.) Oops, I should mention that you also
need to keep your virus guard up, and not (NO NEVER) just run any old
VBscript you find on the Net.

WMI, using WSH (ala VBScript) has the potential to render all your
Win98 BATCH files obsolete,... the ones that you find yourself setting
up to run from Windows to get some of those system jobs done... The
proof is left to the reader :) (If you don't know what Batch files
are, just remember that I said this was a bit tech'y... and, if you
think Batch files are Tech'y, then stick with the prepackaged
installer-based Windows applications for now.)

For this example, here is a script that shows my Machine and Serial
Number:

---------- whoami.vbs -----------
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.InstancesOf("Win32_SystemEnclosure")
For Each objItem in colItems
strMyHw = objItem.Manufacturer & " s/n " & objItem.SerialNumber
Next
Wscript.Echo strMyHw
---------- end whoami.vbs ---------

From the command prompt (DOS Prompt, with Windows running) you type:

DOS> cscript whoami.vbs

(... Note that cscript.exe is part of the WSH package and must be on
the 'DOS Path')

This shows... "Gateway s/n 0123456789" (...I'm faking this number!)

....for my machine.

To run from Windows (double clicking on the .vbs file) you only need
to associate .vbs with the application 'wscript.exe'... that is, the
command to run from the OPEN action is 'wscript.exe "%1"'

Just a few more examples...

The following script builds a string showing all the running processes
and then displays it:

-------- processes.vbs --------------
On Error Resume Next
strComputer = "."
strConfirm = ""
Set oCIM = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
For each Process in oCIM.ExecQuery("SELECT * FROM Win32_Process",,48)
strConfirm = strConfirm & vbCrLf & Process.Name
Next
WScript.Echo strConfirm
--------- end processes.vbs ----------

Here's a little WMI Script that shows all your installed Codecs and
any version information available...

--------- showcodecs.vbs ------------
On Error Resume Next
strComputer = "."
strCodec=""
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_CodecFile",,48)
For Each objItem in colItems
strCodec=strCodec & vbcrlf & "-- " & objItem.Description & " [" &
objItem.Version & "] (" & objItem.Manufacturer & ") " & objItem.Name
Next
Wscript.Echo strCodec
--------- end showcodecs.vbs ----------

This is pretty lame stuff on the XP OS... Just remember that I am
doing this on a Win98 machine! Well, so much for old DOS batch
files... For Lots and Lots of WSH and WMI help, just search Google
for those words,... and you won't come back for a while.

As the Wizard of Oz once said, "I can't come back! I don't know how
it works."

Dale Fordberg


P.S. More fun WMI tools are here:

Scriptomatic...
(One Line)
http://www.microsoft.com/downloads/...bd-c1c5-41e7-9da8-212c414a7ab0&DisplayLang=en

"Writing WMI Scripts Using the Scriptomatic Utility

This magical utility lets you write WMI scripts even if you don't
know the first thing about WMI. We [MS] recommend you read the
documentation for this utility (accompanied with utility) first before
you continue."

[Hint, DF] - For Win95, 98, you have to EDIT the .HTA file, so that it
starts the (one) DOS window using "command.com" instead of "cmd.exe"
(or use %COMSPEC% instead.... Then this fun little tool will run fine
on Win98 with all the other stuff installed! (Edit the .HTA file and
search for "cmd.exe")

(Download Link - One Line, 101K)
http://download.microsoft.com/download/.NetStandardServer/Utility/1.0/NT5XP/EN-US/scriptomatic.exe


TweakoMatic... (Just released recently)
(One Line)
http://www.microsoft.com/downloads/...1e-6c01-4447-bd7c-c09646d722c8&DisplayLang=en

"The Tweakomatic is a nifty new utility that writes scripts that allow
you to retrieve and/or configure Windows and Internet Explorer
settings. So what, you might ask. Well, think about it. Because these
are WMI scripts, they can be used to configure settings on remote
computers. Need to change something on a remote machine? Then haul out
the Tweakomatic. And think about this: because the Tweakomatic writes
scripts, you could do something like run these scripts as logon or
logoff scripts. In other words, you could quickly, easily, and
automatically configure settings on any or all the computers in your
organization."

(Download Link - One line, 258K)
http://download.microsoft.com/download/d/3/0/d3000559-ec45-40e0-bd36-e4aea5c15299/tweakomatic.EXE


BGInfo (from SysInternals)

http://www.sysinternals.com/ntw2k/freeware/bginfo.shtml

"How many times have you walked up to a system in your office and
needed to click through several diagnostic windows to remind yourself
of important aspects of its configuration, such as its name, IP
address, or operating system version? If you manage multiple computers
you probably need BGInfo. It automatically displays relevant
information about a Windows computer on the desktop's background, such
as the computer name, IP address, service pack version, and more. You
can edit any field as well as the font and background colors, and can
place it in your startup folder so that it runs every boot, or even
configure it to display as the background for the logon screen."
Copyright © 2000-2003 Bryce Cogswell

http://www.sysinternals.com/files/bginfo.zip

[Hints, DF] This one is highly interesting (if not that useful) to
play with on my home computer... But it is very easy to use, and
(here's the hint...) it has a GREAT browse and learn support for WMI
queries built in... You simply define a custom tag that accesses WMI,
and the tool will help you construct queries that show you the results
immediately. This one is just great fun to play with. (After all,
don't you already know that you have a Gateway, with Win98 and 196Meg
Memory, and 1.2Gig Freespace on the hard drive?) (It also annoys my
kids because it keeps writing the systems information into our desktop
backgrounds...) That's another interesting feature of this tool...
Suppose you have a tiled background on your desktop. BGInfo uses
that tile and builds its own background screen with the system report
integrated into the bitmap pattern, then installs that as the
background. All my kids have to do is change the background back to
their original tile, but they don't know that yet :))

Enjoy.

DF
 
A

A.A. Fussy

Thanks- a very useful download
D F said:
I recently discovered WMI - The Windows Management Instrumentation.

This is a bit tech'y ... but it's all Free Software (well, free if
you've already purchased Windows, and don't mind browsing the MDSN.)
According to M$, "Windows Management Instrumentation (WMI) makes
Windows extremely manageable using a single consistent,
standards-based, extensible and object-orientated interface." (I
always HATED the word 'orientated' ... had to find something to hate
about that :)

Anyway, if you are running Windows 2000 or XP, you already have this
installed. (If you work in a network-heavy workplace, undoubtedly
your IT people ... ummm... the Saavyy ones, anyway... are already into
this big time.)

However, MS has also made a package available that provides this
capability on Win95 and Win98-level machines. (I am currently running
Win98 ... NOT SE, and using WMI with success.)

The page to Read about this capability is:
(the following is ONE line...)

http://www.microsoft.com/downloads/details.aspx?FamilyId=98A4C5BA-337B-4E92-
8C18-A63847760EA5&displaylang=en

AND, the download link for the WMI Core 1.5 (you only need this if you
have Win95 or Win98) is:

http://download.microsoft.com/download/platformsdk/wmi9x/1.5/W9X/EN-US/wmi9x
..exe

(Download is 3029K)

The link (today, anyway) to learn more about this is:

http://msdn.microsoft.com/library/en-us/dnanchor/html/anch_wmi.asp

Windows 95 and 98 users will also want to upgrade their Windows
Scripting Host (WSH)! Again, according to Microsoft: "If you are
currently using Windows 2000 or Windows ME, you have version 2.0 of
WSH installed on your computer system. If you are running Windows 95,
98, or Windows NT 4.0, you have version 1.0. To upgrade to WSH 5.6,
visit the Microsoft Windows Script Technologies Web site at
(http://msdn.microsoft.com/scripting/)."

The WSH 5.6 download for Win95,98 is discussed at:
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

and the Win9X, ME, NT4 download for WSH 5.6 is at:
(Link must be one line...)
http://download.microsoft.com/download/4/c/9/4c9e63f1-617f-4c6d-8faf-c2868f6
70c1c/scr56en.exe

(Download is 664K)

So, if you get all that installed, then you can really have fun... (It
is easy to install these packages, but you will want to READ a lot of
the material to get started.) Oops, I should mention that you also
need to keep your virus guard up, and not (NO NEVER) just run any old
VBscript you find on the Net.

WMI, using WSH (ala VBScript) has the potential to render all your
Win98 BATCH files obsolete,... the ones that you find yourself setting
up to run from Windows to get some of those system jobs done... The
proof is left to the reader :) (If you don't know what Batch files
are, just remember that I said this was a bit tech'y... and, if you
think Batch files are Tech'y, then stick with the prepackaged
installer-based Windows applications for now.)

For this example, here is a script that shows my Machine and Serial
Number:

---------- whoami.vbs -----------
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.InstancesOf("Win32_SystemEnclosure")
For Each objItem in colItems
strMyHw = objItem.Manufacturer & " s/n " & objItem.SerialNumber
Next
Wscript.Echo strMyHw
---------- end whoami.vbs ---------

From the command prompt (DOS Prompt, with Windows running) you type:

DOS> cscript whoami.vbs

(... Note that cscript.exe is part of the WSH package and must be on
the 'DOS Path')

This shows... "Gateway s/n 0123456789" (...I'm faking this number!)

...for my machine.

To run from Windows (double clicking on the .vbs file) you only need
to associate .vbs with the application 'wscript.exe'... that is, the
command to run from the OPEN action is 'wscript.exe "%1"'

Just a few more examples...

The following script builds a string showing all the running processes
and then displays it:

-------- processes.vbs --------------
On Error Resume Next
strComputer = "."
strConfirm = ""
Set oCIM = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
For each Process in oCIM.ExecQuery("SELECT * FROM Win32_Process",,48)
strConfirm = strConfirm & vbCrLf & Process.Name
Next
WScript.Echo strConfirm
--------- end processes.vbs ----------

Here's a little WMI Script that shows all your installed Codecs and
any version information available...

--------- showcodecs.vbs ------------
On Error Resume Next
strComputer = "."
strCodec=""
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_CodecFile",,48)
For Each objItem in colItems
strCodec=strCodec & vbcrlf & "-- " & objItem.Description & " [" &
objItem.Version & "] (" & objItem.Manufacturer & ") " & objItem.Name
Next
Wscript.Echo strCodec
--------- end showcodecs.vbs ----------

This is pretty lame stuff on the XP OS... Just remember that I am
doing this on a Win98 machine! Well, so much for old DOS batch
files... For Lots and Lots of WSH and WMI help, just search Google
for those words,... and you won't come back for a while.

As the Wizard of Oz once said, "I can't come back! I don't know how
it works."

Dale Fordberg


P.S. More fun WMI tools are here:

Scriptomatic...
(One Line)
http://www.microsoft.com/downloads/details.aspx?FamilyID=9ef05cbd-c1c5-41e7-
9da8-212c414a7ab0&DisplayLang=en

"Writing WMI Scripts Using the Scriptomatic Utility

This magical utility lets you write WMI scripts even if you don't
know the first thing about WMI. We [MS] recommend you read the
documentation for this utility (accompanied with utility) first before
you continue."

[Hint, DF] - For Win95, 98, you have to EDIT the .HTA file, so that it
starts the (one) DOS window using "command.com" instead of "cmd.exe"
(or use %COMSPEC% instead.... Then this fun little tool will run fine
on Win98 with all the other stuff installed! (Edit the .HTA file and
search for "cmd.exe")

(Download Link - One Line, 101K)
http://download.microsoft.com/download/.NetStandardServer/Utility/1.0/NT5XP/
EN-US/scriptomatic.exe


TweakoMatic... (Just released recently)
(One Line)
http://www.microsoft.com/downloads/details.aspx?FamilyID=bd328d1e-6c01-4447-
bd7c-c09646d722c8&DisplayLang=en

"The Tweakomatic is a nifty new utility that writes scripts that allow
you to retrieve and/or configure Windows and Internet Explorer
settings. So what, you might ask. Well, think about it. Because these
are WMI scripts, they can be used to configure settings on remote
computers. Need to change something on a remote machine? Then haul out
the Tweakomatic. And think about this: because the Tweakomatic writes
scripts, you could do something like run these scripts as logon or
logoff scripts. In other words, you could quickly, easily, and
automatically configure settings on any or all the computers in your
organization."

(Download Link - One line, 258K)
http://download.microsoft.com/download/d/3/0/d3000559-ec45-40e0-bd36-e4aea5c
15299/tweakomatic.EXE


BGInfo (from SysInternals)

http://www.sysinternals.com/ntw2k/freeware/bginfo.shtml

"How many times have you walked up to a system in your office and
needed to click through several diagnostic windows to remind yourself
of important aspects of its configuration, such as its name, IP
address, or operating system version? If you manage multiple computers
you probably need BGInfo. It automatically displays relevant
information about a Windows computer on the desktop's background, such
as the computer name, IP address, service pack version, and more. You
can edit any field as well as the font and background colors, and can
place it in your startup folder so that it runs every boot, or even
configure it to display as the background for the logon screen."
Copyright © 2000-2003 Bryce Cogswell

http://www.sysinternals.com/files/bginfo.zip

[Hints, DF] This one is highly interesting (if not that useful) to
play with on my home computer... But it is very easy to use, and
(here's the hint...) it has a GREAT browse and learn support for WMI
queries built in... You simply define a custom tag that accesses WMI,
and the tool will help you construct queries that show you the results
immediately. This one is just great fun to play with. (After all,
don't you already know that you have a Gateway, with Win98 and 196Meg
Memory, and 1.2Gig Freespace on the hard drive?) (It also annoys my
kids because it keeps writing the systems information into our desktop
backgrounds...) That's another interesting feature of this tool...
Suppose you have a tiled background on your desktop. BGInfo uses
that tile and builds its own background screen with the system report
integrated into the bitmap pattern, then installs that as the
background. All my kids have to do is change the background back to
their original tile, but they don't know that yet :))

Enjoy.

DF
 
B

Boomer

(e-mail address removed) (D F) wrote in
I recently discovered WMI - The Windows Management
Instrumentation.

This is a bit tech'y ... but it's all Free Software (well, free if
you've already purchased Windows, and don't mind browsing the
MDSN.) [snip]

http://www.microsoft.com/downloads/search.aspx?displaylang=en


However, MS has also made a package available that provides this
capability on Win95 and Win98-level machines. (I am currently
running Win98 ... NOT SE, and using WMI with success.)

The page to Read about this capability is:
(the following is ONE line...)

http://www.microsoft.com/downloads/details.aspx?FamilyId=98A4C5BA-3
37B-4E92-8C18-A63847760EA5&displaylang=en
[snip many lines]

Date Published: 2/11/2000

Thanks
 
O

omega

(e-mail address removed) (D F):
I recently discovered WMI - The Windows Management Instrumentation.

This is a bit tech'y ... but it's all Free Software (well, free if
you've already purchased Windows, and don't mind browsing the MDSN.)
[...]

Thank you for the post; I've saved it.

Now, how about for your first project, a custom job just for me? I'll
reward you by pasting an ascii rose or something, if you succeed. ;)

The Internet Explorer Web Accessories Pack includes a script to have
a "View Partial Source" option on the msie context menu. The file that
has that script is named SOURCE.HTM. I've forgot the default location.
I can look specifics up, but am starting by assuming you know what I'm
referring to.

I use this function a lot, in my browsers and programs which use the
MS Browser control, and thus share the msie context menu. What I do not
like is that it's an IE window launched, to display the html that has
been selected. I would prefer to have the output directed instead to
a text editor.

If you learn how the script can be rewritten for that....

--
Karen S.


=========== SOURCE.HTM ==================================

<script language="JavaScript" defer>
<!--
// specific to context menu extensions
var win = external.menuArguments;
// the document object the user right-clicked on
var doc = win.document;
// the text the user selected
var sel = doc.selection;
// an IHTMLElement containing all the html elements in the selection
var rng = sel.createRange();
// the html string composing the range
var szsource = rng.htmlText;
if (szsource.length <= 0) {
szsource = doc.body.outerHTML;
}
// make sure our debugging window is a unique window
var wincounter = 0;

var mywin = window.open("about:blank", "source" + wincounter++,
"toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
while (mywin == null) {
mywin = window.open("about:blank", "source" + wincounter++,
"toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
} // if (mywin == null)

var myDoc = mywin.document;

myDoc.open("text/plain");
myDoc.write(szsource);
myDoc.close();
myDoc.title = "Partial Source for: " + win.location.href;
// -->
 
O

omega

omega said:
(e-mail address removed) (D F):
I recently discovered WMI - The Windows Management Instrumentation.

The Internet Explorer Web Accessories Pack includes a script to have
a "View Partial Source" option on the msie context menu. The file that
has that script is named SOURCE.HTM.
[...]
been selected. I would prefer to have the output directed instead to
a text editor.

Second thoughts already!! When I looked over the source.htm file, I
realized it was not a solid starting point. At least not alone. One would
also want the examples of those scripts which call another program.
I've been saving those as I find them, but will abort going into listing
them as now (short on time).

Yet you might get the general direction in any case. That the msie context
menu, for calling an external program to act on what you've selected, this
seems like it could be a good locale for targeting with custom scripts.

I'm assuming that you can choose what program to call, at will, and hope
that I'm not mistaken on that part. When I ever get around to reading some
of the Script Host documentation, will investigate, to be sure.
 
V

VH

Thanks for reminding me. I was excited when I found out that the
Scriptomatics people btought out a new tool. I downloaded it a couple
of days ago from Betanews but forgot all about it after I got
sidetracked by some other programs downloaded at the same time.

I know I am going to have some fun with this one too.
 
V

VH

Thanks for reminding me. I was excited when I found out that the
Scriptomatics people btought out a new tool. I downloaded it a couple
of days ago from Betanews but forgot all about it after I got
sidetracked by some other programs downloaded at the same time.

I know I am going to have some fun with this one too.
BTW, I meant the Tweakomatic. Forgot to leave the relevant part when
I snipped the original message.

Tried the program last night and it is going to be very useful.
 
O

omega

VH said:
BTW, I meant the Tweakomatic. Forgot to leave the relevant part when
I snipped the original message.

Tried the program last night and it is going to be very useful.

You must meant the program here ->

 
R

Richard Steven Hack

You must meant the program here ->

Maybe this means MCSE's will be able to start to manage as many
machines as UNIX sys admins do, since they've started to learn
scripting. (Heh, heh)
 
K

Klaatu

Those guys in the scripting department at MS are a hoot. Here's another
snippet from the Tweakomatic page
http://www.microsoft.com/technet/treeview/default.asp?
url=/technet/scriptcenter/Tools/twkmatic.asp

Now, to be honest, some of those fears are a bit exaggerated, and the
disclaimer is there largely for legal reasons (remember, this is the day
and age when you can order hot coffee in a restaurant, and then sue the
restaurant when the coffee they give you turns out to be, well, hot). If
you do it correctly, changing the registry is perfectly harmless. At the
same time, however, it’s true that there are certain values in the
registry that should never be changed; in fact, changing them can pretty
much wipe your computer out, once and for all. It’s like working on the
bomb squad: if you snip the right wire, the bomb is defused and
everything is fine. But if you snip the wrong one—Boom! You just created
Microsoft Bob!

LOL
 
L

LateforWork

Klaatu said:
Those guys in the scripting department at MS are a hoot. Here's another
snippet from the Tweakomatic page
http://www.microsoft.com/technet/treeview/default.asp?
url=/technet/scriptcenter/Tools/twkmatic.asp

Now, to be honest, some of those fears are a bit exaggerated, and the
disclaimer is there largely for legal reasons (remember, this is the day
and age when you can order hot coffee in a restaurant, and then sue the
restaurant when the coffee they give you turns out to be, well, hot). If
you do it correctly, changing the registry is perfectly harmless. At the
same time, however, it’s true that there are certain values in the
registry that should never be changed; in fact, changing them can pretty
much wipe your computer out, once and for all. It’s like working on the
bomb squad: if you snip the right wire, the bomb is defused and
everything is fine. But if you snip the wrong one—Boom! You just created
Microsoft Bob!

LOL

Maybe there are reasons for retiring the old batch, but I'd advise doing
all you can to keep it. There's a great deal one can do with batch
files: see here for instance:

http://users.cybercity.dk/~bse26236/batutil/help/INDEX.HTM

Uses to which I put batch:

1. Backup on to CDR/RW any files and have them automatically compressed
with pkzip freeware
2. Enter specific network variables on boot-up
3. Load different programs at boot-up
4. Use encryption that bypasses windows system (no eavesdropping!)

The list is almost endless and it's so easy to use even for the
programming novice.

Let's hear it for batch!

LateforWork/
 
O

omega

Klaatu said:
Those guys in the scripting department at MS are a hoot. Here's another
snippet from the Tweakomatic page
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/Tools/twkmatic.asp

[...]
same time, however, it’s true that there are certain values in the
registry that should never be changed; in fact, changing them can pretty
much wipe your computer out, once and for all. It’s like working on the
bomb squad: if you snip the right wire, the bomb is defused and
everything is fine. But if you snip the wrong one—Boom! You just created
Microsoft Bob!

LOL

Jeeez! They must just be sitting back there, laughing their booties off,
as they compete with who can pound up the most bizarre tales. The bomb
analogy gets the tallest FOS award, but the create Microsoft Bob, that
one gets the novelty/fun prize.
 
D

D F

omega said:
omega <[email protected]>:

[...]
been selected. I would prefer to have the output directed instead to
a text editor.

Second thoughts already!! When I looked over the source.htm file, I
realized it was not a solid starting point. At least not alone. One would
also want the examples of those scripts which call another program.
I've been saving those as I find them, but will abort going into listing
them as now (short on time).

Yet you might get the general direction in any case. That the msie context
menu, for calling an external program to act on what you've selected, this
seems like it could be a good locale for targeting with custom scripts.

I'm assuming that you can choose what program to call, at will, and hope
that I'm not mistaken on that part. When I ever get around to reading some
of the Script Host documentation, will investigate, to be sure.

First (before the longwinded part), you might be interested in this
Freeware:

Internet Explorer Text Archiver

Created by Steve Yandl 6/23/2001

Web Page: http://www.pcnineoneone.com/tweaks/scripts9.html
Download: http://www.pcnineoneone.com/tweaks/ietextarchiver.zip (
7k!)

Install instructions are on the author's Web Page, and (besides) this
is a great learning tool for just the job you outlined above.

...."IE Text Archiver enables you to highlight text on a web page
viewed with Internet Explorer 5 or higher and save the highlighted
text with a simple right-click to a text file in a specified folder on
your local hard drive.
It saves you the steps of having to manually copy the text, open a
text editor, paste the selection, find a place to store it, then save
it, and combines them into a single right-click."

Now, on with the 'long-winded' answer to your proposal...

The script outline you provided in the previous post was very
interesting to me, and (since I am trying to learn more about all
this), I took a stab at the next step, which involves writing the
selection to a file, then opening it in an editor of choice.

So, for starters, new readers should note that the script given in
'Omega's initial post had the headers and few final lines missing, so
I am going to give a complete version here, although you will see that
I just inserted modifications (adding to it) to support writing to a
file.

To install a script like this 'Manually' so that it becomes an entry
in the IE (5, 6) Context Menu (right click)... You have to put a new
entry in the Registry under the IE Key 'MenuExt' telling where the
script file IS. Also, the script file (I think) needs to be a bona
fide .HTM (to be uhumm.... Proper.)

So (new Windows Users) Pick a Place to store the Script File on your
hard drive. (Call that place anything you want, but for this example,
let's pretend you chose C:\SomePlace\SomeWhere, and you save the file
below as ExcerptSource.htm. Now, we are ready... Take up your text
editor and CUT the text out of these messages between the markers, and
save each one as the files you need, then click away...

First, make a REGISTRY restore file to install the key...

(Watch out for lines that get wrapped by the posting software...)
----- Save this as (say) RegisterScript.reg ---------
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt]

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Source
of Selected]
@="C:\\SomePlace\\SomeWhere\\ExcerptSource.htm"
----- end of RegisterScript.reg was the line before this -----

Modify the above file FIRST (right click and edit) to change the PATH
to be your path, and you can change 'Source of Selected' to anything
you want.

Don't need to execute this just, yet... First let's cut and save the
revised Script File (... just a thing I have about making sure that
the file is REAL before pointing to it :-0)

------ Save this as C:\SomePlace\SomeWhere\ExcerptSource.htm ---------
<html>

<head>
</head>

<body>
<script language="JavaScript" defer>
<!--
// specific to context menu extensions
var win = external.menuArguments;
// the document object the user right-clicked on
var doc = win.document;
// the text the user selected
var sel = doc.selection;
// an IHTMLElement containing all the html elements in the selection
var rng = sel.createRange();
// the html string composing the range
var szsource = rng.htmlText;
alert("BrowserSourcePart is Active");
if (szsource.length <= 0) {
szsource = doc.body.outerHTML;
}
// make sure our debugging window is a unique window
var wincounter = 0;

var mywin = window.open("about:blank", "source" + wincounter++,
"toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
while (mywin == null) {
mywin = window.open("about:blank", "source" + wincounter++,
"toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
} // if (mywin == null)
var myDoc = mywin.document;

myDoc.open("text/plain");
myDoc.write(szsource);
myDoc.close();
myDoc.title = "Partial Source for: " + win.location.href;

// Pick one... (Remember to escape \ in JavaScript.... and NOT in VB
:)
var viewerTool = "C:\\Program Files\\NoteTab Light\\NoteTab.exe";
// var viewerTool = "notepad.exe";

// Change this to be a file YOU want...
var myFile = "C:\\SelectedExample.txt";

WriteFileVB(szsource,myFile);
ViewWithTool(viewerTool,myFile);

// -->
</script>

<script language="VBScript"><!--
' Note, you can mix VBScript and JavaScript in the same module...

' Write a local file containing the selected text (complete with HTML
markup).
sub WriteFileVB(passedText,storeFile)

Dim fso, outf ' Objects to support writing the output file.

Set fso = CreateObject("Scripting.FileSystemObject")

' According to the MS Documentation, the OpenTextFile parameters
mean this...
' Opentext(thefiletoopen, Mode: 1-Read 2-Write 8-Append,
CanWeCreateIt)
Set outf=fso.OpenTextFile(storeFile,2,True) ' Open the file, create
if necessary, overwrite.

outf.WriteLine passedText ' Put the whole selection at once.

set outf=nothing ' Release the objects from memory (and close the
file).
set fso=nothing
end sub

' Start a Viewing Tool named by the user, and open a file named by the
user.
sub ViewWithTool(usersViewer,usersFile)

Dim WshShell, oExec ' Objects needed to run system 'Shell'
programs.
Set WshShell = CreateObject("WScript.Shell")

' Note: Provide a complete path to the executable of usersViewer.
' Some tools (like notepad) are covered by a Command in the
registry,
' and don't need a full path. If this cannot find your viewer,
provide a
' complete path. For example, 'notepad.exe' works all by itself,
but you
' may need to Quote something like NoteTab ...
' "C:\Program Files\NoteTab Light\NoteTab.exe"
' We also quote the file name here so that you can have spaces in
it.
' IF the command for the viewer is NOT as simple as
' 'tool.exe file.txt' then you may
' have to alter the command line to produce the right combination of
' parameters...

Set oExec = WshShell.Exec(usersViewer + " """ + usersFile + """")

Set wshShell = nothing
Set oExec = nothing
end sub
//-->
</script>
</body>

</html>
------ end of ExcerptSource.htm was the line before this -------------

Now, as long as you picked the name you really wanted, (you didn't
like C:\SomePlace\SomeWhere\ExcerptSource.htm ??)... AND you have
Edited the Registry restore file (above) so that it points to the SAME
file you just stored, NOW...

Double-Click on the 'RegisterScript.Reg' file, (whatever you called
it) and confirm all the prompts... This simply adds the key to the
registry. (You can do that with RegEdit too.) Read MS literature
about the 'Contexts' sub-key, where you can tell this entry WHEN to
show up, and when to NOT show up. :)

At this point, when you start IE (version 5.0+...) you should be able
to Select some text (highlight)... Then Right-Click, and when you
select 'Source of Selected' TWO things will happen... (which can both
be Fixed...)

A new window will open showing the HTML Source of the selection, just
like the original script did. This window can (itself) be SAVED if
you want, (and that makes the rest of the activity sort of pointless
:)... but hey, this was a learning experience!!

The next thing that happens is that NOTEPAD opens with the same text,
except this text is READ from a local file, written by this procedure
(... C:\SelectedText.txt)...

Okay, still pretty lame, but NOW,... YOU can change all the parameters
in the script file to be what you want... Go and Do that before you
break something (and blame it on me :))) You can pick a different
editor, as long as you know how to write a command line for it to open
a file. Another thing to try is to use 'Sendkeys' to just push the
data into an open editor window, but that's another night...

Of course, there is NO WARRANTY for this modification, and I cannot be
responsible for ANYTHING you do with it! (I got this attitude from
Microsoft Literature...!!)

In summary, some interesting things I learned and reviewed... (THANKS
Omega!!)

- How IE Context Menu extensions work (ohhh so easy!)
- That you can MIX JavaScript and VBScript in the same
file/application.
- (AND... see above... that you have to WATCH the Escaped \ in
Javascript Strings.)
- You can do things via Context Menu Installed HTM files that the
browser won't let you do from a plain Web Page, for security reasons
(and you shouldn't, either !)
- Some helpful examples of the VBScript applications, withing the
Windows Scripting Host family of Fine Products. :)

Before doing anything serious with all this, one should clean out
things that are not contributing to the job you need to do. For
example, you probably don't need to open and write the new web page,
if you just want the file to work with.

But now, this whole IE Context Menu thing is OUT from behind the
curtains.

All for tonight.

D F
 
O

omega

(e-mail address removed) (D F):

------ Save this as C:\SomePlace\SomeWhere\ExcerptSource.htm --------- [...]
// Pick one... (Remember to escape \ in JavaScript.... and NOT in VB :)
var viewerTool = "C:\\Program Files\\NoteTab Light\\NoteTab.exe";
// var viewerTool = "notepad.exe";

// Change this to be a file YOU want...
var myFile = "C:\\SelectedExample.txt";

WriteFileVB(szsource,myFile);
ViewWithTool(viewerTool,myFile); [...]
' Start a Viewing Tool named by the user, and open a file named by the user.
sub ViewWithTool(usersViewer,usersFile) [...]
------ end of ExcerptSource.htm was the line before this -------------

Note for anyone saving this file. When you first run it through a text
editor, to customize the paths, you might also need to be sure to get rid
of any line breaks that were inserted in transmission by the news reader.
Second note. I found that the comment made within the file is true: you
have to be sure to select for your chosen viewsource tool one that it is
smart enough to accept a file as an argument (most are smart enough, but
not all).
At this point, when you start IE (version 5.0+...) you should be able
to Select some text (highlight)... Then Right-Click, and when you
select 'Source of Selected' TWO things will happen... (which can both
be Fixed...)

A new window will open showing the HTML Source of the selection, just
like the original script did. This window can (itself) be SAVED if
you want, (and that makes the rest of the activity sort of pointless
:)... but hey, this was a learning experience!!

The next thing that happens is that NOTEPAD opens with the same text,
except this text is READ from a local file, written by this procedure
(... C:\SelectedText.txt)...

Wow, that was FastTrack accomplishment! I've had this kind of thing on my
ToDo list for something over two years, and had not made it to step A. It
works exactly as you describe. Congrats!

The only next customization...is there a way to have the IE window close
itself down automatically? It's the editor I love seeing, which does
launch, from your menu enhancement, and does indeed contain source html! =)
Everything I wanted. Except only, when I see that extra IE window, I
would prefer not to have to interact with it. Is there a way this pref
can be worked into the script?
In summary, some interesting things I learned and reviewed... (THANKS
Omega!!)

- How IE Context Menu extensions work (ohhh so easy!)

I should have started with giving you the MSDN chapter that had planted the
seed of my wish. Even though you've nowalready figured out the workings,
and might also have already read these pages, here it is belatedly:

MSIE Extensions Chapter (most stuff just for IE)

http://msdn.microsoft.com/workshop/browser/ext/extensions.asp

Context Menu Section (here the Good stuff, works globally, on all browsers
+ most programs using the MS Browser Control)

http://msdn.microsoft.com/workshop/browser/ext/tutorials/menu.asp
- That you can MIX JavaScript and VBScript in the same
file/application.
- (AND... see above... that you have to WATCH the Escaped \ in
Javascript Strings.)

The regentry etc for this I was already familiar with -- but the scripting
language, I know close to nothing, so thank you for learning these things!
- You can do things via Context Menu Installed HTM files that the
browser won't let you do from a plain Web Page, for security reasons
(and you shouldn't, either !)

That's why all those bookmarklets type things are of no use to me. MSIE
sees them as coming from the "internet security zone," not the "local
computer security zone." I keep scripting off in the default "internet
zone," thus all those en masse flat out don't run on my system.

It is only these scripts that are designed to be extensions for the menu,
those are the ones that work great, and plug in very smoothly with MSIE.
Before doing anything serious with all this, one should clean out
things that are not contributing to the job you need to do. For
example, you probably don't need to open and write the new web page,
if you just want the file to work with.

I hope you, or even someone else, might be willing to do that study, to
see about how to not launch the IE windows if possible, or at least have
it close itself? I don't have the scripting knowledge to figure it out.
But now, this whole IE Context Menu thing is OUT from behind the
curtains.

Yes, it's great stuff. I've paid attention to the programs, and MSIE
web accessories, who use this menu (includes IE text archiver that you
brought up).... Yet what I did not know was the important thing. Can one
have a script written where there is a choice of programs, such as a
fav text editor, that gets called?

You've proved it can be done! So this is a wide road for customization.
Getting your global msie menu to act on what you want, with the program
you want. Happy day. :)
 
O

omega

(e-mail address removed) (D F):

Re: customizing the msie context-menu
----- Save this as (say) RegisterScript.reg ---------
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt]

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Source
of Selected]
@="C:\\SomePlace\\SomeWhere\\ExcerptSource.htm"
----- end of RegisterScript.reg was the line before this -----

Related subject. For even those who can't write script. The one thing you
can do, without a great deal of knowhow, is customize that which already
appears on your msie context menu.

Launch your registry editor, and export the parent key shown above, to
save as a backup. Now look over this key.

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt]

You'll see subkey names, such as "Download with programQ," "Save Image with
programZ," "Search with BotX," and so on. Those are the menu-entry names as
they appear in your MSIE context menu.

They are arbitrary, those names, they do not have to be matched to some
call elsewhere. So you can organize this menu by changing the names. For
example, make all appropriate menu items start with "Download with" And
all appropriate menu items start with "Image Saveto.." To group them by
kind, in a way that makes them easier to parse.

You can also just kill off any of those menu items you want, too, the ones
that you don't use. (If so, just keep your backup file, if you think you
might want them back later.)

The second thing. These menu items do not automatically arrange themselves
alphabetically. They get (non) arranged essentially according to the date
they were entered into the registry.

In order to arrange them alphabetically, you would need to export the key
from the registry. Twice: One as a backup, and one for editing with your
text editor.

Open your exported key with a notepad, and arrange them into alphabetical
order with it, by dragging blocks. Blocks, meaning make sure of course to
keep the values of a key grouped beneath it. For example, this whole block
would be need to be kept together:

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\&Selection
to WinInfo]
@="D:\\SYSUTILS\\SHELL\\ADDED\\MSIE\\winfo\\addsel.htm"
"Contexts"=dword:00000030

Note that it's "Selection to WinInfo" in this case, which represents what
you're arranging alphabetically. So that would be in the S (Selection)
area.

When you're done with the file in notepad and ready to re-merge it into
the registry, don't yet do it. First delete the original key with your
registry editor (else your new alphabetical order won't be obeyed).
Final step, merge this .reg which you've now ordered in alphebetcially
arranged blocks.

(Sidenote, you don't have to have arranged alphabetical as your chosen
ordering. Any ordering will be accepted, just it's hard for me to visualize
wanting other than alphabetical)

Since you've saved the original key as a backup, it follows there is not
risk to the procedure. If somehow you made some weird error when editing
with notepad (don't know what weird error possible, but anyway), you can
backtrack. Delete the key again, and restore/merge your saved backup.

Is it time-consuming to alphabetically arrange these keys in your text
editor? Yes. Is it worth it? IMO, yes.

Why is there not a third-party utility, a frontend GUI for this key,
as there are for so many other registry keys, one that can perform the
alphabetizing (or sorting however) automatically, as well as provide
a convenient interface for renaming and deleting those menu items?

Don't know. Just that no one's got to it yet. Freeware authors listening?
 
D

D F

omega said:
I hope you, or even someone else, might be willing to do that study, to
see about how to not launch the IE windows if possible, or at least have
it close itself? I don't have the scripting knowledge to figure it out.

Sorry about the line-breaking problems with the last post, AND the
sorry hacked code... (... one thing at a time..:)... At the bottom of
this post is a revised script file that just eliminates the IE Open
Window, and cleans up some of the long lines - The Code is still
hacked... But, it should be real easy for someone to just write it all
in VBScript. (Too much fun for me, thanks.)

Now, before I kill-file myself, I recommend that anyone interested in
this exercise ALSO get the free program DLExpert from
http://www.yanew.com/ -

DLExpert Version 0.99(2001.12.20)-
http://www.yanew.com/dlexpert099.exe

As the author says "DLExpert is a multi-thread resuming downloading
software. It make full use of resource of the client and the server to
download files from Internet at the most speedy rate. DLExpert's
powerful multi-thread function makes it download different parts of
the same file simultaneously. Namely it can divide the file into any
parts, at most more than 100 parts(NOT ONLY 5 OR 6 PARTS).Each of them
will be downloaded by one thread,so different parts can be downloaded
simultaneously, make speedy of downloading very quick."

That author integrates DLExpert with IE in just about the same way as
this past discussion illustrates. Check out his file 'GetAll.htm'
from the install directory, and you will see the outline of a script
to grab all the links on a given page. (These could also be written
to a file, if desired.) I use DLExpert all the time, but never
realized that his setup was so instructive.

Okay, last but not least...
Here is the revised, shortened script that writes the file, then opens
it with Notetab (... and anyone can still do various edits to change
the editor,... yadda yaddaah yadddddddaaaaa..... :)

------ Save this as C:\SomePlace\SomeWhere\ExcerptSource.htm ---------
<html>
<head></head>
<body>
<script language="JavaScript" defer>
<!--
// specific to context menu extensions
var win = external.menuArguments;
// the document object the user right-clicked on
var doc = win.document;
// the text the user selected
var sel = doc.selection;
// an IHTMLElement containing ...elements in the selection
var rng = sel.createRange();
// the html string composing the range
var szsource = rng.htmlText;

if (szsource.length <= 0) {
szsource = doc.body.outerHTML;
}

// Pick one,(Remember to escape \ in JavaScript, and NOT in VB :)
// Uncomment the line you want, or add your own definition.
// var viewerTool = "C:\\Program Files\\NoteTab Light\\NoteTab.exe";
var viewerTool = "notepad.exe";

// Change this to be a file YOU want...
var myFile = "C:\\SelectedExample.txt";

// This is really DUMB to call VB rountines, just to do this...
// Give UP - Write this whole thing in VBScript... Think how
// successful you will feel! Try it, You'll LIKE it.

WriteFileVB(szsource,myFile);
ViewWithTool(viewerTool,myFile);

// -->
</script>

<script language="VBScript"><!--
' Note, you can mix VBScript and JavaScript in the same module...

' Write a file containing the selected text, markup.
sub WriteFileVB(passedText,storeFile)

Dim fso, outf ' Objects to support writing the output file.

Set fso = CreateObject("Scripting.FileSystemObject")

' The OpenTextFile parameters mean this...
' Opentext(thefiletoopen, Mode: 1-Read 2-Write 8-Append,
CanWeCreateIt)
Set outf=fso.OpenTextFile(storeFile,2,True) ' Open the file.

outf.WriteLine passedText ' Put the whole selection, CR at end.

set outf=nothing ' Close the file.
set fso=nothing
end sub

' Start a Viewing Tool named by the user, open the temp file.
sub ViewWithTool(usersViewer,usersFile)

Dim WshShell, oExec ' Objects to run system 'Shell' programs.
Set WshShell = CreateObject("WScript.Shell")

' If necessary, provide a full path to the executable of
usersViewer.
' Some like notepad) are covered by a Command statement in the
registry,
' If this procedure cannot find your viewer, then provide a
' complete path. For example, 'notepad.exe' works all by itself,
' but you may need to Quote something like NoteTab ...
' "C:\Program Files\NoteTab Light\NoteTab.exe"
' We also quote the file name here so that you can have spaces in
it.
' IF the command for the viewer is NOT as simple as
' 'tool.exe file.txt' then you may
' have to alter the command line...

Set oExec = WshShell.Exec(usersViewer + " """ + usersFile + """")

Set wshShell = nothing
Set oExec = nothing
end sub
//-->
</script>
</body>
</html>
------ end of ExcerptSource.htm was the line before this -------------

That's all I can do tonight... Hope this works for you.

D F
 
O

omega

(e-mail address removed) (D F):
Sorry about the line-breaking problems with the last post

Nothing to apologize for. It's expected in news posts. The only workaround
is to temporarily post with columns set at 5000. It's a workaround I never
see used. Perhaps some clients don't easily set a per-post change of line
breaks. And then receiving clients, mainly MSOE, as far as I know, they
may well break things on receive, defeating any efforts in the send.

And in this case, since we're opening your script in a text editor already,
it's probably even good for us to eliminate line breaks as we go through
it, since maybe in the process absorb by osmosis some familiarity with the
scripting language.
At the bottom of this post is a revised script file that just eliminates
the IE Open Window

I can't believe you. You actually achieved this? So soon too? Well, I got
to try it out, find if this is really true..... Will post back in a while.
 
O

omega

(e-mail address removed) (D F):
Here is the revised, shortened script that writes the file, then opens
it with Notetab (... and anyone can still do various edits to change
the editor,... yadda yaddaah yadddddddaaaaa..... :)
[...]
------ end of ExcerptSource.htm was the line before this -------------

That's all I can do tonight... Hope this works for you.

Success! Excellent!

I didn't even know I could have this. With your script, my chosen editor
launches up with the source HTML of the excerpt I've selected, quickly and
cleanly. =) From there, I can even SaveAs to keep clips. Plus, GoneAtLast
is that fat, annoying IE window, which I had to endure for years, just to
see a bit of html source. Thank you!

However, your work here is not yet done. <G>


SUGGESTION #1. An addition to your .reg file....
----- Save this as (say) RegisterScript.reg ---------
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt]
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Source of Selected]
@="C:\\SomePlace\\SomeWhere\\ExcerptSource.htm" "contexts"=dword:00000010

----- end of RegisterScript.reg was the line before this -----

I copied that "contexts" data from the reg entry that was associated with
the original Web Accessories source.htm script. Some mentions about how
that "contexts" data field serves is at msdn:
http://msdn.microsoft.com/workshop/browser/ext/tutorials/context.asp

It keeps the msie context menu in focus. So that, for instance, a "View
Picture with..." command will only show up on the menu when there is an
image being targeted.


SUGGESTION #2. An addition to your script file....

It's time to sign it! It works great, and is ready for release. (In a
comments line, near the bottom or top, you really ought insert some form
of your name/ID/nym as author sig.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top