InstallShield - How to run installer using custom actions (VB script) - vb.net

I have a package which binds my product and MATLAB run time as a dependency. The dependency should be installed only if its not present in target machine. I have selected deferred execution of a VB script (It should fire after File transfer).
Here's the code:
public function MatlabCheck()
Dim MATLABVal
MATLABVal = Session.property("MATLABROOT")
If Len(MATLABVal) = 0 Then
Set objShell = CreateObject("WScript.shell")
Dim cmd
cmd = Session.Property("INSTALLDIR\v1.0\dependencies\MCR_R2013b_win32_installer.exe")
objShell.run cmd
end if
end function
Note that I have put MATLABROOT property under Additional Requirements.
Using InstallShield Limited Edition on VS 2013.
I tried running this setup with the script integrated, however, it didn't work.

Related

How to call java object in VBA with classpath

We use a CMD to call a PowerShell script. In the PowerShell script, a Java program is called. Both files are in the same directory. I want this all replaced by VBA within Microsoft Access. I have found several related topics but I can't decide whether it is possible or not based on these topics. Topics like Launch jar file from VBA code
The CMD contains the following code:
SET CLASSPATH=.\yyyyy.jar
powershell .\startscript.ps1
The PowerShell script contains the following sample:
& java '-Djavax.net.ssl.trustStore="zzzz.keystore"' com.router.router.router.Router -user:... etc.
We also run the same Java program in a different setting, only with the use of one .CMD-file. This is made like:
SET USR=user
SET CLASSPATH=.\yyyyy.jar
java -Djavax.net.ssl.trustStore=zzzz.keystore com.router.router.router.Router -user:%USR% etc.
Preferably both PowerShell and CMD become obsolete and the parameters like "-user" are fed with variables from the VBA code.
Does someone have a usable link, example or code? Please advice.
What you are trying to do is to run a command via the command line. It just happens that this command runs java, as far as the VBA code is concerned it may run anything that the shell would understand.
A sample code to run a command via a shell in VBA is the following (note there are many ways and it's super easy to find these samples on internet, I'm just using the first one I found):
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = False
Dim windowStyle As Integer: windowStyle = 1
wsh.Run "cmd.exe /S /C " & yourCommand
... where yourCommand is the litteral string you would run in your command prompt. Now, it's all about string concatenation in VBA. Following your sample (and adding the username directly from VBA):
user = Environ("UserName")
yourCommand = "java -Djavax.net.ssl.trustStore=zzzz.keystore com.router.router.router.Router -user:" & user
(please note that I replaced %USR% - which asks the shell to retrieve the username - with a variable user that I've defined in VBA, even though in this specific example, the function Environ is asking environment variables so it's still asking it to a shell).

Import-Module not working from within WinForms Application

