Hi everyone!

I am trying to implement a custom action using embedded VB Scriptcode! I just copied the contents of the .vbs file which works fine outside windows installer into the textbox of the custom action(i am using wise). However there seems to be a problem with these lines:

Set WshShell = WScript.CreateObject("WScript.Shell")
...
Call WshShell.Run("osql -n -s. -E -i""" + TempDir + "\RtInstall_AttachDb.sql"" -o""" + TempDir + "\RtInstall_AttachDb.sql.log""",0,true)

Does anyone know how to correctly call some external program from embedded vbscript code?
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Try this [:)]

Change:
Set WshShell = WScript.CreateObject("WScript.Shell")

To:
Set WshShell = CreateObject("WScript.Shell")

For More Info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/s

Regards,
Rob.
Answered 08/30/2005 by: MSIPackager
Third Degree Black Belt

  • This fixed a script I was working on, thanks...
Please log in to comment
0
Thx! Was also my first guess but then I'am getting the error on the second line!
Answered 08/30/2005 by: sini
Orange Senior Belt

Please log in to comment
0
Have you defined "TempDir"?
Answered 08/30/2005 by: WiseUser
Fourth Degree Brown Belt

Please log in to comment
0
Here's the code:

Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Set fso = CreateObject("Scripting.FileSystemObject")

InstallDir = session.property("INSTALLDIR")

'Temporären Pfad ermitteln
TempDir = fso.GetSpecialFolder(2)

'Create Script
Set tempFile = fso.CreateTextFile(TempDir + "\RtInstall_AttachDb.sql", true)
tempFile.WriteLine("USE master")
tempFile.WriteLine("")
tempFile.WriteLine("declare @ProgramDir VarChar(1024)")
tempFile.WriteLine("declare @DataFile VarChar(1024)")
tempFile.WriteLine("declare @IndexFile VarChar(1024)")
tempFile.WriteLine("declare @LogFile VarChar(1024)")
tempFile.WriteLine("")
tempFile.WriteLine("set @DataFile = '" + InstallDir + "\DB\NOEV_Rechentool_Data.mdf'")
tempFile.WriteLine("set @IndexFile = '" + InstallDir + "\DB\NOEV_Rechentool_Index.ndf'")
tempFile.WriteLine("set @LogFile = '" + InstallDir + "\DB\NOEV_Rechentool_Log.ldf'")
tempFile.WriteLine("")
tempFile.WriteLine("exec dbo.sp_attach_db @dbname = 'NOEV_Rechentool', ")
tempFile.WriteLine(" @filename1 = @DataFile,")
tempFile.WriteLine(" @filename2 = @IndexFile,")
tempFile.WriteLine(" @filename3 = @LogFile")
tempFile.WriteLine("")
tempFile.Close

'Run script
msgbox "osql -n -s. -E -i""" + TempDir + "\RtInstall_AttachDb.sql"" -o""" + TempDir + "\RtInstall_AttachDb.sql.log"""
Call WshShell.Run("osql -n -s. -E -i""" + TempDir + "\RtInstall_AttachDb.sql"" -o""" + TempDir + "\RtInstall_AttachDb.sql.log""",0,true)
fso.DeleteFile(TempDir + "\RtInstall_AttachDb.sql")

When I enter the string that is displayed in the messagebox via commandline it works! The script attaches a database to the msde!
Answered 08/30/2005 by: sini
Orange Senior Belt

Please log in to comment
0
Is the action running under your account, or deferred as system?

I'd try making this visible by changing ",0,true)" to ",5,true)".

I'd also try adding the full path and file extension to the "osql" tool. In fact, I'd try hard-coding the entire command line at first - just to make sure that it works... then I'd start to add my variables.

I'd also use an inputbox to message out the command line so I could copy and paste it exactly into a cmd window.
Answered 08/30/2005 by: WiseUser
Fourth Degree Brown Belt

Please log in to comment
0
Thx the problem was that Wshell.run needs a fully qualified path!
Answered 08/30/2005 by: sini
Orange Senior Belt

Please log in to comment
0
Another question: How can I include foldervariables like [ProgramFiles] in my embedded code? via session.property?
Answered 08/30/2005 by: sini
Orange Senior Belt

Please log in to comment
0
You can use the session object if it's available ("ProgramFilesFolder").

Session.Property("ProgramFilesFolder")
Me.Property("ProgramFilesFolder")
Property("ProgramFilesFolder")

Otherwise, you can read it from here:
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir"

It's also got an environment variable ("%ProgramFiles%") which you can use under certain circumstances (such as running commands).[;)]

WshShell.Run Chr(34) & "%ProgramFiles%\MyApp\MyApp.exe" & Chr(34)

You can read the value of this variable using the "session" object too:

Session.Property("%ProgramFiles")
Me.Property("%ProgramFiles")
Property("%ProgramFiles")

Hope this helps.
Answered 08/30/2005 by: WiseUser
Fourth Degree Brown Belt

Please log in to comment
0
thx man!
Answered 08/30/2005 by: sini
Orange Senior Belt

Please log in to comment
0
Also, remember that Session.Property() is NOT available if its a deferred custom action. [:(]
Answered 08/31/2005 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
Answer this question or Comment on this question for clarity