I am very new to VBS, but thought I could create a simple script that
would be scheduled to run a couple times a day to make an archive of
my webcam video.
I created the script, but it doesn't work sometimes. Here is what it
does: Stop program (dorgem.exe), move webcam video to Archive folder,
start program (dorgem.exe).

It works great, except sometimes dorgem does not close. If I use the /
F option with taskkill the program does not start up properly the next
time. I think the solution would be to have the script verify that
the process "dorgem.exe" halted and then continue with the file move,
and if the program did not halt try again 60 seconds later (It seems
to work after the 2nd or 3rd time if I do this manually from the
command line).

Can anybody give me some clues on how to do this? I cant seem to find
the answer online.
Here is my script...

'This script closes dorgem, moves a file, then opens dorgem.
'
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("taskkill /IM dorgem.exe")
WScript.sleep 2000
Set WshShell = WScript.CreateObject ("WScript.Shell")
WshShell.Run ("C:\Windows\system32\cmd.exe")
WScript.sleep 1000
'WshShell.SendKeys "move ""C:\Documents and Settings\doggod\My
Documents\My Videos\vidcap*"""
'WshShell.SendKeys " ""C:\Documents and Settings\doggod\My Documents
\My Videos\Archive\vidcap6pm"""
'WshShell.SendKeys "{ENTER}"
WshShell.SendKeys """C:\PROGRAM FILES\Dorgem\Dorgem.exe"""
WshShell.SendKeys "{ENTER}"
WScript.sleep 400
WshShell.SendKeys "exit"
WshShell.SendKeys "{ENTER}"

Re: Script to restart process... by Rafael

Rafael
Thu Jan 24 22:47:20 CST 2008

Hello

There are many ways to do what you are asking.
- You can use WMI to stop the service and check for its status before
issuing the next command.

- You can make your code more efficient if you avoid using sendKeys and use
something like the File System Object (FSO)

check this for some wmi samples
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/services/

check this for FSO copy folder
http://msdn2.microsoft.com/en-us/library/xbfwysex(VS.85).aspx

hope this helps,
--
**********
Rafael T


<jzachariasen@gmail.com> wrote in message
news:9b25cbe5-1575-42ea-a7c5-1e76bc62218f@t1g2000pra.googlegroups.com...
>I am very new to VBS, but thought I could create a simple script that
> would be scheduled to run a couple times a day to make an archive of
> my webcam video.
> I created the script, but it doesn't work sometimes. Here is what it
> does: Stop program (dorgem.exe), move webcam video to Archive folder,
> start program (dorgem.exe).
>
> It works great, except sometimes dorgem does not close. If I use the /
> F option with taskkill the program does not start up properly the next
> time. I think the solution would be to have the script verify that
> the process "dorgem.exe" halted and then continue with the file move,
> and if the program did not halt try again 60 seconds later (It seems
> to work after the 2nd or 3rd time if I do this manually from the
> command line).
>
> Can anybody give me some clues on how to do this? I cant seem to find
> the answer online.
> Here is my script...
>
> 'This script closes dorgem, moves a file, then opens dorgem.
> '
> Set objShell = CreateObject("Wscript.Shell")
> objShell.Run("taskkill /IM dorgem.exe")
> WScript.sleep 2000
> Set WshShell = WScript.CreateObject ("WScript.Shell")
> WshShell.Run ("C:\Windows\system32\cmd.exe")
> WScript.sleep 1000
> 'WshShell.SendKeys "move ""C:\Documents and Settings\doggod\My
> Documents\My Videos\vidcap*"""
> 'WshShell.SendKeys " ""C:\Documents and Settings\doggod\My Documents
> \My Videos\Archive\vidcap6pm"""
> 'WshShell.SendKeys "{ENTER}"
> WshShell.SendKeys """C:\PROGRAM FILES\Dorgem\Dorgem.exe"""
> WshShell.SendKeys "{ENTER}"
> WScript.sleep 400
> WshShell.SendKeys "exit"
> WshShell.SendKeys "{ENTER}"



Re: Script to restart process... by James

James
Thu Jan 24 22:58:35 CST 2008

<jzachariasen@gmail.com> wrote in message
news:9b25cbe5-1575-42ea-a7c5-1e76bc62218f@t1g2000pra.googlegroups.com...
>I am very new to VBS, but thought I could create a simple script that
> would be scheduled to run a couple times a day to make an archive of
> my webcam video.
> I created the script, but it doesn't work sometimes. Here is what it
> does: Stop program (dorgem.exe), move webcam video to Archive folder,
> start program (dorgem.exe).
>
> It works great, except sometimes dorgem does not close. If I use the /
> F option with taskkill the program does not start up properly the next
> time. I think the solution would be to have the script verify that
> the process "dorgem.exe" halted and then continue with the file move,
> and if the program did not halt try again 60 seconds later (It seems
> to work after the 2nd or 3rd time if I do this manually from the
> command line).
>
> Can anybody give me some clues on how to do this? I cant seem to find
> the answer online.
> Here is my script...
>
> 'This script closes dorgem, moves a file, then opens dorgem.
> '
> Set objShell = CreateObject("Wscript.Shell")
> objShell.Run("taskkill /IM dorgem.exe")
> WScript.sleep 2000
> Set WshShell = WScript.CreateObject ("WScript.Shell")
> WshShell.Run ("C:\Windows\system32\cmd.exe")
> WScript.sleep 1000
> 'WshShell.SendKeys "move ""C:\Documents and Settings\doggod\My
> Documents\My Videos\vidcap*"""
> 'WshShell.SendKeys " ""C:\Documents and Settings\doggod\My Documents
> \My Videos\Archive\vidcap6pm"""
> 'WshShell.SendKeys "{ENTER}"
> WshShell.SendKeys """C:\PROGRAM FILES\Dorgem\Dorgem.exe"""
> WshShell.SendKeys "{ENTER}"
> WScript.sleep 400
> WshShell.SendKeys "exit"
> WshShell.SendKeys "{ENTER}"

You can easily do this with a 3 line batch file (watch for wrapping):

taskkill /IM dorgem.exe"
move "C:\Documents and Settings\doggod\My Documents\My Videos\vidcap*"
"C:\Documents and Settings\doggod\My Documents\My
Videos\Archives\vidcap6pm\"
start "" "C:\Program Files\Dorgem\dorgem.exe"

If you wish to use a script, try the following:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit
Dim oWSH, oFSO, sSourceDir, sDestinDir
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWSH = CreateObject("WScript.Shell")

sSourceDir = "C:\Documents and Settings\doggod\My " _
& "Documents\My Videos\"
sDestinDir = "C:\Documents and Settings\doggod\My " _
& "Documents\My Videos\Archives\vidcap6pm\"

oWSH.Run "taskkill /IM dorgem.exe", 0, True
On Error Resume Next
oFSO.MoveFile sSourceDir & "vidcap*", sDestinDir
On Error Goto 0
oWSH.Run """C:\Program Files\Dorgem\dorgem.exe""", 1, False
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Re: Script to restart process... by jzachariasen

jzachariasen
Fri Jan 25 06:37:47 CST 2008

On Jan 24, 8:58 pm, "James Whitlow" <jwhitlow.60372...@bloglines.com>
wrote:
> <jzacharia...@gmail.com> wrote in message
>
> news:9b25cbe5-1575-42ea-a7c5-1e76bc62218f@t1g2000pra.googlegroups.com...
>
>
>
> >I am very new to VBS, but thought I could create a simple script that
> > would be scheduled to run a couple times a day to make an archive of
> > my webcam video.
> > I created the script, but it doesn't work sometimes. Here is what it
> > does: Stop program (dorgem.exe), move webcam video to Archive folder,
> > start program (dorgem.exe).
>
> > It works great, except sometimes dorgem does not close. If I use the /
> > F option with taskkill the program does not start up properly the next
> > time. I think the solution would be to have the script verify that
> > the process "dorgem.exe" halted and then continue with the file move,
> > and if the program did not halt try again 60 seconds later (It seems
> > to work after the 2nd or 3rd time if I do this manually from the
> > command line).
>
> > Can anybody give me some clues on how to do this? I cant seem to find
> > the answer online.
> > Here is my script...
>
> > 'This script closes dorgem, moves a file, then opens dorgem.
> > '
> > Set objShell = CreateObject("Wscript.Shell")
> > objShell.Run("taskkill /IM dorgem.exe")
> > WScript.sleep 2000
> > Set WshShell = WScript.CreateObject ("WScript.Shell")
> > WshShell.Run ("C:\Windows\system32\cmd.exe")
> > WScript.sleep 1000
> > 'WshShell.SendKeys "move ""C:\Documents and Settings\doggod\My
> > Documents\My Videos\vidcap*"""
> > 'WshShell.SendKeys " ""C:\Documents and Settings\doggod\My Documents
> > \My Videos\Archive\vidcap6pm"""
> > 'WshShell.SendKeys "{ENTER}"
> > WshShell.SendKeys """C:\PROGRAM FILES\Dorgem\Dorgem.exe"""
> > WshShell.SendKeys "{ENTER}"
> > WScript.sleep 400
> > WshShell.SendKeys "exit"
> > WshShell.SendKeys "{ENTER}"
>
> You can easily do this with a 3 line batch file (watch for wrapping):
>
> taskkill /IM dorgem.exe"
> move "C:\Documents and Settings\doggod\My Documents\My Videos\vidcap*"
> "C:\Documents and Settings\doggod\My Documents\My
> Videos\Archives\vidcap6pm\"
> start "" "C:\Program Files\Dorgem\dorgem.exe"
>
> If you wish to use a script, try the following:
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Option Explicit
> Dim oWSH, oFSO, sSourceDir, sDestinDir
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oWSH = CreateObject("WScript.Shell")
>
> sSourceDir = "C:\Documents and Settings\doggod\My " _
> & "Documents\My Videos\"
> sDestinDir = "C:\Documents and Settings\doggod\My " _
> & "Documents\My Videos\Archives\vidcap6pm\"
>
> oWSH.Run "taskkill /IM dorgem.exe", 0, True
> On Error Resume Next
> oFSO.MoveFile sSourceDir & "vidcap*", sDestinDir
> On Error Goto 0
> oWSH.Run """C:\Program Files\Dorgem\dorgem.exe""", 1, False
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TY very much James. Your script shows me a much better way to go
about this. It works great on my test box. Tonight I will try it on
my machine that sometimes has trouble closing the program.