I have a VB.net app where I invoke Import-Module on a PowerShell from within my vb.net Window Application but the error says it could not find the module. Error as below.
Import-Module : The specified module 'MSOnline' was not loaded because no valid module file was found in any module directory.
When I load the same Module by launching the PowerShell externally in the usual way it works fine. Image as below.
The VB script is as below
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = True
.FileName = "powershell.exe"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
Dim psscript As String = My.Resources.mymsolPS
procStartInfo.Arguments = psscript
procExecuting = Process.Start(procStartInfo)
End With
End Sub
My PowerShell Script is saved in my.resource as a txt file. My PowerShell Script is as below.
Import-Module Msonline
Connect-msolService
I replaced the PowerShell script to Get-Help and that works only it dosnt work when I use Import-Module Msonline.
One more information that can be shared is the module is stored in the below location.
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\MSOnline\MSOnline.psd1
Any Help is greatly appreciated.
Thanks in Advance
Update 2:
More fiddling with it found some thing which i am not sure if is relevant.
If I launch the powershell from within my VB.net and run the below command I cant see the MSOnline module.
PS C:\windows\system32>> cd $env:WINDIR\System32\WindowsPowerShell\v1.0\Modules\
PS C:\windows\System32\WindowsPowerShell\v1.0\Modules>> dir
If I run the PowerShell directly from my system and run the above script I can see the Module
d----- 11/22/2017 2:59 PM MSOnline
Still a mystery for me which I cant crack. :(
A difference I notice is when launching from your app, or locally, the directory is either your user, or system.. so maybe the way PS is being loaded it can't find the module.
What about if you provide a full path to the module?
I've had much better luck using RunSpace - I use it to pass any powershell commands - here are a snippet from one of the sites and some examples to look at:
'Create the runspace.
Using R As System.Management.Automation.Runspaces.Runspace = _
System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()
'Create the pipeline
Using P As System.Management.Automation.Runspaces.Pipeline = R.CreatePipeline()
'Open the runspace.
R.Open()
'Create each command (in this case just one)...
Dim Cmd As New System.Management.Automation.Runspaces.Command("C:\script.ps1", True)
'...and add it to the pipeline.
P.Commands.Add(Cmd)
'Execute the commands and get the response.
Dim Result As System.Collections.ObjectModel.Collection(Of _
System.Management.Automation.PSObject) = P.Invoke()
'Close the runspace.
R.Close()
'Display the result in the console window.
For Each O As System.Management.Automation.PSObject In Result
Console.WriteLine(O.ToString())
Next
End Using
End Using
http://www.winsoft.se/2009/08/execute-a-cmdlet-or-ps1-script-from-visual-basic/
https://social.msdn.microsoft.com/Forums/vstudio/en-US/5d2279c8-e02c-45eb-a631-951c56067bb5/run-powershell-script-from-vbnet?forum=vbgeneral
https://code.msdn.microsoft.com/windowsdesktop/VBPowerShell-6b4f83ea
The last one provides a pretty solid breakdown of what it's doing. Let me know if you can't get it to work, I can try to see if this import works on an app.
I actually found the solution after hours of pain. This is pretty silly solution.
Went I went to my application Properties I found that the Preferred run was set to 32 bit hence when my PowerShell was launched from within it was looking for the module under SYSWOW where its suppose to look it under System32. I unchecked the "Preferred 32 BIT" and not it imports the module from system 32.
Thought I should share this silly miss so that others should not suffer the same.

"The system cannot find the file specified" error running Ant from VB.NET

I'm trying to run a Python application word2html using Apache Ant through a VB project. The following bit of code called for the executable.
//in loop
If (Not ExecuteProgram("ant", "word2html", True)) Then
Throw New System.Exception("couldn't run word2html")
End If
//executeprogram function
Public Function ExecuteProgram(ByVal ExeLoc As String, ByVal ExeArgs As String, ByVal bSynch As Boolean) As Boolean
'The exefile location is passed in along with a boolean value of whether to
'execute the file syncronously or asynchronously
Try
Dim MyInstance As New System.Diagnostics.Process
Dim si As New ProcessStartInfo(ExeLoc, ExeArgs)
MyInstance.StartInfo = si
MyInstance.Start()
If bSynch Then
'run synch
MyInstance.WaitForExit()
End If
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
The code ran successfully a couple weeks ago, but it now fails with the following error message:
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at ConsoleApplication1.Hello.ExecuteProgram(String ExeLoc, String ExeArgs, Boolean bSynch)
in
C:\Users\shwang\Desktop\svn\trunk\data\data_loading\scripts\data_sheet
_scripts\Pipeline\ProcessDatasheetPipeline\Module1.vb:line 349
When I run ant word2html from the cmd window, it runs successfully.
I suspect it's my working environment that's changed I've checked that the ANT_HOME and JAVA_HOME variable are correct and included in the PATH environment variable. What other dependencies should I be checking? I'm currently using Microsoft VB 2010 Express as my IDE.
ant is actually a batch script, not an executable. That's why the error message is "The system cannot find the file specified". Windows cannot find an executable named ant.
You can use cmd.exe with its /c option to run the batch script:
If (Not ExecuteProgram("cmd.exe", "/c ant word2html", True)) Then

How to open the SCCM Configuration Manager in VB - Visual Studio 2015

I'm creating a tool in VB using Visual Studio 2015 and I'm having some issues with forcing one item on a menu strip when clicked to open the SCCM Configuration Manager.
So far I've tried:
Option 1
Dim ProcID As Integer
ProcID = Shell("control smscfgrc", AppWinStyle.NormalFocus)
Option 2
Process.Start("cmd.exe", "control smscfgrc")
Option 3
Dim p as Process = new Process()
Dim pi as ProcessStartInfo = new ProcessStartInfo()
pi.Arguments = "control smscfgrc"
pi.FileName = "cmd.exe"
p.StartInfo = pi
Option 4
Shell=("control smscfgrc", 0)
None of the above work, they just open the console but nothing else.
If I open a regular cmd window using "windows + R" and type the command "control smscfgrc" it open the SCCM Configuration Manager as it should.
I really need this to complete my tool, any help is much appreciated!
Thank you for the time you took to read this.
I'm not a guru with VS nor VB, but your commands to open cmd.exe looks incorrect. You need to add a /c. The command in the Run window ( + R) would look like this ...
cmd.exe /c control smscfgrc
Of course, control is actually control.exe, so you don't even need cmd.exe:
control.exe smscfgrc
Tested and confirmed that this opens the Configuration Manager Properties window from the Run windows on my computer.
You also may need the full path to control.exe. I would use environment variables; I think this is how it would be done in VB:
Dim control_exe As String
control_exe = Environment.GetEnvironmentVariable("SystemRoot") & "\System32\control.exe"
You will automatically get redirected to SysWOW64 if running on as a 32-bit process on a 64-bit OS.
Option 2
Process.Start(control_exe, "smscfgrc")
Option 3
Dim p as Process = new Process()
Dim pi as ProcessStartInfo = new ProcessStartInfo()
pi.Arguments = "smscfgrc"
pi.FileName = control_exe
p.StartInfo = pi

The x command does not correctly when invoked under SASWorkspaceManager.WorkspaceManager?

I have written some SAS code that calls R via the x command (I am using SAS 9.1.3 so there is no native SAS interface to R).
OPTIONS XWAIT XSYNC;
X """&r_path."" --no-save --quiet < ""&out_code_folder.\code.r"" > ""&out_code_folder.\abba.log""";
This code works correctly when I run it in the SAS IDE but when I try to run the same code in VBA using (here strSAScode contains the above mentioned SAS code).
Dim obWM As SASWorkspaceManager.WorkspaceManager
Dim temp_dispaly_alert As Boolean
Dim sm As SAS_Management
Debug.Print strSASCode
Set sm = New SAS_Management
'Set obServerDef = New SASWorkspaceManagerServerDef
Set obWM = New SASWorkspaceManager.WorkspaceManager
Set obSAS = obWM.Workspaces.CreateWorkspaceByServer("MyServerName", VisibilityProcess, Nothing, "", "", "")
Set sm.obLS = obSAS.LanguageService
temp_dispaly_alert = Application.DisplayAlerts
Application.DisplayAlerts = False
sm.obLS.Submit strSASCode
Now every other code works, except the x command. Please Help.
By default, use of SYSTEM and X commands is disabled when accessed via techniques that use integration technologies due to potential security risks.
Have you followed the steps for 9.1.3 on Windows described in this usage note?
It describes how to enable this functionality on your SAS server; you may need to adapt what's described for the workspace, instead of the stored process, server.