|
Prev: update text file
Next: Disable USD
From: Daz on 25 Jun 2008 14:44 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
From: Tom Lavedas on 25 Jun 2008 15:19 On Jun 25, 2:44 pm, Daz <darren.black...(a)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/
From: Pegasus (MVP) on 25 Jun 2008 15:18 "Daz" <darren.blackley(a)gmail.com> wrote in message news:bc110220-7571-47a0-9253-cd76146bf797(a)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!
From: Daz on 26 Jun 2008 00:41 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
From: Pegasus (MVP) on 26 Jun 2008 18:42
"Daz" <darren.blackley(a)gmail.com> wrote in message news:c975b492-61a9-490b-a9ca-f5b4e4457abb(a)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". |