kumarkiranc
Posts: 85
Joined: Tue Sep 18, 2007 6:49 am

Problem

Hi,

Iam trying to stop the service using vbscript. When i run outside the advance installer the service is stopping. When i run through the custom action in it is not working.

Wscript.sleep 1000 is not working in advance installer

Thanks
Kiran
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

Note that the installer runs script Custom Actions directly and does not use the Windows Script Host. Therefore, the WScript object cannot be used inside a script Custom Action because this object is provided by the Windows Script Host.

Note that Advanced Installer allows you to stop a service by using a Control Operation in the "Services" page.
http://www.advancedinstaller.com/user-g ... rties.html

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,

You can use WScript.Sleep from your VBScript Custom Action through the following hack:
1. Your VBScript CA will create a temporary file (with a .vbs extension).
2. The CA will write WScript.Sleep interval in the temporary file created previously.
3. The CA will launch the temporary .vbs file using the command wscript.exe TempFile.tmp.vbs
4. The CA will delete the temp .vbs file.

The Delay and DelayHelper functions below illustrate the above method, while the DelayTest function (it can be added as a Custom Action) illustrates how the Delay function can be used.

Code: Select all

Function DelayTest()
  MsgBox "Delaying for 5 seconds..."
  Delay(5000)
  MsgBox "Done!"  
End Function

Function Delay(interval)
  Dim delayCmd
  delayCmd = "WScript.Sleep " & CStr(interval)
  DelayHelper(delayCmd)
End Function

Function DelayHelper(strContent)  
  Const TemporaryFolder = 2
  Dim fso, WshShell
  Dim tempFolder, tempName, tempFullPath, tempFile
  Dim strCmd, ret

  Set fso = CreateObject("Scripting.FileSystemObject")
  Set WshShell = CreateObject("WScript.Shell")
  Set tempFolder = fso.GetSpecialFolder(TemporaryFolder)

  tempName = fso.GetTempName
  tempFullPath = fso.BuildPath(tempFolder, tempName)
  
  Set tempFile = fso.CreateTextFile(tempFullPath, True)
  tempFile.WriteLine(strContent)
  tempFile.Close
  
  ' append a vbs extension
  fso.MoveFile tempFullPath, tempFullPath & ".vbs"
  tempFullPath = tempFullPath & ".vbs"

  ' execute the temp vbs file using the wscript interpreter
  strCmd = "wscript.exe " & chr(34) & tempFullPath & chr(34)
  
  ' MsgBox strCmd
  ret = WshShell.Run(strCmd, 1, true)
  
  ' delete the temp file
  Set tempFile = fso.GetFile(tempFullPath)
  tempFile.Delete
End Function
Hope this helps.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
jusher
Posts: 174
Joined: Thu Dec 22, 2011 12:00 pm

Re: Problem

Yes I found this hack on the internet. What i am trying to do is create all of the files required by the service, which I cannot do until the folders are installed through the installation. I have a CA which then starts the service. My problem now is where I choose modify. I want to wait for service STOPPED message from the sc query command output to a text file. I use the delay hack to wait 15 seconds. If I identify STOPPED the I want to restart service. Otherwise I delay a while and retry 100 times before giving up. The point is that the service start is not occuring every time.
I am checking if Session.Property("InstallMode") = "Change" to then stop and query status before starting the service. The start is outside the above mention select so it will run on both install and modify.
Is this property the best one to check?
Regards, John
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Problem

Hello John,

I'm afraid I don't fully understand your scenario. If you want to detect if your installation package run on "Modify" mode, then you should check if the following condition is true:
  • AI_INSTALL_MODE = "Change"
Let us know if this helps, otherwise give us more details about your scenario (maybe exemplify).

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”