How to start up an exe with parameters - vb.net

I am new to Visual Basic. I am using VB Premium 2012.
Is there a way I can open/start up an exe file (not my app) with params. I know we can do it in batch coding using echo and stuff. Can it be done in vb?
I want to open up "app.exe" with params as "-login usernamehere passwordhere"

Try this
Dim pHelp As New ProcessStartInfo
pHelp.FileName = "YourApplication.exe"
pHelp.Arguments = "parameter1,parameter2"
pHelp.UseShellExecute = True
pHelp.WindowStyle = ProcessWindowStyle.Normal
Dim proc As Process = Process.Start(pHelp)
I hope this helps...

Related

VB.Net Process.Start - Verb

I want my vb.net Program to launch notepad and elevate the credentials however there is no prompt and the program just opens.
Dim process As System.Diagnostics.Process = Nothing
Dim processStartInfo As System.Diagnostics.ProcessStartInfo
processStartInfo = New System.Diagnostics.ProcessStartInfo()
processStartInfo.FileName = "notepad.exe"
processStartInfo.Verb = "runas"
processStartInfo.Arguments = ""
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
processStartInfo.UseShellExecute = True
process = System.Diagnostics.Process.Start(processStartInfo)
There's a lot of unnecessary code there. You're using two lines to declare and set your two variables when you only need one each time. You're setting the FileName property explicitly when you can pass an argument to the constructor and you're also setting three properties to their default values. I just stripped it down to the bare minimum:
Dim psi As New ProcessStartInfo("notepad.exe") With {.Verb = "runas"}
Dim proc = Process.Start(psi)
When I ran that code from a new WinForms app with just a Button on the form and I got a UAC prompt as expected.

Execute custom ArcGIS model with Visual Basic

I made a function which should execute a custom ArcGIS model.
I use VB 2010 with ArcGIS 10.2. The button which should execute this function is placed on a dockable window.
Dim model As Geoprocessor = New Geoprocessor()
model.AddToolbox("D:\Chris\Van Hall Larenstein\Ruimtelijke Informatie Technologie\RPS\RPS.tbx")
Dim parameters As ESRI.ArcGIS.esriSystem.IVariantArray = New ESRI.ArcGIS.esriSystem.VarArrayClass()
model.Execute("RPS_TEST", parameters, Nothing)
There are no errors reported in VB 2010, but it doesn't work in ArcGIS. What am I doing wrong?
EDIT:
Dim pToolHelper As IGPToolCommandHelper2 = New GPToolCommandHelper
'Set the tool you want to invoke.
Dim toolboxPath = "C:\Program Files\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\Analysis Tools.tbx"
pToolHelper.SetToolByName(toolboxPath, "Buffer")
'Create the messages object to pass to the InvokeModal method.
Dim msgs As IGPMessages
msgs = New GPMessages
'Invoke the tool.
pToolHelper.InvokeModal(0, Nothing, True, msgs)
My.ArcMap.Application.CurrentTool = Nothing
Chris Driessen
If you want user define parameters than this is not the way to do it.
Your code immediately executes the model (without the parameters).
See this link on how to open geoprocessing tool dialog.

VB.Net Printing PDF Fails (But equivalent works from PowerShell)

I'm trying to write a small desktop app that just sits around and prints files as they get downloaded.
Sending a PDF file to the printer with PowerShell works fine and it prints:
.\AcroRd32.exe /N /T C:\Path\to\201402124_label.pdf "Brother QL-700"
However, doing the same in Visual Studio 2012 does not work. The Adobe Reader window opens with the label, and closes, but the file never show up at the printer to be printed. This doesn't make sense because this same code is currently working to send larger PDFs to a duplex printer in the same manner (just using a different printer saved in My.Settings):
For Each file As IO.FileInfo In files
If file.CreationTime > My.Settings.LastRunDate Then
MsgBox(file.Name)
Dim startInfo As New ProcessStartInfo
Dim proc As Process = New Process
startInfo.WindowStyle = ProcessWindowStyle.Hidden
startInfo.Verb = "print"
startInfo.Arguments = My.Settings.LabelPrinterSettings.PrinterName.ToString
startInfo.UseShellExecute = True
startInfo.CreateNoWindow = True
startInfo.FileName = file.FullName
proc.StartInfo = startInfo
proc.Start()
proc.WaitForInputIdle()
proc.CloseMainWindow()
End If
Next
I can't figure out why doing this over the CLI/PowerShell works, but not inside VB.net
Why not simply use Process.Start(String, String)? Much more straight forward and clean. You can then use the returned Diagnostics.Process to run your other commands like WaitForInputIdle().
You would probably use something like this:
Dim proc As Process = Process.Start("AcroRd32.exe", _
String.Format("/N /T {0} ""{1}""", _
"C:\Path\to\201402124_label.pdf", "Brother QL-700")

Run already opened process in vb.net

I have a windows form that, on the click of a button, runs a process (MATLAB) and executes a file.
Dim myProcesses() As Process
myProcesses = Process.GetProcessesByName("Matlab")
If myProcesses.Count > 0 Then
'~~~~ what goes here? ~~~~
Else
Dim startInfo As New ProcessStartInfo
startInfo.FileName = "C:\Program Files\MATLAB\R2011b\bin\matlab.exe"
startInfo.WorkingDirectory = MatlabDir 'MatlabDir is defined elsewhere
startInfo.Arguments = "matlab.exe -r test_plot2"
Process.Start(startInfo)
End If
The above code opens MATLAB and executes the script "test_plot2.m" if MATLAB isn't already open. But what do I write in the first IF statement, if MATLAB is already open, and all I want to do is run the file?
Thanks in advance.
Its supposed to be the same. I mean, it doesn't matter if its opened or not, unless the application (Matlab) manages something different, then you have to guess how. Have you tried just using the same code?
Example:
Dim startInfo As New ProcessStartInfo
startInfo.FileName = "notepad.exe"
startInfo.Arguments = "C:\temp\test.txt"
Process.Start(startInfo)
It doesn't matter if you have Notepad already opened or not.

Run console hidden

I'm trying to run a console window hidden while using CreateProcess(I can't use the ProcessStartInfo class because I have to run it with some other special settings)
I have tried to use the CREATE_NO_WINDOWS flag, but somehow, the console still pops up. This is the code I have:
Dim ProzessInfo = New Process_Information
Dim StartInfo = New Startup_Information, PS = New Security_Flags, TS = New Security_Flags
If CreateProcess(Nothing, target, PS, TS, False, PROCESS_CREATION_FLAG.CREATE_NO_WINDOW, Nothing, Nothing, StartInfo, ProzessInfo) = 0 Then MsgBox("Couln't start application")
What have I missed to run it hidden?
You may want to try
AppwinStyle.Hide, True
MSDN AppWinStyle
Or
EDIT:
Try This for Processes
Dim psi1 As New ProcessStartInfo("file path here")
Process.CreateNoWindow = True
Depending on what your end goal is you can always change the application type to Windows Forms Application. (Assuming you are running a console app now.)