powershellcmddllattributesget-childitem

How can I check for the presence of .DLL files using cmd.exe or PowerShell, without changing permissions?


How can I check for the presence of these https://bugzilla.mozilla.org/show_bug.cgi?id=1841751#c4 .DLL files in C:\ProgramData and child containers, using cmd.exe or PowerShell?

Preferably one-liners rather that scripts.

Without changing access permissions of any files or folders. (When using explorer I would have to change the permissions).

Have not tried anything yet as I am not sure what to do exactly, or if it will do something irreversible. Not even sure if this would show the attributes for the DLLs without the need to change permissions. Thought of using Get-Childitem, but this:- Get file version and assembly version of DLL files in the current directory and all sub directories says items stay loaded and can't be deleted "unfortunately it loads the files and never releases them". Unless using code I don't understand to spawn a new PowerShell instance.


Solution

  • Fundamentally, the subdirectories of the hidden system directory C:\ProgramData ($env:ProgramData or $env:ALLUSERSPROFILE) fall into one of 3 categories:

    Interactively, for directories in (b) and (c), the current user can persistently gain access via a one-time action in File Explorer, which changes the file-system permissions (ACLs):

    Programmatically, (for directories that haven't already been "unlocked" interactively), you can only gain access to category (b) ad hoc, without changing permissions:[1]

    Start-Process -Verb RunAs (Get-Process -Id $PID).Path @'
      -NoExit -Command
    
      Get-ChildItem -ErrorAction SilentlyContinue -ErrorVariable err -Recurse -Force -Filter *.dll -LiteralPath C:\ProgramData  |
        ForEach-Object VersionInfo |
        Where-Object FileVersion -in '1.0.0.26638', '1.0.0.26793', '1.0.0.27567', '1.0.0.29915', '1.0.0.31122'
    
      if ($err) {
        $notAuthorized, $others = $err.Where({ $_.Exception -is [System.UnauthorizedAccessException] }, 'Split')
        if ($notAuthorized) {
          Write-Warning "You are not authorized to access the following paths:`n $($notAuthorized.TargetObject -join "`n  ")"
        }
        if ($others) {
          Write-Warning "The following unexpected errors occurred:`n $($others.ForEach('ToString') -join "`n  ")"
        }
      }
    '@.Replace('"', '\"')
    

    Note:

    combination of these four pieces of information (Timestamp, CheckSum=0, ImageSize, File version)


    [1] Conceivably, there is a way through impersonation or ad-hoc modification of the privileges of the user token associated with the current process, but I am not sure.