File: C:/Windows/OEM/Tracing.wsf
<?XML version="1.0" ?>
<package>
<?component error="true" debug="true" ?>
<comment>
</comment>
<component id="TraceSource">
<registration
progid="WaGuest.TraceSource"
description="description"
version="1.0.0.0"
clsid="{73E31C0A-9A21-43D2-B1F1-68C2E307A2B4}"/>
<public>
<property name="Name" />
<method name="CreateEvent" />
<method name="TraceEvent" />
<method name="GetCurrentTime" />
<method name="GetElapsedMSSinceNow">
<parameter name="timestamp" />
</method>
<method name="DateTimeAdd">
<parameter name="timestamp" />
<parameter name="milliseconds" />
</method>
</public>
<object id="FSO" progid="Scripting.FileSystemObject" />
<script language="VBScript"><![CDATA[
Option Explicit
Dim g_LogFilePath
g_LogFilePath = FSO.BuildPath(FSO.GetSpecialFolder(0), "Panther\WaSetup.xml")
Function HexJS(i)
HexJS = Hex(i)
End Function
Function CreateEvent(Category)
Dim evtDoc, evt
Set evtDoc = CreateObject( "Microsoft.XMLDOM" )
Set evt = evtDoc.createElement("Event")
With evtDoc.appendChild(evt)
.setAttribute "time", formatCurrentDate()
.setAttribute "category", Category
.setAttribute "source", Me.Name
End With
Set CreateEvent = evt
End Function
Sub TraceEvent(evt)
' write the event to the event log
Dim errorNumber
On Error Resume Next
Do
Dim oLogStream
Err.Clear
Set oLogStream = FSO.OpenTextFile(g_LogFilePath, 8, -1)
errorNumber = Err.number
If errorNumber = 0 Then
oLogStream.WriteLine evt.xml
End If
If Not (IsEmpty(oLogStream)) Then
oLogStream.Close
End If
Loop While errorNumber = &H46
End Sub
Function GetCurrentTime()
GetCurrentTime = formatCurrentDate()
End Function
Function DateTimeAdd(timestamp, milliseconds)
DateTimeAdd = addTimeMs(timestamp, milliseconds)
End Function
Function GetElapsedMSSinceNow(timestamp)
GetElapsedMSSinceNow = getElapsedMS(timestamp)
End Function
]]></script>
<script language="JScript"><![CDATA[
function formatDate(dt) {
return "" +
dt.getUTCFullYear() + "-" +
padDigits(dt.getUTCMonth() + 1, 2) + "-" +
padDigits(dt.getUTCDate(), 2) + "T" +
padDigits(dt.getUTCHours(), 2) + ":" +
padDigits(dt.getUTCMinutes(), 2) + ":" +
padDigits(dt.getUTCSeconds(), 2) + "." +
padDigits(dt.getUTCMilliseconds(), 3) + "Z";
}
function formatCurrentDate() {
var d = new Date();
return formatDate(d);
}
function padDigits(n, totalDigits) {
n = n.toString();
var pd = "";
for (i = 0; i < (totalDigits - n.length); i++) {
pd += "0";
}
return pd + n;
}
// Get the number of milliseconds since the epoch for a formatted
// UTC string. If the string cannot be parsed, the current date
// time in UTC is used.
function getMSFromEpochFromUtcString(ts) {
try {
// 2000-01-01T12:00:00.000Z
var pattern = /^(\d{4})\-(\d{2})\-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z$/;
var xs = ts.match(pattern);
return Date.UTC(xs[1], xs[2] - 1, xs[3], xs[4], xs[5], xs[6], xs[7]);
} catch (e) {
// getTime() is UTC based.
return new Date(0).getTime();
}
}
// Get the elapsed time in milliseconds for the specified timestamp from now.
//
// ts1: UTC formatted time string, e.g. 2000-01-02T03:04:05Z
function getElapsedMS(ts1) {
var d1 = getMSFromEpochFromUtcString(ts1);
var d2 = new Date().getTime(); // getTime() is UTC based.
return d2 - d1;
}
// Adds the given milliseconds to the given timestamp.
//
// ts: UTC formatted time string, e.g. 2000-01-02T03:04:05Z
// tc: milliseconds to add
function addTimeMs(ts, tc) {
var lts = getMSFromEpochFromUtcString(ts);
var dt = new Date(lts + tc);
return formatDate(dt);
}
]]></script>
</component>
</package>