
Using WScrip.Echo in a WSC file....?
Miles,
You can use the following:
'
' Create an object to handle output
'
Set StatusLine = wscript.createobject( "Status.wsc")
'
' Due to the completely STUPID manner in which scripting
' is handled in .WSC files, the WScript object must be
' passed to the object
'
StatusLine.Wscript = WSCRIPT
'
' If outputting to the GUI, we want to concatenate the
' output so that the user doesn't need to press OK
' for every output line
'
StatusLine.Concatenate = TRUE
StatusLine.Status= "Test Data - Line 1"
StatusLine.Status= "Test Data - Line 2"
'
' Turn Concatenation off (this will output all queued lines)
'
StatusLine.Concatenate = False
StatusLine.Status= "Test Data - Line 3"
------------------------------------
Here is the STATUS.WSC file:
<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<registration
description="Status"
progid="Status.WSC"
version="1.00"
classid="{7b6c8000-4cca-11d4-83b0-006094f9d8fc}"
</registration>
<public>
<property name="Status">
<get/>
<put/>
</property>
<property name="Concatenate">
<get/>
<put/>
</property>
<property name="WScript">
<get/>
<put/>
</property>
</public>
<implements type="Behavior" id="Behavior"/>
<script language="VBScript">
<![CDATA[
Dim strStatus
Dim bConcatenate
Dim objWScript
function get_Concatenate()
get_Concatenate = bConcatenate
end function
function put_Concatenate(bTrueFalse)
bConcatenate = bTrueFalse
if bConcatenate = "True" then
else
if strStatus <> "" then
objWscript.echo strStatus
strStatus = ""
end if
end if
end function
function get_WScript()
get_WScript = objWScript
end function
function put_WScript(ScriptObject)
Set objWScript = ScriptObject
end function
function get_Status()
get_Status = strStatus
end function
function put_Status(StatusLine)
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
If LCase(Right(objWScript.FullName, 11))
= "wscript.exe" Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(Left
(objWScript.scriptfullname, InStrRev
(objWScript.scriptfullname, ".", -1, vbTextCompare)) & "log",
ForAppending, True)
ts.WriteLine StatusLine
ts.Close
Set ts = Nothing
Set fs = Nothing
if bConcatenate = True then
strStatus = strStatus & vbCRLF & StatusLine
else
objWScript.Echo StatusLine
end if
Else
objWScript.echo StatusLine
End If
end function
]]>
</script>
</component>
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com