Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved: Error In Query #121

Closed
Matt-CyberGuy opened this issue Jan 28, 2022 · 15 comments
Closed

Solved: Error In Query #121

Matt-CyberGuy opened this issue Jan 28, 2022 · 15 comments

Comments

@Matt-CyberGuy
Copy link

Afternoon guys,

We've been slowly but surely streamlining how to deploy software to our endpoints and figure out some great scripting for installing MeshAgent on Windows endpoints. But I came across a really odd issue on random systems.

We have a group of systems where the agent just won't install, we get the below error

...Checking for previous installation of "meshagent" [NONE]
...Installing service [ERROR] Error in Query

The above is the result of running the exe with -install or -fullinstall . The oddest thing is if I run it with just the run flag, the agent connects without an issue.

Any ideas?

@krayon007
Copy link
Collaborator

krayon007 commented Jan 28, 2022

What version of windows are you seeing this on?
You can run the command, meshagent -info and it will report what the agent thinks it's running on.

@Matt-CyberGuy
Copy link
Author

Matt-CyberGuy commented Jan 28, 2022 via email

@krayon007
Copy link
Collaborator

Later, I will have some commands for you to try, so we can figure out what is going on with those machines

@Matt-CyberGuy
Copy link
Author

Matt-CyberGuy commented Jan 28, 2022 via email

@krayon007
Copy link
Collaborator

Try running this command, it will output more info, and should help pinpoint where it's failing:
MeshAgent -fullinstall --verbose=1

@Matt-CyberGuy
Copy link
Author

Thanks, I just ran it on a few systems on different networks, received the same results:

...Checking for previous installation of "meshagent" [NONE]
...Installing service
CoInitializeEx()
CoUninitialize()
CoInitializeEx()
CoUninitialize()
 [ERROR] Error in Query

@krayon007
Copy link
Collaborator

If you do MeshAgent -info what does it show for the commit date? That way I know exactly which version of the agent you are using.

@Matt-CyberGuy
Copy link
Author

Matt-CyberGuy commented Jan 28, 2022

Hmm... it just hangs, but I've pulled it directly from our server that's running 0.9.74

According to other similar systems on the same network that installed fine, this is what shows up in our portal:
image

From the above working system

Compiled on: 11:25:25, Jan  7 2022
   Commit Hash: 22744773169b32a8b7c4382dba41a897b5c2d63c
   Commit Date: 2022-Jan-6 19:09:37-0800
Using OpenSSL 1.1.1l  24 Aug 2021
Agent ARCHID: 4
Detected OS: Microsoft Windows 10 Pro - 19043 - x64

@krayon007
Copy link
Collaborator

Ok, try running this command (kinda long so may want to cut/paste):
MeshAgent -exec "try{console.log(JSON.stringify(require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_OperatingSystem', ['Caption','BuildNumber'])))}catch(x){console.log(x);};process.exit();"

@Matt-CyberGuy
Copy link
Author

Just tried it, it outputs the same as before

Error in Query

@krayon007
Copy link
Collaborator

Does this command work on your machine?
wmic OS GET /FORMAT:LIST

@Matt-CyberGuy
Copy link
Author

Matt-CyberGuy commented Jan 29, 2022

Running from powershell, I get the following:

Node - SALES-AIO-11
System.Management.Automation.RemoteException
ERROR:
System.Management.Automation.RemoteException
Description = Invalid class
System.Management.Automation.RemoteException

---- edit----

I ran the same command above on another system that the agent installed on, LOTS of output

@Matt-CyberGuy
Copy link
Author

Matt-CyberGuy commented Jan 29, 2022

I got it!!! your command above got me looking into fixing the wmic repository.
I followed the steps in this:
https://www.thewindowsclub.com/how-to-repair-or-rebuild-the-wmi-repository-on-windows-10

After stopping WMIC, reseting the repository, then letting it rebuild, the above command ran correctly and the meshagent installed without an issue.

Guess I'm gonna have to write this into my onboarding script.

Thank you! This was a big help!!! U guys are the best!

@Matt-CyberGuy Matt-CyberGuy changed the title Error In Query Solved: Error In Query Jan 29, 2022
@krayon007
Copy link
Collaborator

Interesting! I'm going to modify the code to catch this exception. I never expected this particular query to fail. I may make it save a log entry mentioning the wmi repository, so others with the same issue can resolve it

@Matt-CyberGuy
Copy link
Author

For anyone interested, below is a code snippet for fixing the WMI issue from the powershell script I wrote for deploying meshagent. If anyone is interested in the full deployment script, let me know and I can make a new thread with a skeleton script for users to follow.

# Install the remote agent & store the output in a variable
$cmdOutput = .\meshagent.exe -install 

#Determine if installation failed due to wmi issues
if ($cmdOutput -like '*Error in Query*'){
    Write-Host ""
    Write-Host "WMI repository corrupted, attempting to reset and rebuild"
    Write-Host ""
    net stop winmgmt /y
    Winmgmt /resetrepository
    winmgmt /verifyrepository
    Write-Host ""
    .\meshagent.exe -install 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants