Page 1 of 1

VB Sciprt HELR!!!

Posted: August 14, 2007, 4:02 pm
by cid
I need a vb script that will do the following



Ask a question

If they say yes



Ask another question

If they say yes

Write to a log file this echo %username%,%computername%,%time%,%date%



This can be with the msgbox variable with vbscript.
I jusy can not figure out how.

Anyone have any advice?

Re: VB Sciprt HELR!!!

Posted: August 15, 2007, 11:39 am
by cadalano
just like this:

if msgbox("question 1?", vbYesNo)=vbYes Then
if msgbox("question 2?", vbYesNo)=vbYes Then
dim fso, outfile, wshNet
Set wshnet = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set outfile = fso.OpenTextFile("C:\logfile.log", 2, 1)
outFileString = "echo %" & wshNet.username & "%,%" & wshNet.computername & "%,%" & FormatDateTime(Now, vbLongTime) & "%,%" & FormatDateTime(Date, vbShortDate) & "%"
outFile.Write outFileString
end if
end if

Re: VB Sciprt HELR!!!

Posted: August 15, 2007, 11:41 am
by cadalano
reading it again, you probably need the logfile to be a running list, rather than overwriting each time.


To do that, change the OpenTextFile method to:

Set outfile = fso.OpenTextFile("C:\logfile.log", 8, 1)


and put a carriage return / line feed on your string:

outFileString = "echo %" & wshNet.username & "%,%" & wshNet.computername & "%,%" & FormatDateTime(Now, vbLongTime) & "%,%" & FormatDateTime(Date, vbShortDate) & "%" & vbCrLf

Re: VB Sciprt HELR!!!

Posted: August 15, 2007, 11:45 am
by cadalano
reading it again, youre making a batch file and need the actual text "username" and "computername" probably. So i'm an idiot with the wshNet stuff. You can take it out easily and just leave a string!

Re: VB Sciprt HELR!!!

Posted: August 15, 2007, 12:11 pm
by cid
Thank you sir!!

Re: VB Sciprt HELR!!!

Posted: August 15, 2007, 12:29 pm
by Fash
,8,1 ??... lol c64 memories!