Using WScrip.Echo in a WSC file....? 
Author Message
 Using WScrip.Echo in a WSC file....?

Does anyone know of a better way to implement the WScript.Echo method in a
Windows Script component file?  The only way I have been able to do it is to
actually pass the WScript object from a .VBS file in the functions to the
.WSC file... like this:

In .VBS file:

Set oObj = CreateObject("WSCFile.WSC")
Wscript.Echo "Getting User Information..."
WSCFile.GetUserInfo(WScript)
WScript.End

In .WSC file:

Function get_GetUSerInfo(WScript)
    WScript.Echo "Declaring variables...."
    Dim x, y, z
    ...
    WScript.Echo "Doing other things..."
    ...
    WScript.Echo "Doing other things..."
    ...
    WScript.Echo "GetUser Info Completed."
End Function

Surely there is a better way!
Thanks in Advance.
miles



Mon, 09 Sep 2002 03:00:00 GMT  
 Using WScrip.Echo in a WSC file....?
Until something like <implements type="WSH" /> comes along, your way is as good as any.  You could
give the WSC a property that you assign the WScript object to once and then use the internal
property reference instead of passing a reference on multiple calls.

--
Michael Harris
MVP Scripting

Does anyone know of a better way to implement the WScript.Echo method in a
Windows Script component file?  The only way I have been able to do it is to
actually pass the WScript object from a .VBS file in the functions to the
.WSC file... like this:

In .VBS file:

Set oObj = CreateObject("WSCFile.WSC")
Wscript.Echo "Getting User Information..."
WSCFile.GetUserInfo(WScript)
WScript.End

In .WSC file:

Function get_GetUSerInfo(WScript)
    WScript.Echo "Declaring variables...."
    Dim x, y, z
    ...
    WScript.Echo "Doing other things..."
    ...
    WScript.Echo "Doing other things..."
    ...
    WScript.Echo "GetUser Info Completed."
End Function

Surely there is a better way!
Thanks in Advance.
miles



Mon, 09 Sep 2002 03:00:00 GMT  
 Using WScrip.Echo in a WSC file....?
Yeah... that is what I was afraid of... :)
I just wanted to make sure that there was not a way you could specify
something like <implements type="WSH" />.  Possible new feature in WSH 2.5
or 3???
Thanks!
Miles


Quote:
> Until something like <implements type="WSH" /> comes along, your way is as

good as any.  You could
Quote:
> give the WSC a property that you assign the WScript object to once and

then use the internal
Quote:
> property reference instead of passing a reference on multiple calls.

> --
> Michael Harris
> MVP Scripting




Quote:
> Does anyone know of a better way to implement the WScript.Echo method in a
> Windows Script component file?  The only way I have been able to do it is
to
> actually pass the WScript object from a .VBS file in the functions to the
> .WSC file... like this:

> In .VBS file:

> Set oObj = CreateObject("WSCFile.WSC")
> Wscript.Echo "Getting User Information..."
> WSCFile.GetUserInfo(WScript)
> WScript.End

> In .WSC file:

> Function get_GetUSerInfo(WScript)
>     WScript.Echo "Declaring variables...."
>     Dim x, y, z
>     ...
>     WScript.Echo "Doing other things..."
>     ...
>     WScript.Echo "Doing other things..."
>     ...
>     WScript.Echo "GetUser Info Completed."
> End Function

> Surely there is a better way!
> Thanks in Advance.
> miles



Fri, 13 Sep 2002 03:00:00 GMT  
 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



Sun, 15 Dec 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Using WSC files from ASP (VBScript)

2. Using WSC files from ASP (VBScript)

3. Using WScript in wsc files

4. NEWS: echo on, echo off.

5. How to echo msg AFTER a log file has finished being written to

6. how to output to a FILE, instead of ECHO

7. Using WSC and DCOM

8. Interfacing with Access object using WSC written in JScript

9. Expose Python library to PerlScript using WSC

10. Using WScript object in WSC components

11. Using Wscript Objects in WSC

12. Using an ActiveX control within MSG.WSC

 

 
Powered by phpBB® Forum Software