Discussion:
Looking for a good scripting language.
(too old to reply)
s***@hotmail.com
2005-02-28 18:03:39 UTC
Permalink
Hello,

I am newbie to Windows. (Advanced Linux user). For Windows, I want
to
write a script that searchs for all executables in computer. Then, I
want to
run another program ("dumpbin") on each of the result. Finally I want
to
collate the results.

Can someone tell me what is a good language to do this? I looked at
VBScript
and Windows Script Host. TO me, it looks like these languages do not
support
directory traversal.

I can use PERL. But then, I do no want to install perl. My program will
have
to run on some hosts which may not have perl. So I want to make
miminalistic
assumptions.

thanks,
Sudhakar.
Corné Bogaarts
2005-02-28 21:51:20 UTC
Permalink
You can use VBScript, JScript, or batchfiles for this purpose.
Post by s***@hotmail.com
Hello,
I am newbie to Windows. (Advanced Linux user). For Windows, I want
to
write a script that searchs for all executables in computer. Then, I
want to
run another program ("dumpbin") on each of the result. Finally I want
to
collate the results.
Can someone tell me what is a good language to do this? I looked at
VBScript
and Windows Script Host. TO me, it looks like these languages do not
support
directory traversal.
I can use PERL. But then, I do no want to install perl. My program will
have
to run on some hosts which may not have perl. So I want to make
miminalistic
assumptions.
thanks,
Sudhakar.
Gerry Hickman
2005-02-28 23:31:28 UTC
Permalink
Hi,

JScript is the best scripting language for Windoze. Closer to Perl and
open standards ECMA script, and more powerful than "kiddie" VBScript.
You can recurse files and folders with both JScript and VBScript but
you'll have to use a built-in COM object called "FileSystemObject". You
can also use Perl with WMI to manipulate remote machines that don't have
Perl installed. Here's an example of recursing folders using JScript.
This program outputs the current user's IE Favorites to a text file.
Note the trawlFolder() function is being called recursively.

Look out for line wrap!

----- start ----- start ----- start -----

// Fav2Text.js
//
// Convert Current User's Favorites to Text

var strOutFile = "d:\\Fav2Text.txt";

var ForReading = 1;
var ForWriting = 2;
var ForAppending = 8;

var fso = new ActiveXObject("Scripting.FileSystemObject");
var oWshShell = new ActiveXObject("WScript.Shell");
var strFavs = oWshShell.SpecialFolders("Favorites");
var objFolder = fso.GetFolder(strFavs);

var arrFileList = new Array();
arrFileList = trawlFolder(objFolder, arrFileList);

var fh = fso.OpenTextFile(strOutFile, ForWriting, true);
for (var i in arrFileList) {
if (!checkExtension(arrFileList[i].Name)) continue;
var oWshUrlShortcut = oWshShell.CreateShortcut(arrFileList[i].Path);
var strLine = stripExtension(arrFileList[i].Name) + "; ";
strLine += oWshUrlShortcut.TargetPath;
fh.WriteLine(strLine);
}

fh.Close();
fso = null;
oWshShell = null;

function trawlFolder(objFolder, arrFileList) {
var eFolderList = new Enumerator(objFolder.SubFolders);
var eFileList = new Enumerator(objFolder.files);
// Iterate *files* in current *folder*
for (; !eFileList.atEnd(); eFileList.moveNext()) {
objFile = eFileList.item();
arrFileList.push(objFile);
}

// Iterate *subfolders* below current *folder*
for (; !eFolderList.atEnd(); eFolderList.moveNext()) {
objFolder = eFolderList.item();
arrFileList = trawlFolder(objFolder, arrFileList);
}
return arrFileList;
}

function stripExtension(strFileName) {
var re = /\..+$/i;
var strName = strFileName.replace(re,"");
return strName;
}

function checkExtension(strFileName) {
var re = /\.url$/i;
if(strFileName.match(re)) {
return true;
} else {
return false;
}
}

