1.

Solve : VBScript - Read text file & Decide Process from Results?

Answer»

Hi All,

I am using vbscript to find what out what the operating system is, and creating a text file with the results - by way of the OS version (i.e. XP is 5.1, Vista is 6.0.00).

What I'd like to do is then decide which disc cleanup commands to use from these results, through another VBScript file. I can get the script to read from the text file, but I can't it to WORK if I add "If and Else" arguments on the OS version detail it finds.

I'm trying to get it to read the file and if it reads "5.1 then do this" - else "if it reads 6.0 do that"

My code thus far is:

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("..\whatisos.txt", ForReading)

strLine = objFile.ReadLine
If strLine = "5.1" Then

dim SHELL
set shell=createobject("wscript.shell")
shell.run "cleanupxp.bat"
set shell=nothing

Else

dim shell
set shell=createobject("wscript.shell")
shell.run "cleanupvista.bat"
set shell=nothing

End If

objFile.Close


Any help is greatly appreciated.
your Dim-ing Shell twice. remove the Second Dim Shell Line.


what errors do you get?none now you absolute genius!! LOL nice PRAISE... Quote from: pcwizard on September 23, 2008, 01:44:44 PM

none now you absolute genius!!
Good! One way to make SURE you don't accidentally Dimension a variable twice is to declare them all first, IE, with your constants.

I get burnt a lot myself when I try to Dimension them right when I need them, but I'm spoiled because I'm using VB6 rather then VBScript, which means I actually get an IDE.


Discussion

No Comment Found