/build/static/layout/Breadcrumb_cap_w.png

Custom Action VBScript

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

Answers (10)

Posted by: MSIPackager 19 years ago
3rd Degree Black Belt
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.

Comments:
  • This fixed a script I was working on, thanks... - PaulSIsaac 10 years ago
Posted by: sini 19 years ago
Orange Senior Belt
0
Thx! Was also my first guess but then I'am getting the error on the second line!
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
Have you defined "TempDir"?
Posted by: sini 19 years ago
Orange Senior Belt
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!
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
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.
Posted by: sini 19 years ago
Orange Senior Belt
0
Thx the problem was that Wshell.run needs a fully qualified path!
Posted by: sini 19 years ago
Orange Senior Belt
0
Another question: How can I include foldervariables like [ProgramFiles] in my embedded code? via session.property?
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
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.
Posted by: sini 19 years ago
Orange Senior Belt
0
thx man!
Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
0
Also, remember that Session.Property() is NOT available if its a deferred custom action. [:(]
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