Force Installation Script to Stop?
Running a VBScript as a deferred action. I want it (based on some condition checking by the vbscript) to fail and terminate the installation. How do I go about doing this?
Also, I was wondering if there is a way to write a "custom" line manually into the log file.. possibly using a session object within a vbscript?
Also, I was wondering if there is a way to write a "custom" line manually into the log file.. possibly using a session object within a vbscript?
0 Comments
[ + ] Show comments
Answers (12)
Please log in to answer
Posted by:
AngelD
15 years ago
#1 then vbscript function return value will handle this, ex.
Function MyFunction()
Const msiDoActionStatusSuccess = 1
Const msiDoActionStatusFailure = 3
If Something_Is_Wrong Then
MyFunction = msiDoActionStatusFailure : Exit Function
End If
MyFunction = msiDoActionStatusSuccess
End Function
#2 Something like this:
msiLog "text that should be logged"
Function msiLog(Message)
Const msiMessageTypeInfo = &H04000000
Dim Record : Set Record = Nothing
Set Record = Session.Installer.CreateRecord(1)
Record.StringData(0) = "CA Log: [1]"
Record.StringData(1) = Message
Session.Message msiMessageTypeInfo, Record
Set Record = Nothing
End Function
Function MyFunction()
Const msiDoActionStatusSuccess = 1
Const msiDoActionStatusFailure = 3
If Something_Is_Wrong Then
MyFunction = msiDoActionStatusFailure : Exit Function
End If
MyFunction = msiDoActionStatusSuccess
End Function
#2 Something like this:
msiLog "text that should be logged"
Function msiLog(Message)
Const msiMessageTypeInfo = &H04000000
Dim Record : Set Record = Nothing
Set Record = Session.Installer.CreateRecord(1)
Record.StringData(0) = "CA Log: [1]"
Record.StringData(1) = Message
Session.Message msiMessageTypeInfo, Record
Set Record = Nothing
End Function
Posted by:
jayteeo
15 years ago
Hi AngelD, Thanks for the response.
I'm not quite following your first answer. Is MyFunction the name of my Custom Action?
Here's what I'm trying to do. This is the VBS inside a CA called "MyCustomAction"
'Dostuff to figure determine if Something_Is_Wrong
If Something_Is_Wrong
'tell Windows Installer that the CA MyCustomAction failed
End If
I'm not quite following your first answer. Is MyFunction the name of my Custom Action?
Here's what I'm trying to do. This is the VBS inside a CA called "MyCustomAction"
'Dostuff to figure determine if Something_Is_Wrong
If Something_Is_Wrong
'tell Windows Installer that the CA MyCustomAction failed
End If
Posted by:
AngelD
15 years ago
You can specify a specific function to call withing the vbscript custom action, in my example that would be the MyFunction function.
If this function returns value 3 the installation will fail
The "if statement" you need to come up with yourself when you want to catch your function to return a failure.
If this function returns value 3 the installation will fail
The "if statement" you need to come up with yourself when you want to catch your function to return a failure.
Posted by:
anonymous_9363
15 years ago
One of the first habits you need to get into is using names which mean something for your CAs, functions, variables and so on. Calling it 'MyCustomAction' means that whoever has to maintain your package at some future point has no clue what it does until he/she opens it to look. Calling it (say) 'TestPresenceOfBlah.EXE' shows its function straight away.
For details on how CAs work, have a read of the 'Custom Action' section on MSDN.
For details on how CAs work, have a read of the 'Custom Action' section on MSDN.
Posted by:
jayteeo
15 years ago
Posted by:
jayteeo
15 years ago
Hi AngelD - Your suggestion didn't seem to work unless I've overlooked something.
This is my CA's embedded script..
***
Function Install_IIS_7()
Const msiDoActionStatusSuccess = 1
Const msiDoActionStatusFailure = 3
'Create Shell Object
'Set Style Property
Dim WindowStyle
WindowStyle = 0 '0 for hidden, 4 to show it
'Set Variables
Dim Executable, Parameters, Path, TempFolder
Executable = "ServerManagerCmd.exe"
Parameters = "-install Web-Server"
TempFolder = Session.Property("CustomActionData")
'Run installation
Set WshShell = CreateObject("WScript.Shell")
ExitCode = WshShell.Run("cmd.exe /c %WinDir%\SysNative\" & Executable & " " & _
Parameters & "> " & TempFolder & "InstallIIS7.txt" , _
WindowStyle, True)
'Delete Temporary file
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(TempFolder & "InstallIIS7.txt") _
And ExitCode = 0 Then
FSO.DeleteFile(TempFolder & "InstallIIS7.txt")
End If
MsgBox("Exit Code: " & ExitCode)
If ExitCode <> 0 Then
Install_IIS_7 = msiDoActionStatusFailure
Else
Install_IIS_7 = msiDoActionStatusSuccess
End If
Set WshShell = Nothing
Set FSO = Nothing
End Function
Install_IIS_7()
****
When ExitCode = 1001, the CA does not fail. What am I missing?
This is my CA's embedded script..
***
Function Install_IIS_7()
Const msiDoActionStatusSuccess = 1
Const msiDoActionStatusFailure = 3
'Create Shell Object
'Set Style Property
Dim WindowStyle
WindowStyle = 0 '0 for hidden, 4 to show it
'Set Variables
Dim Executable, Parameters, Path, TempFolder
Executable = "ServerManagerCmd.exe"
Parameters = "-install Web-Server"
TempFolder = Session.Property("CustomActionData")
'Run installation
Set WshShell = CreateObject("WScript.Shell")
ExitCode = WshShell.Run("cmd.exe /c %WinDir%\SysNative\" & Executable & " " & _
Parameters & "> " & TempFolder & "InstallIIS7.txt" , _
WindowStyle, True)
'Delete Temporary file
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(TempFolder & "InstallIIS7.txt") _
And ExitCode = 0 Then
FSO.DeleteFile(TempFolder & "InstallIIS7.txt")
End If
MsgBox("Exit Code: " & ExitCode)
If ExitCode <> 0 Then
Install_IIS_7 = msiDoActionStatusFailure
Else
Install_IIS_7 = msiDoActionStatusSuccess
End If
Set WshShell = Nothing
Set FSO = Nothing
End Function
Install_IIS_7()
****
When ExitCode = 1001, the CA does not fail. What am I missing?
Posted by:
jayteeo
15 years ago
Posted by:
AngelD
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.