Repository: conan-io/conan

Issue:
Package Manager used with Chocolatey doesn't find already installed packages
### Describe the bug

The command below in the recipe of my project is not able to check that the package is installed on my system:
    Chocolatey(self).check(["miktex"])

But the package is correctly installed:
  choco list
  Chocolatey v2.4.0
  chocolatey 2.4.0
  miktex 24.4.0
  miktex.install 24.4.0
  3 packages installed.

Windows PC, Conan version 2.9.3



### How to reproduce it

Install miktex chocolatey package.
Execute the code in a recipe:

       def system_requirements(self):
            missing_packages = []
            apt_missing = Apt(self).check(["miktex"])
            if apt_missing:
                missing_packages.extend(apt_missing)

            choco_missing = Chocolatey(self).check(["miktex", "eee"])
            if choco_missing:
                missing_packages.extend(choco_missing)

            if missing_packages:
                raise ConanException("System requirements not met, please install: {}".format(", ".join(missing_packages)))
            




Discussion:
Hi @vergara-r 

Thanks for your feedback.

Quick question, what are you trying to achieve?
The modern system-package-manager integrations are smart, you want to typically do:
```python
def system_requirements(self):
     Chocolatey(self).install(["miktex", "eee"])
```

And let users define the behavior via the ``tools.system.package_manager:mode`` conf (type ``conan config list package_manager`` to see related confs). So Conan will automatically do the checks and raise the exception for you, and it will also allow to opt-in to automatically install the packages if you want, always controlled by the user.

I am not sure what could be the error, I am trying:
```python
    def system_requirements(self):
        Chocolatey(self).install(["miktex"])
```
and then:
```bash
$ conan install . -c tools.system.package_manager:mode=install
```
and seems to work, it install version 24.4.0. (without the mode=install it will raise with an error reporting about the missing package, it seems exactly what you are trying to implement).

Also if I do:
```python
def system_requirements(self):
        choco_missing = Chocolatey(self).check(["miktex", "eee"])

        if choco_missing:
            from conan.errors import ConanException
            raise ConanException("System requirements not met, please install: {}".format(", ".join(choco_missing)))
```
works fine:
```
ERROR: conanfile.py (mypkg/0.1): Error in system_requirements() method, line 36
        raise ConanException("System requirements not met, please install: {}".format(", ".join(choco_missing)))
        ConanException: System requirements not met, please install: miktex, eee
```
Oh, sorry, now I see what you mean, I overlooked it. It is the check once it is installed. I will check this.
Got it. It seems the ``Choco().check()`` was using a legacy choco command line syntax.

I am updating it in https://github.com/conan-io/conan/pull/17382, for next Conan 2.10 release.

Note however, the above still stands, the one line ``Chocolatey(self).install(["miktex"])`` can do the check, and the install, by configuration, this would be the recommended approach
Unfortunately automate installation is some company contexts is not straight forward with ``Chocolatey(self).install(["miktex"])``
``Chocolatey detected you are not running from an elevated command shell. You may experience errors - many functions/packages require admin rights. Only advanced users should run choco w/out an
 elevated shell.``
So I can only check in the recipe if the package has been installed.
Is it possible to launch the command in an elevated mode ?
Thanks for the fix proposal in [17382](https://github.com/conan-io/conan/pull/17382), package system management from recipe is a great feature!



Patch:
diff --git a/conan/tools/system/package_manager.py b/conan/tools/system/package_manager.py
index 98a5dda3e3a..aebd9f855c8 100644
--- a/conan/tools/system/package_manager.py
+++ b/conan/tools/system/package_manager.py
@@ -320,8 +320,7 @@ class Chocolatey(_SystemPackageManagerTool):
     tool_name = "choco"
     install_command = "{tool} install --yes {packages}"
     update_command = "{tool} outdated"
-    check_command = '{tool} search --local-only --exact {package} | ' \
-                    'findstr /c:"1 packages installed."'
+    check_command = '{tool} list --exact {package} | findstr /c:"1 packages installed."'
 
 
 class PacMan(_SystemPackageManagerTool):


Test patch:
diff --git a/test/integration/tools/system/package_manager_test.py b/test/integration/tools/system/package_manager_test.py
index 5eb052baca9..25bcb90f0fb 100644
--- a/test/integration/tools/system/package_manager_test.py
+++ b/test/integration/tools/system/package_manager_test.py
@@ -323,7 +323,7 @@ def fake_check(*args, **kwargs):
     (Brew, 'test -n "$(brew ls --versions package)"'),
     (Pkg, 'pkg info package'),
     (PkgUtil, 'test -n "`pkgutil --list package`"'),
-    (Chocolatey, 'choco search --local-only --exact package | findstr /c:"1 packages installed."'),
+    (Chocolatey, 'choco list --exact package | findstr /c:"1 packages installed."'),
     (PacMan, 'pacman -Qi package'),
     (Zypper, 'rpm -q package'),
 ])