----- end ----- end ----- end -----
Post by s***@hotmail.com
Hello,
I am newbie to Windows. (Advanced Linux user). For Windows, I want
to
write a script that searchs for all executables in computer. Then, I
want to
run another program ("dumpbin") on each of the result. Finally I want
to
collate the results.
Can someone tell me what is a good language to do this? I looked at
VBScript
and Windows Script Host. TO me, it looks like these languages do not
support
directory traversal.
I can use PERL. But then, I do no want to install perl. My program will
have
to run on some hosts which may not have perl. So I want to make
miminalistic
assumptions.
thanks,
Sudhakar.
--
Gerry Hickman (London UK)
Al Dunbar [MS-MVP]
2005-03-01 04:19:50 UTC
Permalink
Post by Gerry Hickman
Hi,
JScript is the best scripting language for Windoze. Closer to Perl and
open standards ECMA script, and more powerful than "kiddie" VBScript.
You can recurse files and folders with both JScript and VBScript but
you'll have to use a built-in COM object called "FileSystemObject". You
can also use Perl with WMI to manipulate remote machines that don't have
Perl installed. Here's an example of recursing folders using JScript.
This program outputs the current user's IE Favorites to a text file.
Note the trawlFolder() function is being called recursively.
Although I agree that jscript is a more powerful scripting language than
batch, the distance between batch and jscript is of a similar order of
magnitude to that between batch and vbscript.

Had the question been asked in one of the batch-oriented newsgroups, a batch
solution would likely have been given that was simpler and more direct than
your jscript one (or its vbscript equivalent!).

Powerful is one thing, applicability to the task is another. Of course, the
OP's original environment and background might have a thing or two to say
about this as well.

/Al
Post by Gerry Hickman
Look out for line wrap!
----- start ----- start ----- start -----
// Fav2Text.js
//
// Convert Current User's Favorites to Text
var strOutFile = "d:\\Fav2Text.txt";
var ForReading = 1;
var ForWriting = 2;
var ForAppending = 8;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var oWshShell = new ActiveXObject("WScript.Shell");
var strFavs = oWshShell.SpecialFolders("Favorites");
var objFolder = fso.GetFolder(strFavs);
var arrFileList = new Array();
arrFileList = trawlFolder(objFolder, arrFileList);
var fh = fso.OpenTextFile(strOutFile, ForWriting, true);
for (var i in arrFileList) {
if (!checkExtension(arrFileList[i].Name)) continue;
var oWshUrlShortcut = oWshShell.CreateShortcut(arrFileList[i].Path);
var strLine = stripExtension(arrFileList[i].Name) + "; ";
strLine += oWshUrlShortcut.TargetPath;
fh.WriteLine(strLine);
}
fh.Close();
fso = null;
oWshShell = null;
function trawlFolder(objFolder, arrFileList) {
var eFolderList = new Enumerator(objFolder.SubFolders);
var eFileList = new Enumerator(objFolder.files);
// Iterate *files* in current *folder*
for (; !eFileList.atEnd(); eFileList.moveNext()) {
objFile = eFileList.item();
arrFileList.push(objFile);
}
// Iterate *subfolders* below current *folder*
for (; !eFolderList.atEnd(); eFolderList.moveNext()) {
objFolder = eFolderList.item();
arrFileList = trawlFolder(objFolder, arrFileList);
}
return arrFileList;
}
function stripExtension(strFileName) {
var re = /\..+$/i;
var strName = strFileName.replace(re,"");
return strName;
}
function checkExtension(strFileName) {
var re = /\.url$/i;
if(strFileName.match(re)) {
return true;
} else {
return false;
}
}
----- end ----- end ----- end -----
Post by s***@hotmail.com
Hello,
I am newbie to Windows. (Advanced Linux user). For Windows, I want
to
write a script that searchs for all executables in computer. Then, I
want to
run another program ("dumpbin") on each of the result. Finally I want
to
collate the results.
Can someone tell me what is a good language to do this? I looked at
VBScript
and Windows Script Host. TO me, it looks like these languages do not
support
directory traversal.
I can use PERL. But then, I do no want to install perl. My program will
have
to run on some hosts which may not have perl. So I want to make
miminalistic
assumptions.
thanks,
Sudhakar.
--
Gerry Hickman (London UK)
Gerry Hickman
2005-03-01 23:26:45 UTC
Permalink
Post by Al Dunbar [MS-MVP]
Had the question been asked in one of the batch-oriented newsgroups, a batch
solution would likely have been given that was simpler and more direct than
your jscript one (or its vbscript equivalent!).
I gave an OO general purpose folder recursion routine that can be run
"anytime", "anywhere", not just seaching for EXE files on one computer,
but being able to recurse folders for large and robust network
applications. It also demonstrates other facilities such as obtaining
user specific profile data, regular expressions, and File I/O.

