Hi all,

I am looking for a simple way to wait for a process/function to
finish. I have tried a few combinations of code, however i keep
getting various errors and i am getting frustrated, hence the request
for help.

what i am doing is running a file copy registration function for dll
in vbscript that i need to wait for it to complete before i do the
next function/sub.

--- Example --
Sub Window_OnLoad
copyDLL("test.dll")
nextFunction()
etc
End Sub

Function copyDLL(oFile)
the function stuff
End Function
--- End Example ---

I would like to put some script in place that will wait until the
copyDLL function has completed before doing nextFunction() etc...

I appreciate your help in advance.

Cheers,
Darren

Re: waiting for function/process to finish... by Tom

Tom
Wed Jun 25 14:19:13 CDT 2008

On Jun 25, 2:44 pm, Daz <darren.black...@gmail.com> wrote:
> Hi all,
>
> I am looking for a simple way to wait for a process/function to
> finish. I have tried a few combinations of code, however i keep
> getting various errors and i am getting frustrated, hence the request
> for help.
>
> what i am doing is running a file copy registration function for dll
> in vbscript that i need to wait for it to complete before i do the
> next function/sub.
>
> --- Example --
> Sub Window_OnLoad
> copyDLL("test.dll")
> nextFunction()
> etc
> End Sub
>
> Function copyDLL(oFile)
> the function stuff
> End Function
> --- End Example ---
>
> I would like to put some script in place that will wait until the
> copyDLL function has completed before doing nextFunction() etc...
>
> I appreciate your help in advance.
>
> Cheers,
> Darren

That's not enough info for me (at least) to provide any response.
Script functions run synchronously, unless a new thread is being
created with something like a Run or Exec. That's the part that needs
to be examined to be able to respond. I think you will need to show
more of the code of "the function stuff" for anyone to respond, I
think.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: waiting for function/process to finish... by Pegasus

Pegasus
Wed Jun 25 14:18:49 CDT 2008


"Daz" <darren.blackley@gmail.com> wrote in message
news:bc110220-7571-47a0-9253-cd76146bf797@h1g2000prh.googlegroups.com...
> Hi all,
>
> I am looking for a simple way to wait for a process/function to
> finish. I have tried a few combinations of code, however i keep
> getting various errors and i am getting frustrated, hence the request
> for help.
>
> what i am doing is running a file copy registration function for dll
> in vbscript that i need to wait for it to complete before i do the
> next function/sub.
>
> --- Example --
> Sub Window_OnLoad
> copyDLL("test.dll")
> nextFunction()
> etc
> End Sub
>
> Function copyDLL(oFile)
> the function stuff
> End Function
> --- End Example ---
>
> I would like to put some script in place that will wait until the
> copyDLL function has completed before doing nextFunction() etc...
>
> I appreciate your help in advance.
>
> Cheers,
> Darren

It all depends on how you code the copyDLL function. Let's
have a look at your code!



Re: waiting for function/process to finish... by Daz

Daz
Wed Jun 25 23:41:36 CDT 2008

Const ForReading = 1
strCount = 0
strComputer = "."
Set ObjWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
\root\cimv2")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Act = CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")


Sub Main
If window.external.argv(1) = "" Then
help
ElseIf FSO.GetFile(cfgfile).Size > 0 Then
Call Update_Services
Else
InvalidFile
End If
CheckActiveX("ZProgBar.ocx")
iTimerID = window.setInterval("Display_Progress", strCount)
Call Display_Progress
End Sub

Sub Display_Progress
If ProgressBar1.Value = ProgressBar1.Max Then
window.clearInterval(iTimerID)
self.close
Else
ProgressBar1.Value = ProgressBar1.Value + 1
End If
End Sub

