Hi.
Firstly I am new to making my own commands for VA and writing script for it. I tried reading the documentation, but I don't seem to understand to correct steps to take and feel a bit like an idiot because I can't seem to figure it out.
During my practice I wanted to make commands to open specific applications on my computer, but with the goal of not duplicating code unnecessarily. I made a command that would check if a process is running, if so it would focus the program. If not then it would open the process. This worked fine, but as I want it to work for multiple programs, I wrote a reusable version of the code which would accept the two variables processName and processPath. With the following VB.Net inline script stored in the command 'Start Program':
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Drawing
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Linq
Imports System.Xml.Linq
Imports System.Threading.Tasks
Imports System.Runtime.InteropServices
Public Class VAInline
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
End Function
Public Sub Main()
' Dim processName As String = processName
' Dim processPath As String = processPath
Dim p As Process() = Process.GetProcessesByName(processName)
If p.Count() = 0 Then
Process.Start(processPath)
Else
Dim hWnd As IntPtr = p(0).MainWindowHandle
SetForegroundWindow(hWnd)
End If
End Sub
End Class
Now if I have for example have a new command called 'Whatsapp' and the arguments:
processName: 'Whatapp'
processPath: 'C:\Users\%USERNAME%\AppData\Local\WhatsApp\WhatsApp.exe'
How would I pass these parameters as arguments to the 'Start Program' command from the 'Whatsapp' Command?
Ideally I would want a single command for all Programs with the correct pairing of the processNames and processPaths based in the input word, but baby steps