If he's used to Linux and Perl, I don't think he'd want a bungling batch
file that can only run on one machine!

If you read his post again (I'm not saying you didn't) I think you'll
agree this is definitely a job for scripting and not a batch file, and
he does ask for "a good scripting language" in the subject?
--
Gerry Hickman (London UK)
Al Dunbar [MS-MVP]
2005-03-02 18:56:33 UTC
Permalink
Post by Gerry Hickman
Post by Al Dunbar [MS-MVP]
Had the question been asked in one of the batch-oriented newsgroups, a batch
solution would likely have been given that was simpler and more direct than
your jscript one (or its vbscript equivalent!).
I gave an OO general purpose folder recursion routine that can be run
"anytime", "anywhere", not just seaching for EXE files on one computer,
but being able to recurse folders for large and robust network
applications. It also demonstrates other facilities such as obtaining
user specific profile data, regular expressions, and File I/O.
Interesting, as I have been recently taken to task for providing a solution
that went the slightest bit beyond the absolute minimal task that was asked
of us in one of the batch groups.

But I digress. I was not dissing your contribution, only making some
alternate suggestions to give the OP more options to choose from.
Post by Gerry Hickman
If he's used to Linux and Perl, I don't think he'd want a bungling batch
file that can only run on one machine!
Perhaps, but it is really only the OP who knows what he wants.
Post by Gerry Hickman
If you read his post again (I'm not saying you didn't) I think you'll
agree this is definitely a job for scripting and not a batch file, and
he does ask for "a good scripting language" in the subject?
I agree completely, however you seem not to consider batch as a "scripting
language". While I agree it is significantly less capable in many respects
than jscript, there are whole bunches of people who rely on it for admin
purposes to the exclusion of the more sophisticated options. I still do some
things in batch, even though they could be done in *my* scripting language
of choice, for much the same reason that handsaws remain in common use in
the electric era.

/Al
Gerry Hickman
2005-03-02 21:38:54 UTC
Permalink
Hi Al,
Post by Al Dunbar [MS-MVP]
I agree completely, however you seem not to consider batch as a "scripting
language". While I agree it is significantly less capable in many respects
than jscript, there are whole bunches of people who rely on it for admin
purposes to the exclusion of the more sophisticated options.
I don't dispute BAT files are quicker and better for certain tasks, I
just thought scripting was more appropriate for this specific task.

I do love seeing those examples the batch experts post from time to time
with 'for loops' and 'tokens'
--
Gerry Hickman (London UK)
Al Dunbar [MS-MVP]
2005-03-03 04:08:46 UTC
Permalink
Post by Gerry Hickman
Hi Al,
Post by Al Dunbar [MS-MVP]
I agree completely, however you seem not to consider batch as a "scripting
language". While I agree it is significantly less capable in many respects
than jscript, there are whole bunches of people who rely on it for admin
purposes to the exclusion of the more sophisticated options.
I don't dispute BAT files are quicker and better for certain tasks, I
just thought scripting was more appropriate for this specific task.
I do love seeing those examples the batch experts post from time to time
with 'for loops' and 'tokens'
At last, something we can agree on! I mean, how can one expect to read code
with stuff in it like the following that I read elsewhere earlier this
evening:

%%Z%%Y%%X%%W%%V%%U%%T%%S%%R%%Q%%P%%O%%N%%M%%L%%K%%J%%I%%H%%G%%F%%E%%D%%C%%B%
%A

without getting a headache! Granted this is taken out of context, but
really...

