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?
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)
Please log in to answer
Posted by:
MSIPackager
19 years ago
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.
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
Posted by:
sini
19 years ago
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!
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
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.
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
Posted by:
WiseUser
19 years ago
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.
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).[;)]
You can read the value of this variable using the "session" object too:
Me.Property("%ProgramFiles")
Property("%ProgramFiles")
Hope this helps.
Posted by:
brenthunter2005
19 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.