Sub Update_Services
Set objTextFile = FSO.OpenTextFile(cfgfile, ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = Trim(objTextFile.Readline)
If (strNextLine <> "") Then
arrServiceList = Split(strNextLine , ",")
Set colListOfServices = objWMI.ExecQuery("Select * from
Win32_Service Where Name ='" &_
Trim(LCase(arrServiceList(0))) & "'")
For Each objService In colListOfServices
objService.ChangeStartMode(Trim(LCase(arrServiceList(1))))
If Trim(LCase(arrServiceList(1))) <> "automatic" Then
objService.StopService()
If Trim(LCase(arrServiceList(1))) = "automatic" Then
objService.StartService()
Next
strCount = strCount + 1
End If
Loop
End Sub

Function CheckActiveX(objX)
sysDir = window.external.GetSystemDirectory()
oActive = window.external.FindResource(objX)
If Fso.FileExists(sysDir & objX) Then
' Nothing to be done :D '
Else
window.external.CopyResourceToFile oActive, sysDir
'Act.run "RegSvr32 /s " & sysDir & oActive, 0, True
window.external.DllRegisterServer sysDir & "\" & objX
End If
End Function

Sub Window_Onload
StyleIT
idTimer = window.setTimeout("Main", 200, "VBScript")
End Sub

Re: waiting for function/process to finish... by Pegasus

Pegasus
Thu Jun 26 17:42:02 CDT 2008


"Daz" <darren.blackley@gmail.com> wrote in message
news:c975b492-61a9-490b-a9ca-f5b4e4457abb@w8g2000prd.googlegroups.com...
> Const ForReading = 1
> strCount = 0
> strComputer = "."
> Set ObjWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
> \root\cimv2")
> Set FSO = CreateObject("Scripting.FileSystemObject")
> Set Act = CreateObject("Wscript.Shell")
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> \cimv2")
>
>
> Sub Main
> If window.external.argv(1) = "" Then
> help
> ElseIf FSO.GetFile(cfgfile).Size > 0 Then
> Call Update_Services
> Else
> InvalidFile
> End If
> CheckActiveX("ZProgBar.ocx")
> iTimerID = window.setInterval("Display_Progress", strCount)
> Call Display_Progress
> End Sub
>
> Sub Display_Progress
> If ProgressBar1.Value = ProgressBar1.Max Then
> window.clearInterval(iTimerID)
> self.close
> Else
> ProgressBar1.Value = ProgressBar1.Value + 1
> End If
> End Sub
>
> Sub Update_Services
> Set objTextFile = FSO.OpenTextFile(cfgfile, ForReading)
> Do Until objTextFile.AtEndOfStream
> strNextLine = Trim(objTextFile.Readline)
> If (strNextLine <> "") Then
> arrServiceList = Split(strNextLine , ",")
> Set colListOfServices = objWMI.ExecQuery("Select * from
> Win32_Service Where Name ='" &_
> Trim(LCase(arrServiceList(0))) & "'")
> For Each objService In colListOfServices
> objService.ChangeStartMode(Trim(LCase(arrServiceList(1))))
> If Trim(LCase(arrServiceList(1))) <> "automatic" Then
> objService.StopService()
> If Trim(LCase(arrServiceList(1))) = "automatic" Then
> objService.StartService()
> Next
> strCount = strCount + 1
> End If
> Loop
> End Sub
>
> Function CheckActiveX(objX)
> sysDir = window.external.GetSystemDirectory()
> oActive = window.external.FindResource(objX)
> If Fso.FileExists(sysDir & objX) Then
> ' Nothing to be done :D '
> Else
> window.external.CopyResourceToFile oActive, sysDir
> 'Act.run "RegSvr32 /s " & sysDir & oActive, 0, True
> window.external.DllRegisterServer sysDir & "\" & objX
> End If
> End Function
>
> Sub Window_Onload
> StyleIT
> idTimer = window.setTimeout("Main", 200, "VBScript")
> End Sub

I'm probably a bit dense but I don't really understand your
program. Here are some of the things that confuse me:
- What is behind the reference to
"window.external.CopyResourceToFile oActive, sysDir"?
- If you want to copy a file, why not use the FS object?
- You declare "sub main" but you never call it. How does
your program start? What is the purpose of putting the
main program into a subroutine?
- You refer to "InvalidFile" but there is no function/subroutine
of this name. How does it work?
- Same for "StyleIt".



Re: waiting for function/process to finish... by Tom

Tom
Thu Jun 26 20:16:19 CDT 2008

On Jun 26, 6:42=A0pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "Daz" <darren.black...@gmail.com> wrote in message
>
> news:c975b492-61a9-490b-a9ca-f5b4e4457abb@w8g2000prd.googlegroups.com...
>
>
>
> > Const ForReading =3D 1
> > strCount =3D 0
> > strComputer =3D "."
> > Set ObjWMI =3D GetObject("winmgmts:{impersonationLevel=3Dimpersonate}!\=
\.
> > \root\cimv2")
> > Set FSO =3D CreateObject("Scripting.FileSystemObject")
> > Set Act =3D CreateObject("Wscript.Shell")
> > Set objWMIService =3D GetObject("winmgmts:\\" & strComputer & "\root
> > \cimv2")
>
> > Sub Main
> > If window.external.argv(1) =3D "" Then
> > help
> > ElseIf FSO.GetFile(cfgfile).Size > 0 Then
> > Call Update_Services
> > Else
> > InvalidFile
> > End If
> > CheckActiveX("ZProgBar.ocx")
> > =A0iTimerID =3D window.setInterval("Display_Progress", strCount)
> > =A0Call Display_Progress
> > End Sub
>
> > Sub Display_Progress
> > If ProgressBar1.Value =3D ProgressBar1.Max Then
> > =A0window.clearInterval(iTimerID)
> > =A0 self.close
> > Else
> > =A0ProgressBar1.Value =3D ProgressBar1.Value + 1
> > End If
> > End Sub
>
> > Sub Update_Services
> > Set objTextFile =3D FSO.OpenTextFile(cfgfile, ForReading)
> > Do Until objTextFile.AtEndOfStream
> > =A0 =A0strNextLine =3D Trim(objTextFile.Readline)
> > =A0 =A0If (strNextLine <> "") Then
> > =A0 =A0 =A0arrServiceList =3D Split(strNextLine , ",")
> > =A0 =A0 =A0 Set colListOfServices =3D objWMI.ExecQuery("Select * from
> > Win32_Service Where Name =3D'" &_
> > =A0 =A0 Trim(LCase(arrServiceList(0))) & "'")
> > For Each objService In colListOfServices
> > =A0 objService.ChangeStartMode(Trim(LCase(arrServiceList(1))))
> > If Trim(LCase(arrServiceList(1))) <> =A0"automatic" Then
> > objService.StopService()
> > If Trim(LCase(arrServiceList(1))) =3D =A0"automatic" Then
> > objService.StartService()
> > Next
> > strCount =3D strCount + 1
> > =A0 =A0End If
> > Loop
> > End Sub
>
> > Function CheckActiveX(objX)
> > sysDir =3D window.external.GetSystemDirectory()
> > oActive =3D window.external.FindResource(objX)
> > If Fso.FileExists(sysDir & objX) Then
> > ' Nothing to be done :D '
> > =A0Else
> > =A0window.external.CopyResourceToFile oActive, sysDir
> > =A0'Act.run "RegSvr32 /s " & sysDir & oActive, 0, True
> > =A0window.external.DllRegisterServer sysDir & "\" & objX
> > =A0End If
> > End Function
>
> > Sub Window_Onload
> > StyleIT
> > idTimer =3D window.setTimeout("Main", 200, "VBScript")
> > End Sub
>
> I'm probably a bit dense but I don't really understand your
> program. Here are some of the things that confuse me:
> - What is behind the reference to
> =A0 "window.external.CopyResourceToFile oActive, sysDir"?
> - If you want to copy a file, why not use the FS object?
> - You declare "sub main" but you never call it. How does
> =A0 =A0your program start? What is the purpose of putting the
> =A0 =A0main program into a subroutine?
> - You refer to "InvalidFile" but there is no function/subroutine
> =A0 =A0of this name. How does it work?
> - Same for "StyleIt".

This doesn't appear to be VBS under WSH. Rather, the reference to
'window' suggest some form of an HTML-like host - or possibly .Net.

Tom Lavedas
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Re: waiting for function/process to finish... by Paul

Paul
Mon Jun 30 19:09:35 CDT 2008


"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:52629681-cbf3-4e0d-8b90-28cd3fcd6ad3@k37g2000hsf.googlegroups.com...
On Jun 26, 6:42 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "Daz" <darren.black...@gmail.com> wrote in message
>
> news:c975b492-61a9-490b-a9ca-f5b4e4457abb@w8g2000prd.googlegroups.com...
>
>
>
> > Const ForReading = 1
> > strCount = 0
> > strComputer = "."
> > Set ObjWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
> > \root\cimv2")
> > Set FSO = CreateObject("Scripting.FileSystemObject")
> > Set Act = CreateObject("Wscript.Shell")
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> > \cimv2")
>
> > Sub Main
> > If window.external.argv(1) = "" Then
> > help
> > ElseIf FSO.GetFile(cfgfile).Size > 0 Then
> > Call Update_Services
> > Else
> > InvalidFile
> > End If
> > CheckActiveX("ZProgBar.ocx")
> > iTimerID = window.setInterval("Display_Progress", strCount)
> > Call Display_Progress
> > End Sub
>
> > Sub Display_Progress
> > If ProgressBar1.Value = ProgressBar1.Max Then
> > window.clearInterval(iTimerID)
> > self.close
> > Else
> > ProgressBar1.Value = ProgressBar1.Value + 1
> > End If
> > End Sub
>
> > Sub Update_Services
> > Set objTextFile = FSO.OpenTextFile(cfgfile, ForReading)
> > Do Until objTextFile.AtEndOfStream
> > strNextLine = Trim(objTextFile.Readline)
> > If (strNextLine <> "") Then
> > arrServiceList = Split(strNextLine , ",")
> > Set colListOfServices = objWMI.ExecQuery("Select * from
> > Win32_Service Where Name ='" &_
> > Trim(LCase(arrServiceList(0))) & "'")
> > For Each objService In colListOfServices
> > objService.ChangeStartMode(Trim(LCase(arrServiceList(1))))
> > If Trim(LCase(arrServiceList(1))) <> "automatic" Then
> > objService.StopService()
> > If Trim(LCase(arrServiceList(1))) = "automatic" Then
> > objService.StartService()
> > Next
> > strCount = strCount + 1
> > End If
> > Loop
> > End Sub
>
> > Function CheckActiveX(objX)
> > sysDir = window.external.GetSystemDirectory()
> > oActive = window.external.FindResource(objX)
> > If Fso.FileExists(sysDir & objX) Then
> > ' Nothing to be done :D '
> > Else
> > window.external.CopyResourceToFile oActive, sysDir
> > 'Act.run "RegSvr32 /s " & sysDir & oActive, 0, True
> > window.external.DllRegisterServer sysDir & "\" & objX
> > End If
> > End Function
>
> > Sub Window_Onload
> > StyleIT
> > idTimer = window.setTimeout("Main", 200, "VBScript")
> > End Sub
>
> I'm probably a bit dense but I don't really understand your
> program. Here are some of the things that confuse me:
> - What is behind the reference to
> "window.external.CopyResourceToFile oActive, sysDir"?
> - If you want to copy a file, why not use the FS object?
> - You declare "sub main" but you never call it. How does
> your program start? What is the purpose of putting the
> main program into a subroutine?
> - You refer to "InvalidFile" but there is no function/subroutine
> of this name. How does it work?
> - Same for "StyleIt".

This doesn't appear to be VBS under WSH. Rather, the reference to
'window' suggest some form of an HTML-like host - or possibly .Net.


I'm thinking it is run under an IE host. One reference I found to
window.external was this:
http://support.microsoft.com/kb/q183339/. Maybe recent IE versions have
more methods available.

-Paul Randall