/Al
Gerry Hickman
2005-03-04 01:11:36 UTC
Permalink
Post by Al Dunbar [MS-MVP]
%%Z%%Y%%X%%W%%V%%U%%T%%S%%R%%Q%%P%%O%%N%%M%%L%%K%%J%%I%%H%%G%%F%%E%%D%%C%%B%
%A
Hehe, I've just remembered why I like scripting! This reminds me of
those old batch files they used with RAMDISK.SYS to find the "next
available drive letter".
--
Gerry Hickman (London UK)
Al Dunbar [MS-MVP]
2005-03-04 05:04:10 UTC
Permalink
%%Z%%Y%%X%%W%%V%%U%%T%%S%%R%%Q%%P%%O%%N%%M%%L%%K%%J%%I%%H%%G%%F%%E%%D%%C%%B%
Post by Gerry Hickman
%A
Hehe, I've just remembered why I like scripting! This reminds me of
those old batch files they used with RAMDISK.SYS to find the "next
available drive letter".
As much as there have been, and continue to be, examples of the worst kind
of batch scripting, there are some who do a much better job, and some who do
as bad a job - in other the more modern languages.

But, deep down, have you no empathy whatsoever for those who revel in the
sheer arcanity of those old technologies from which very clever individuals
wrested results unimagined by the originators?

/Al
Gerry Hickman
2005-03-04 15:11:04 UTC
Permalink
Post by Al Dunbar [MS-MVP]
But, deep down, have you no empathy whatsoever for those who revel in the
sheer arcanity of those old technologies from which very clever individuals
wrested results unimagined by the originators?
Well it was only a few weeks ago I was having to code up config.sys and
autoexec.bat for a DOS 6.22 bootable CD with network support. It's for
kicking of new builds of Windows over a non-DHCP network. Anyone
remember all the EMM386 and HIMEM switches?

I was amazed how well this worked out though, once I'd got the RAMDISK
sorted out, and a separate "tools" partition on the CD, it's got a very
modern feel to it. Just boot it up, choose a NIC and you're on the
network in no time with a vast array of tools that would never have been
able to fit on a floppy.
--
Gerry Hickman (London UK)
j***@cidermail.com
2005-03-22 15:35:04 UTC
Permalink
Post by Al Dunbar [MS-MVP]
%%Z%%Y%%X%%W%%V%%U%%T%%S%%R%%Q%%P%%O%%N%%M%%L%%K%%J%%I%%H%%G%%F%%E%%D%%C%%B%
As much as there have been, and continue to be, examples of the worst kind
of batch scripting, there are some who do a much better job, and some who do
as bad a job - in other the more modern languages.
But, deep down, have you no empathy whatsoever for those who revel in the
sheer arcanity of those old technologies from which very clever individuals
wrested results unimagined by the originators?
/Al
***@cidermail.com

Torgeir Bakken (MVP)
2005-03-01 15:25:46 UTC
Permalink
Post by s***@hotmail.com
Hello,
I am newbie to Windows. (Advanced Linux user). For Windows, I want
to
write a script that searchs for all executables in computer. Then, I
want to
run another program ("dumpbin") on each of the result. Finally I want
to
collate the results.
Can someone tell me what is a good language to do this? I looked at
VBScript
and Windows Script Host. TO me, it looks like these languages do not
support
directory traversal.
Hi

As long as all the computers are Win2k, WinXP and Win2k3, you
can use WMI for this.

Try the following VBScript with cscript.exe in a command prompt:

'--------------------8<----------------------
sComputer = "." ' Use "." for local computer
sExtension = "exe"

Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer _
& "\root\cimv2")


' get all local drives in a collection
Set oDriveSet = oWMI.ExecQuery _
("select Name from Win32_LogicalDisk where DriveType=3")

' get all files with the specified extension
For Each oDrive In oDriveSet
sWQL = "Select Name from CIM_DataFile where Drive='" _
& oDrive.Name & "' AND Extension='" & sExtension & "'"

Set oResult = oWMI.ExecQuery(sWQL,, 48)
For Each oFile In oResult
WScript.Echo "File: " & oFile.Name
Next
Next
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
Continue reading on narkive:
Loading...