Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am doing work in a lab where I record the time of my experiments and I need to see reminders while I wait for the process to complete.
I need to make/find a count up timer application that displays message boxes at given time intervals. I also need it to record start and stop times to a spreadsheet. Researching the problem, I think a simple vbs script would work well. Once I have the script, I know enough to customize to my needs. However, I don't know how to put this together from scratch.
Chris Peterson

this might help..
first off, remember that you can *-/+- etc
like
5*60 << 5 minutes
5*3600 << 5 hours@echo off
cls
:sets
set /A SleepTime=
rem in secounds how long to sleep?
set /A TimeToStop=
rem how long shal i run be4 killing myself?
set /A TotalTime=0
set Fi=C:\TimeToStop.bat
set CW=C:\CreateWarning.bat
rem added that to make the bat smaller
:first
if exist %Fi% del %Fi%
echo @echo off>>%Fi%
echo "C:\Sleep.exe" %TimeToStop%>>%Fi%
echo Taskkill /IM Sleep.exe /F>>%Fi%
echo Taskkill /IM cmd.exe /F>>%Fi%
start %Fi%
:begin
"C:\Sleep.exe" %SleepTime%
set /A TotalTime=%TotalTime%+%SleepTime%
title been sleeping for %TotalTime% now
:CreateWarninig
if exist %CW% del %CW%
echo title Warning>>%CW%
echo @echo off>>%CW%
echo cls>>%CW%
echo echo Warning, have been sleeping for %TotalTime%
echo echo its %SleepTime% since last time you saw this.>>%CW%
echo pause>>%CW%
start %CW%
goto beginyou will be needing this Sleep program tho http://www.computerhope.com/dutil.htm
(direct link: http://www.computerhope.com/downloa... and sorry but i don't know VBS scripting but.. no1 else was answering this 1 so.. thought id give it a shot)

It's not what I'd categorize as simple, but this is probably what you're looking for:
Option Explicit
Dim shell, log, dateTime
Dim WMI, opts, PID, proc, ref, e
const cmd = "notepad.exe"
const startDir = "C:\windows\system32"
const logPath = "C:\log.csv"
Set shell = CreateObject("WScript.Shell")
Set WMI = GetObject("winmgmts:root\cimv2")
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
Set log = CreateObject("Scripting.FileSystemObject") _
.OpenTextFile(logPath, 8, True)
'Start watched process
'Reference: http://msdn.microsoft.com/en-us/library/aa394375(VS.85).aspx
Set opts = WMI.Get("Win32_ProcessStartup").SpawnInstance_
With opts
.CreateFlags = &H4000008 'Detached_Process + Create_Default_Error_Mode
.PriorityClass = 32 'Normal
.ShowWindow = 1 'Normal
End With
e = WMI.Get("Win32_Process").Create(cmd, startDir, opts, PID)
If e <> 0 Then
Dim str : str = "ERROR #" & e
Select Case e
Case 2 str = str & ": Access Denied"
Case 3 str = str & ": Insufficient Privllege"
Case 8 str = str & ": Unknown Failure"
Case 9 str = str & ": Not Found: " & cmd
Case 21 str = str & ": Script screwed up"
End Select
WScript.Echo str
WScript.Quit e
End If
'Start looking for the death of our process.
set ref = WMI.ExecNotificationQuery("SELECT * " _
& "FROM __instancedeletionevent " _
& "WITHIN 5 " _
& "WHERE TargetInstance ISA 'Win32_Process' "_
& "AND TargetInstance.ProcessID = " & PID)
'Make sure the process is still out there.
'(If not, we've already failed to catch its end.)
'Note: This is a very ungraceful crash. Expect a cryptic (WMI) error.
' Basically, if you get an error refering to line... 48(-ish?), this failed
Set proc = WMI.InstancesOf("Win32_Process")("Win32_Process=""" & PID & """")shell.Popup "Started: " & cmd, 5 '5 second popup
'Yeah...
'When NextEvent times out, it'll raise an Error. We catch it, show a popup,
'unraise the event, and loop.
On Error Resume Next
Do
If Err.Number Then
'Popup for 5 seconds
shell.Popup "Still waiting...", 5, "Bored Now"
Err.Clear 'Reset Err.
End If
Set proc = ref.NextEvent(10000) 'Wait period is in milliseconds
Loop While Err = &H80043001 'wbemErrTimedOut
'Error handling off.
On Error GoTo 0
'Output to .csv
'Note: dateTime's functionallity changes, depending on your version of WinXP.
' If the times are off by a few hours, swap the Trues and Falses.
dateTime.Value = proc.TargetInstance.CreationDate
log.Write dateTime.GetVarDate(True) & ","
dateTime.SetFileTime proc.TIME_CREATED, False
log.WriteLine dateTime.GetVarDate(True)
WScript.Echo "Done!"

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |