This is my script. While running, a window is opened, and refreshed
every so many seconds. Works great, but I want a button that I can
use to cancel the script and close the window. I know I can use these
two commands
objExplorer.Quit 'close window
Wscript.Quit 'quit proccess
but I can't get a html button to call them. Can someone please help
me and show me how, or give me a better way of doing what I want.

Thanks


On Error Resume Next
LocalDirectory = "C:\X"
RemoteDirectory = "D:\X\"
Seconds = 5
Minutes = ( Seconds / 60 )
strComputer = "."

Set objExplorer = CreateObject ( "InternetExplorer.Application" )
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 550
objExplorer.Height = 200
objExplorer.Visible = 1
objExplorer.Document.Title = "Script in progress"

Do
LastRanTime = Now

If Seconds > 59 Then
objExplorer.Document.Body.InnerHTML = "This script will run every "
& Minutes & " minutes. <BR> " &_
"Your script is now being processed and may take several minutes to
complete. <BR>" &_
"This script last ran at " & LastRanTime
Else
objExplorer.Document.Body.InnerHTML = "This script will run every "
& Seconds & " seconds. <BR> " &_
"Your script is now being processed and may take several minutes to
complete. <BR>" &_
"This script last ran at " & LastRanTime
End If

objExplorer.Reload( True )

Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set objWMIService = GetObject( "winmgmts:\\" & strComputer & "\root
\cimv2" )
Set colFileList = objWMIService.ExecQuery _
( "ASSOCIATORS OF {Win32_Directory.Name='" & LocalDirectory & "'}
Where " & "ResultClass = CIM_DataFile" )

For Each objFile In colFileList

If ucase( objFile.Extension ) = "DXF" Then

RemoteFile = RemoteDirectory & objFile.FileName & "." &
objFile.Extension

If objFSO.FileExists( RemoteFile ) Then

Set objLocalFile = objFSO.GetFile( objFile.Name )
LocalDate = objLocalFile.DateLastModified

Set objRemoteFile = objFSO.GetFile( RemoteFile )
RemoteDate = objRemoteFile.DateLastModified

If LocalDate > RemoteDate Then
objFSO.CopyFile objLocalFile.Path, objRemoteFile.Path, True
End If

Else

objFSO.CopyFile objFile.Name, RemoteDirectory, True

End If

End If

Next

Wscript.Sleep( Seconds * 1000 )

Loop

Re: Cancel Button Problems by billy

billy
Mon Jun 18 09:34:06 CDT 2007

On Jun 18, 9:48 am, inthepickle <inthepic...@gmail.com> wrote:
> This is my script. While running, a window is opened, and refreshed
> every so many seconds. Works great, but I want a button that I can
> use to cancel the script and close the window. I know I can use these
> two commands
> objExplorer.Quit 'close window
> Wscript.Quit 'quit proccess
> but I can't get a html button to call them. Can someone please help
> me and show me how, or give me a better way of doing what I want.
>
> Thanks
>
> On Error Resume Next
> LocalDirectory = "C:\X"
> RemoteDirectory = "D:\X\"
> Seconds = 5
> Minutes = ( Seconds / 60 )
> strComputer = "."
>
> Set objExplorer = CreateObject ( "InternetExplorer.Application" )
> objExplorer.Navigate "about:blank"
> objExplorer.ToolBar = 0
> objExplorer.StatusBar = 0
> objExplorer.Width = 550
> objExplorer.Height = 200
> objExplorer.Visible = 1
> objExplorer.Document.Title = "Script in progress"
>
> Do
> LastRanTime = Now
>
> If Seconds > 59 Then
> objExplorer.Document.Body.InnerHTML = "This script will run every "
> & Minutes & " minutes. <BR> " &_
> "Your script is now being processed and may take several minutes to
> complete. <BR>" &_
> "This script last ran at " & LastRanTime
> Else
> objExplorer.Document.Body.InnerHTML = "This script will run every "
> & Seconds & " seconds. <BR> " &_
> "Your script is now being processed and may take several minutes to
> complete. <BR>" &_
> "This script last ran at " & LastRanTime
> End If
>
> objExplorer.Reload( True )
>
> Set objFSO = CreateObject( "Scripting.FileSystemObject" )
> Set objWMIService = GetObject( "winmgmts:\\" & strComputer & "\root
> \cimv2" )
> Set colFileList = objWMIService.ExecQuery _
> ( "ASSOCIATORS OF {Win32_Directory.Name='" & LocalDirectory & "'}
> Where " & "ResultClass = CIM_DataFile" )
>
> For Each objFile In colFileList
>
> If ucase( objFile.Extension ) = "DXF" Then
>
> RemoteFile = RemoteDirectory & objFile.FileName & "." &
> objFile.Extension
>
> If objFSO.FileExists( RemoteFile ) Then
>
> Set objLocalFile = objFSO.GetFile( objFile.Name )
> LocalDate = objLocalFile.DateLastModified
>
> Set objRemoteFile = objFSO.GetFile( RemoteFile )
> RemoteDate = objRemoteFile.DateLastModified
>
> If LocalDate > RemoteDate Then
> objFSO.CopyFile objLocalFile.Path, objRemoteFile.Path, True
> End If
>
> Else
>
> objFSO.CopyFile objFile.Name, RemoteDirectory, True
>
> End If
>
> End If
>
> Next
>
> Wscript.Sleep( Seconds * 1000 )
>
> Loop

Might i suggest that you move your code to a HTA? An HTA adds IE's
user interface (html tags and text areas) to VBScript's functionality
(so it won't require instancing IE). Start by going the MS
Scriptcenter and downloading the HTA Helpomatic:
http://www.microsoft.com/technet/scriptcenter/createit.mspx

It has several examples that will help you do exactly what you want.