the system cannot find the file specified. (0x80070002)

Dzevad Alic 0 Reputation points
2023-06-22T13:11:24.3766667+00:00

Hello,

I've tried to deploy a application through intune to our company portal.

The application is getting pushed to the portal but when installing a error code gets returned.

I believe something is wrong with my detection rule, but i cant find out what.

User's image

User's image

Detection rule:

Start-Transcript -Path "C:\Windows\Logs\Software\Greenshot-winget-detect.log" -Force

$wingetApp = Get-AppxPackage -AllUsers -Name Microsoft.DesktopAppInstaller
$wingetPath = "$($wingetApp.InstallLocation)\winget.exe"

if (-not $wingetApp)
{
    Write-Host "Microsoft.DesktopAppInstaller does not appear to be installed."
}

if (-not (Test-Path -Path $wingetPath))
{
    Write-Host "Could not locate $wingetPath. Exiting with exit code 1..."

    Stop-Transcript

    exit 1
}
else
{
    Write-Host "winget Path: $wingetPath"

    $wingetVersion = (& $wingetPath show --id Greenshot.Greenshot --accept-source-agreements | Where-Object { $_ -like "Version:*" }).replace("Version:","").trim()

    $registryPath = @("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
    $registryData = Get-ChildItem -Path $registryPath | Get-ItemProperty | Where-Object UninstallString | Where-Object { $_.DisplayName -match "Greenshot" } | Get-Unique

    $installedRegistryVersion = $registryData.DisplayVersion
    $installedRegistryNameVersion = ($registryData.DisplayName | Select-String -Pattern "\d+(\.\d+)+").Matches.Value

    Write-Host "Installer: Greenshot.Greenshot"
    Write-Host "Latest winget version: $wingetVersion"
    Write-Host "Installed registry display version: $installedRegistryVersion"
    Write-Host "Installed registry display name version: $installedRegistryNameVersion"

    $installed = $false

    if (($installedRegistryVersion) -and ($wingetVersion))
    {
        $matchRegistryVersion = try { [System.Version]$wingetVersion -match [System.Version]$installedRegistryVersion } catch {}
        $greaterRegistryVersion = try { [System.Version]$installedRegistryVersion -gt [System.Version]$wingetVersion } catch {}
        $matchRegistryString = try { $wingetVersion -eq $installedRegistryVersion } catch {}

        if (($matchRegistryVersion) -or ($greaterRegistryVersion) -or ($matchRegistryString))
        {
            $installed = $true
        }
    }

    if (($installedRegistryNameVersion) -and ($wingetVersion))
    {
        $matchRegistryVersion = try { [System.Version]$wingetVersion -match [System.Version]$installedRegistryNameVersion } catch {}
        $greaterRegistryVersion = try { [System.Version]$installedRegistryNameVersion -gt [System.Version]$wingetVersion } catch {}
        $matchRegistryString = try { $wingetVersion -eq $installedRegistryNameVersion } catch {}

        if (($matchRegistryVersion) -or ($greaterRegistryVersion) -or ($matchRegistryString))
        {
            $installed = $true
        }
    }

    if ($installed -eq $true)
    {
        Write-Host "Status: Greenshot is installed and up to date"

        Stop-Transcript
    }
    else
    {
        Write-Host "Status: Greenshot is not installed or up to date. Exiting with exit code 1..."

        Stop-Transcript

        exit 1
    }
}

Does anyone know what the problem is?

Microsoft Security Intune Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Simon Ren-MSFT 40,341 Reputation points Microsoft External Staff
    2023-06-23T07:06:13.3266667+00:00

    Hi,

    Thank you for posting in Microsoft Q&A forum.

    1,The error "the system cannot find the file specified. (0x80070002)" indicates that the file specified in the command or script does not exist or may be in use by another process.

    In the provided script, the error could be caused by the line $wingetPath = "$($wingetApp.InstallLocation)\winget.exe" where the script tries to access the "winget.exe" file from the InstallLocation of the "Microsoft.DesktopAppInstaller". Make sure that the file is present in the location specified or try reinstalling "Microsoft.DesktopAppInstaller" if it is missing.

    It could also help to check the permissions for the file and the path in the script and ensure that they are set correctly.

    2,Additionally, you can check the Intune management console for any logs or specific error messages to help pinpoint the issue.

    Troubleshooting Intune app installation issues

    Troubleshoot Win32 app issues

    Thanks for your time. Have a nice day!

    Best regards,

    Simon


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Pavel yannara Mirochnitchenko 13,331 Reputation points MVP
    2023-06-23T12:00:19.0366667+00:00

    Try file or registery based detection rule. You just need to find out, what files or folders or new registery keys this app generates on file system. Does the app itself gets installed correctly?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.