1.

Solve : Vbs scripting problem?

Answer»

The batch code is like this:

test.bat

Code: [Select]echo %Time% >RecordedTime.txt
echo %username% >>RecordedTime.txt
echo %computername% >>RecordedTime.txt

Then how about the vbs script?
What is the vbs script that will do the same work as "test.bat"?Hard to BELIEVE, but sometimes batch code is actually the BEST tool for the job.

Batch code: (copied from OP)
Code: [Select]echo %Time% >RecordedTime.txt
echo %username% >>RecordedTime.txt
echo %computername% >>RecordedTime.txt

VBScript:
Code: [Select]SET fso = CREATEOBJECT("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set f = fso.CreateTextFile("c:\temp\RecordedTime.txt", True)

f.WriteLine Time
f.WriteLine WshShell.ExpandEnvironmentStrings("%UserName%")
f.WriteLine WshShell.ExpandEnvironmentStrings("%ComputerName%")
f.Close

Feel free to tweak the file label in line 3.

Good LUCK.



Discussion

No Comment Found