Open files

Welcome Forums General PowerShell Q&A Open files

This topic contains 2 replies, has 3 voices, and was last updated by

 
Senior Moderator
2 months, 1 week ago.

  • Author
    Posts
  • #165370

    Participant
    Topics: 22
    Replies: 15
    Points: 17
    Rank: Member

    What is the best and simplest way to detect the process currently opening a given file?

    Regards

    marius

  • #165379

    Participant
    Topics: 4
    Replies: 10
    Points: 75
    Rank: Member

    for a manual process, I use Process Explorer.  https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

    To do it automated with PowerShell, um um need someone smarter than me.

  • #165400

    Senior Moderator
    Topics: 8
    Replies: 1043
    Points: 3,454
    Helping Hand
    Rank: Community Hero

    You could use handle.exe

    with PowerShell, something like below.

    # Say I've opened a file named test.log
    Get-CimInstance -ClassName Win32_Process -Filter "CommandLine like '%test.log%'"
    
    # This filter is actually applied on CommandLine property of below output
    Get-CimInstance -ClassName Win32_Process | Select-Object -First 1 | Format-List *
    

You must be logged in to reply to this topic.