title: howto pass procesname parameter to powershell form vbs script
body: <p>If have created a VBS script that watches for new created processes like notepad.exe or calc.exe. When a new notepad or calc proces is found i like to do something in powershell with the found procesname. </p>
  
  <p>The VBS script i created works fine when I manually edit the procesname in the VBS file, but when i try to use/pass the procesname form vbs (strName) to powershell I expect to see the procesname (notepad.exe), but instead the powershell window shows "strName".</p>
  
  <p>I've been all over the internet to find a solution, without result.</p>
  
  <hr>
  
  <h2>My VBS file [start.vbs]</h2>
  
  <p>source: <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2009/11/02/hey-scripting-guy-november-1-2009.aspx" rel="nofollow noreferrer">http://blogs.technet.com/b/heyscriptingguy/archive/2009/11/02/hey-scripting-guy-november-1-2009.aspx</a> </p>
  
  <pre><code>arrProcesses = Array("calc.exe","notepad.exe")
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2")
  i = 0
  
  Set colMonitoredProcesses = objWMIService. ExecNotificationQuery _        
  ("Select * From __InstanceCreationEvent Within 5 Where TargetInstance ISA 'Win32_Process'")
  
  Do While i = 0
  Set objLatestProcess = colMonitoredProcesses.NextEvent
  strProcess = LCase(objLatestProcess.TargetInstance.Name)
  For Each strName in arrProcesses
      If strName = strProcess Then
  
  
  ''Run Powershell file
  'source: https://stackoverflow.com/questions/19156178/passing-arguments-to-powershell
  
  Set WshShell = CreateObject("WScript.Shell")
  
  ''this works great
  WshShell.Run ("Powershell.exe -file .\GetParamFromVBS.ps1 ""notepad.exe"" ")
  
  'this doesnt
  WshShell.Run ("Powershell.exe -file .\GetParamFromVBS.ps1 ""strName"" ")
  
  'OR
  'Trying to work arround it, with no result :(
  RUNPSVAR="(" + """" +"Powershell.exe -file .\GetParamFromVBS.ps1 &amp; """"" +strName +"""""" +""&amp; " " +"""" +")"
  wscript.Echo RUNPSVAR
  
  WshShell.Run ("Powershell.exe -file .\GetParamFromVBS.ps1 ""RUNPSVAR"" ")
  
      End If
  Next
  Loop
  </code></pre>
  
  <hr>
  
  <h2>My Powershell File [GetParamFromVBS.ps1]</h2>
  
  <p>source: <a href="https://stackoverflow.com/questions/1293907/how-to-pass-command-line-arguments-to-a-powershell-ps1-file">How to pass command-line arguments to a PowerShell ps1 file</a></p>
  
  <pre><code>param($p1, $p2, $p3, $p4)
  $Script:args=""
  
  write-host "Num Args: " $PSBoundParameters.Keys.Count
  
  foreach ($key in $PSBoundParameters.keys) {
  $Script:args+= "`$$key=" + $PSBoundParameters["$key"] + "  "
  }
  write-host $Script:args
  
  pause
  </code></pre>
  
  <p>Anyone any ideas?</p>