1.

Solve : Is WScript,vbscript, and cscript hybrid type's of BATCH????

Answer»

Was checking out some lead's and found some stuff about making "SCRIPT"!

So had to check it over!

It look's as if it has alot of simularity to BATCH .

Don't know for sure myself so thought I would post and see if someone
new anything about SCRIPT and the different thing's I could do with it...

Know how to saveas like in a batch file...and to give it the "name.vbs" when
saving the script file.

But what else can be done with them?
Anyone have some example's for me?

CScript is the command line version of Windows Script Host (WSH) and WScript is the GUI version. Batch uses command.com or cmd.exe to interpret and execute files with a .bat extension. CScript and WScript are the interpreters for VBScript and JScript  files running under the Windows Script Host. Other languages can be added into WSH.

About the only thing  in common between batch files and either vbscript files and jscript files is that they all can accomplish some work. VBScript and JScript can create and utilize COM and ActiveX objects where batch files have only limited communication with Windows. VBS and JS also have limited access to the .Net Framework. Batch language was developed during DOS days  and has never been Microsoft's first choice for a scripting language. Microsoft later settled on VBA. (IBM's first choice was REXX for PC-DOS7 and OS/2 which had been ported from their mainframe product line (VM/CMS).

Generally you pick a language based on what you need to do and what you already know or are willing to learn. All script languages (Python, Perl, VBScript, JScript, Rexx and probably hundreds of others) have their stong points and their not so strong points.

Microsoft has also released Powershell which is closely tied to the .Net Framework. It's very powerful but has a rather steep learning curve compared to some of the other languages. One nice thing is you can send whole objects thru the pipeline as opposed to just text with batch code.

I found this example of a VBScript in the snippet closet. It simply goes to the internet, grabs a new hosts file and installs it on an XP machine.

Code: [Select]
        Const ForWriting = 2
        Const TristateUseDefault = -2
        Const OverWrite = True

        Set objIE = CreateObject("InternetExplorer.Application")
        Set fso = CreateObject("Scripting.FileSystemObject")

        objIE.Navigate("http://www.mvps.org/winhelp2002/hosts.txt")
        Do Until objIE.ReadyState = 4
                WScript.Sleep 100
        Loop
        objIE.document.parentwindow.clipboardData.SetData "text", objIE.document.body.Innertext

        Set f = fso.GetFile("c:\windows\system32\drivers\etc\HOSTS")
        If f.Attributes = f.Attributes AND 1 Then
                f.Attributes = f.Attributes XOR 1
        End If

        If f.Attributes = f.Attributes AND 2 Then
                f.Attributes = f.Attributes XOR 2
        End If

        If f.Attributes = f.Attributes AND 4 Then
                f.Attributes = f.Attributes XOR 4
        End If

        Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
        ts.Write objIE.Document.ParentWindow.ClipboardData.GetData("text")

        f.Attributes = f.Attributes XOR 1
        f.Attributes = f.Attributes XOR 2
        f.Attributes = f.Attributes XOR 4

        ts.Close
        objIE.Quit
        Set objIE = Nothing

Good luck. THANK's Sidewinder I have been triing to learn all the program's that work
with my system that are already their and how I can use them more usefully......but the history on it help's understand alittle more

Have any example's I could toy around with so I can get to know how to use it better .......... more of an advanced learning stage.

I'm still learning batch,DOS, and script so i'm limited on knowledge ....
alway's triing to step up and learn more with programming in any form!

I  have been told that Batch and DOS aren't really programming language's
so I think I did to focas on c,c++, and Pascal !

Worked alittle with them just not enough to get a good start on understanding yet how to setup everything to make a program work right!Ok so what 's this mean that it's going todo in lame term's ................."grabs a new hosts file and installs it on an XP machine."

Before I run it .

That way I will no what to expect!!!

Remember i'm new to alot of this stuff!
So don't quit get what some of it mean's but can and want to learn!
Some people will make the case that batch language is a scripting language but in REALITY it's really a command language that originally came with DOS and now shows up with Windows, usually with some small UPDATES to handle new features of the operating system.

The scripting languages (VBScript, JScript, Python, Perl, Rexx and all the others) are text files that need an interpreter to run; usually supplied with each language. If any changes are made to scripts, they need only to be re-run for the changes to take effect. Generally scripts are faster to write and easier to maintain than full blown programs. On the downside, they tend to run slower than full blown programs.

Programming languages (C, C++, Pascal, VB, and all the others) start out as text files that get compiled and linked. If a change is made, the entire cycle of compile and link must be repeated.

The sample VBScript grabs a hosts file from the internet. The hosts file is the first line of defense your browser checks for off-limit sites. Generally porn sites or known sites for malware, if the address you're trying to connect with has an entry in the hosts file, the browser will reroute the request back to your system with a page displayed it could not find the site. The http://www.mvps.org/winhelp2002/hosts.txt is a good source for a hosts file, but it's updated EVERY two weeks or so. The script goes to the site, selects the host file text, copies it to the clipboard, writes out a new hosts file from the data on the clipboard and flips a few file attributes to hide and make it read-only. Many people do not use a hosts file, but if there are underage children using the computer, a hosts file is one way to prevent kids from viewing inappropriate sites (it's also free).

 Ok so how do you undo the host file for parent's search on everything..
Undo what you just did if it cause's conflict's with the system....I can't imagine the hosts file causing any conflicts unless you're trying to get into some dodgy sites. In any case the hosts file shipped with Windows consists of some comments and a single active line.

You could either write code to RECREATE the original file from scratch, or save the original file. By using an external parameter passed at run time you could decide whether to restore the original file or to get a new one from the net.

There are many ways to do most things when either scripting or programming. You are limited only by your imagination.
 
I suggest search for the script56.chm on your system. It is the compiled help file for VBScript and Jscript and defines all the methods and properties you can use when developing your scripts. Also check out The Script Center for the many tools and examples.

Good luck. Sidewinder thanks for the info.
Alot of this is new to me so I alway's like having a way to undo something
befor I try it out just incase it does cause conflict's with other program's.....
not saying it will of course!
But I have learned one thing from playing around with batch,asm,script and
some other's is that you should alway's find out what all a script, is going todo and how you can undo it .....just incase you turn of a function you need to access your internet account and yes that has happened to me......
that's when I decided to learn all I could!

But really thank's for the info and sorry I didn't get to reply sooner !



Discussion

No Comment Found