You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何判断应用程序EXE是否启动?求LabVIEW封装程序验证启动状态

Hey there, let's tackle your two questions step by step—these are really common scenarios when working with Windows applications and LabVIEW, so I've got you covered!

1. 如何识别任意应用程序EXE文件是否已启动?

Depending on whether you need a manual check or a programmable solution, here are the most reliable approaches for Windows systems:

  • Manual Quick Check
    Open Task Manager (press Ctrl+Shift+Esc), go to the Details tab, and look for your target EXE's filename. Alternatively, use Command Prompt:

    tasklist | findstr /i "your_target.exe"
    

    If you see a line with the EXE name and process ID, it's running. The /i flag makes the search case-insensitive.

  • Programmatic Approach (Windows API)
    For code integration, use the Windows Tool Help API. The core steps are:

    1. Call CreateToolhelp32Snapshot to take a snapshot of all running processes.
    2. Use Process32First and Process32Next to iterate through each process in the snapshot.
    3. For each process, extract the executable path (from the szExeFile field in PROCESSENTRY32 structure) and compare it to your target EXE's full path.
      This method is precise because it matches the actual file path, not just the process name (which can have duplicates).
  • PowerShell Script
    A quick scriptable way without low-level API calls:

    Get-Process | Where-Object {$_.Path -eq "C:\Full\Path\To\your_target.exe"}
    

    If this returns a process object, your EXE is running. You can also check by process name with Get-Process -Name "your_target" -ErrorAction SilentlyContinue.

2. 基于LabVIEW的封装程序验证目标EXE是否成功启动

LabVIEW offers two straightforward ways to build this verification tool—here's how to implement both:

方式一:调用Windows API (精准且高效)

This is the most robust method, especially if you need to avoid false positives from same-named processes:

  1. Set up the VI
    Open LabVIEW, create a new VI. Add a string input control for the target EXE's full path, a boolean button labeled "Check Status", and an indicator (like an LED or text box) to show the result.
  2. Configure Windows API Calls
    Use the Call Library Function Node (under Programming -> Connectivity -> Libraries & Executables) to import these Windows APIs:
    • CreateToolhelp32Snapshot
    • Process32First
    • Process32Next
      You'll need to define the correct data types (e.g., PROCESSENTRY32 structure) as per Windows API documentation.
  3. Build the Logic
    • When the "Check Status" button is pressed, take a process snapshot.
    • Iterate through each process, extract its executable path, and compare it to the input path (normalize both to lowercase to avoid case mismatches).
    • Toggle the indicator to show "Running" or "Not Running" based on the match.
  4. Package as EXE
    Go to File -> Build Application (EXE), select your VI as the startup VI, configure any dependencies (like the API call nodes), and build the standalone executable.

方式二:调用系统命令行 (快速实现)

If you want a simpler setup without API configuration:

  1. Use the "Execute System Command" Function
    Drag the Execute System Command function (under Programming -> Dialog & User Interface) onto your block diagram.
  2. Construct the Command
    For Command Prompt:
    tasklist /FI "IMAGENAME eq your_target.exe" /NH
    
    Or for PowerShell:
    powershell Get-Process -Name "your_target" -ErrorAction SilentlyContinue | Select-Object -Property Name
    
  3. Parse the Output
    Capture the command's output string. If it contains your target EXE name, set the indicator to "Running"; otherwise, "Not Running".
  4. Add UI and Package
    Same as the API method: add input controls, a button, indicators, then build the EXE via LabVIEW's application builder.

Key Notes

  • Always use the full file path when possible to avoid matching processes with the same name but different locations.
  • If your target EXE runs with elevated privileges, your LabVIEW tool may need to be run as administrator to detect it.
  • For multiple instances of the EXE, both methods will still correctly identify that at least one instance is running.

内容的提问来源于stack exchange,提问作者Pragadeesh Ravi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:36:44