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

Unable to locate executable file: 'wmic' #7198

Closed
Terryxxx opened this issue May 15, 2018 · 16 comments
Closed

Unable to locate executable file: 'wmic' #7198

Terryxxx opened this issue May 15, 2018 · 16 comments

Comments

@Terryxxx
Copy link

2

Error: Unable to locate executable file: 'wmic'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.

3

@Terryxxx
Copy link
Author

Can someone help me to resolve this problem?

@nigurr
Copy link

nigurr commented May 16, 2018

@Terryxxx wmic should be available in C:\WINDOWS\System32\Wbem\WMIC.exe
Can you please restart the agent( and command shell) and this should unblock you.

@Terryxxx
Copy link
Author

@nigurr Thanks for your comments. I will try it.

@ShreyasRmsft
Copy link
Member

@Terryxxx are you unblocked now?

@Terryxxx
Copy link
Author

@ShreyasRmsft Problem is not solved

@ShreyasRmsft
Copy link
Member

@Terryxxx did you follow the steps @nigurr has mentioned? Is the wmic.exe present in C:\WINDOWS\System32\Wbem\ on your machine? Did you add it to path and restart the agent process?

Also if you open cmd on the machine and type wmic does it invoke the tool?

@Terryxxx
Copy link
Author

@ShreyasRmsft Yes, I have checked my path and verified wmic.exe in C:\WINDOWS\System32\Wbem\ . Please see the follow pic.
image

@acesiddhu
Copy link
Contributor

@Terryxxx last time I saw this issue was when the build/release definition was overriding the value of Path environment variable. Can you cross check in variable tab to see if Path variables is not getting set

@ShreyasRmsft
Copy link
Member

Also one simple check you can do is add a powershell task with the following code:

Write-Host $env:PATH
wmic.exe -somearg

This will tell us for sure.

@Terryxxx
Copy link
Author

@ShreyasRmsft I have added a task about it, but it run failed. Following is failed log.

2018-05-22T02:43:28.6520608Z ##[debug]Evaluating condition for step: 'PowerShell Script'
2018-05-22T02:43:28.6521871Z ##[debug]Evaluating: succeeded()
2018-05-22T02:43:28.6522081Z ##[debug]Evaluating succeeded:
2018-05-22T02:43:28.6522378Z ##[debug]=> True
2018-05-22T02:43:28.6522658Z ##[debug]Result: True
2018-05-22T02:43:28.6523220Z ##[section]Starting: PowerShell Script
2018-05-22T02:43:28.6527348Z ==============================================================================
2018-05-22T02:43:28.6527540Z Task : PowerShell
2018-05-22T02:43:28.6527652Z Description : Run a PowerShell script
2018-05-22T02:43:28.6527748Z Version : 1.2.3
2018-05-22T02:43:28.6527838Z Author : Microsoft Corporation
2018-05-22T02:43:28.6527947Z Help : More Information
2018-05-22T02:43:28.6528080Z ==============================================================================
2018-05-22T02:43:28.6910197Z ##[debug]Working directory: 'D:\Agent_work\r1\a'
2018-05-22T02:43:28.6911233Z ##[debug]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "try { $null = [System.Security.Cryptography.ProtectedData] } catch { Write-Verbose 'Adding assemly: System.Security' ; Add-Type -AssemblyName 'System.Security' ; $null = [System.Security.Cryptography.ProtectedData] ; $Error.Clear() } ; Invoke-Expression -Command ([System.Text.Encoding]::UTF8.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String('AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAuHn+VhYXJUOylmUIde4AdgAAAAACAAAAAAAQZgAAAAEAACAAAACvbqoEoJKY1l4bRjYbt8ee4FzRpil7w7ywAZM/oftUhgAAAAAOgAAAAAIAACAAAAAURTOnm3ZrSWFBNtFeIbsjfF2632uRrh0gwjVC4IHfSGAAAAD2jZTRLs1rf8D8Eq5sehRq/t6IC/Es0h7CsicTHsxKA7/4ls3JMqofcXlAwiLs2gVQFAcB+lx6DcppcqlHBAkvdIvwWNtRq1xbBg5KaOd05KCu1ldu5TFX3+EgqNK/f5ZAAAAA4ir1H1k7hx4Awva7kCYnNQ0woyqQFwds+hnOliLwggFBXeZ5VNm1Jk1BYySIlaw7wcFlVdPPngJk953So39acg=='), [System.Convert]::FromBase64String('4HhCi3wwb2E8PFA8a1PtKA=='), [System.Security.Cryptography.DataProtectionScope]::CurrentUser))) ; if (!(Test-Path -LiteralPath variable:\LastExitCode)) { Write-Verbose 'Last exit code is not set.' } else { Write-Verbose ('$LastExitCode: {0}' -f $LastExitCode) ; exit $LastExitCode }"
2018-05-22T02:43:28.6912155Z ##[command]. 'C:\Users\superman\AppData\Local\Temp\17cdc4fd-dea3-4406-8899-a606c7206f85.ps1'
2018-05-22T02:43:29.0499961Z D:\Agent_work\r1\a/CN/Artifact1/webApp.runsettings
2018-05-22T02:43:29.2901297Z ##[error]wmic.exe : The term 'wmic.exe' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\superman\AppData\Local\Temp\17cdc4fd-dea3-4406-8899-a606c7206f85.ps1:2 char:1

  • wmic.exe -somearg
  •   + CategoryInfo          : ObjectNotFound: (wmic.exe:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    
    

2018-05-22T02:43:29.3990540Z ##[error]Process completed with exit code 0 and had 1 error(s) written to the error stream.
2018-05-22T02:43:29.4002526Z ##[debug]System.Exception: Process completed with exit code 0 and had 1 error(s) written to the error stream.
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.PowerShellExeHandler.d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.d__1.MoveNext()
2018-05-22T02:43:29.4005685Z ##[section]Finishing: PowerShell Script

@ShreyasRmsft
Copy link
Member

@Terryxxx the failure with wmic was expected.

But i don't see the output for Write-Host $env:PATH
You added the above also right? We just want to confirm whether the PATH variable is getting overridden or not?

If you haven't added Write-Host $env:PATH add it to the script.
You can remove the wmic -somearg line

Also i had specified the order intentionally as i had expected the wmic call to fail but wanted to know content of the PATH variable before wmic was called.

Just run the script with just Write-Host $env:PATH that should tell us all we need to know

@Terryxxx
Copy link
Author

Terryxxx commented May 22, 2018

@ShreyasRmsft I have added Write-Host $env:PATH. But it does't show any things when it run.

image

Following is log:

2018-05-22T05:59:33.3102436Z ##[debug]Evaluating condition for step: 'PowerShell Script'
2018-05-22T05:59:33.3204402Z ##[debug]Evaluating: succeeded()
2018-05-22T05:59:33.3213885Z ##[debug]Evaluating succeeded:
2018-05-22T05:59:33.3253092Z ##[debug]=> True
2018-05-22T05:59:33.3278103Z ##[debug]Result: True
2018-05-22T05:59:33.3338892Z ##[section]Starting: PowerShell Script
2018-05-22T05:59:33.3537405Z ==============================================================================
2018-05-22T05:59:33.3537576Z Task : PowerShell
2018-05-22T05:59:33.3537670Z Description : Run a PowerShell script
2018-05-22T05:59:33.3537762Z Version : 1.2.3
2018-05-22T05:59:33.3537866Z Author : Microsoft Corporation
2018-05-22T05:59:33.3537974Z Help : More Information
2018-05-22T05:59:33.3538089Z ==============================================================================
2018-05-22T05:59:33.4100063Z ##[debug]Working directory: 'D:\Agent_work\r1\a'
2018-05-22T05:59:33.4101474Z ##[debug]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "try { $null = [System.Security.Cryptography.ProtectedData] } catch { Write-Verbose 'Adding assemly: System.Security' ; Add-Type -AssemblyName 'System.Security' ; $null = [System.Security.Cryptography.ProtectedData] ; $Error.Clear() } ; Invoke-Expression -Command ([System.Text.Encoding]::UTF8.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String('AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAuHn+VhYXJUOylmUIde4AdgAAAAACAAAAAAAQZgAAAAEAACAAAACYR93E0aSxuKrBOufX65APPCO33riw/wIUpKLoojUqLQAAAAAOgAAAAAIAACAAAAB9kRvn5OttTfe015MaoqIupVw6jbiR97SJrPg4Bh+IoGAAAACkefwSg4+Wv2/iPxQWQSnaUO/fKDaqiGGsxnRPY73FqsGFNqvM50Uo/+Ml1MHhI8UFeJbPq7mW2/0DBiji+hdZOk8f8rgXBmA+XVlhp2K8WBel0suL6Zyg3lD81CED+aZAAAAANh8LzBue2P6Q7uDZM1pQCTk0J3MpDH/elApDLPN7IkTg0PoamtR9BbqOVdMQPMjvF8k32H6PcNBgXQncvO3v0Q=='), [System.Convert]::FromBase64String('g78OSelZMRrPnuegKRGz7Q=='), [System.Security.Cryptography.DataProtectionScope]::CurrentUser))) ; if (!(Test-Path -LiteralPath variable:\LastExitCode)) { Write-Verbose 'Last exit code is not set.' } else { Write-Verbose ('$LastExitCode: {0}' -f $LastExitCode) ; exit $LastExitCode }"
2018-05-22T05:59:33.4102250Z ##[command]. 'C:\Users\superman\AppData\Local\Temp\53ee6e1f-4cd3-421c-8ef7-963999efcb56.ps1'
2018-05-22T05:59:33.7527254Z D:\Agent_work\r1\a/CN/Artifact1/webApp.runsettings
2018-05-22T05:59:33.8076935Z ##[section]Finishing: PowerShell Script

@ShreyasRmsft
Copy link
Member

Then it's clear that something in your definition is overriding your system path variable.

But by the way why can't i see the Hello World output from your script?

without the PATH variables value there is no way the task can get the location of wmic and it is bound to fail.

Next step is to identify who is resetting or clearing the PATH variable. Can you send screenshots of your variables section of the build definition.

You can also export your definition to a json file and attach it here or send it to devops_tools@microsoft.com

@Terryxxx
Copy link
Author

@ShreyasRmsft Thank you very much! I have solved this problem. Cause by I set a "path" variable in definition variables, it reset computer environment path. I have deleted it, it can run successfully.

@michael-gaudet
Copy link

This is old, but this thread just solved an issue I was dealing with for days! Thank you @ShreyasRmsft. For anyone else who may stumble across this issue...

I was getting the same error as originally reported. On my server VM, I used powershell to Write-Host $env:PATH and it was missing any mention of the C:\WINDOWS\System32\Wbem\ directory.

I have never had to change this, so I found this reference to set the path variables:
https://ginesys.atlassian.net/wiki/spaces/PUB/pages/1900549/How+To+Set+the+PATH+variable+in+environment+variable+in+Windows

Step by step:

  1. Hit windows key and type "system environment variables", which should open the System Properties dialog Advanced page.
  2. Click the Environment Variables button near the bottom.
  3. In the lower half of this screen, under the "System variables" section, highlight the "Path" Variable and click "Edit".
  4. Add C:\Windows\System32\Wbem
  5. Add %SystemRoot%\System32\Wbem
  6. Reboot.
  7. Confirmed update using powershell again.

I queued up the build in TFS, and it ran perfectly.

@ShreyasRmsft
Copy link
Member

@michael-gaudet glad it helped :)

Generally Wbem should be included in the PATH by default. Not sure if the image was a custom image or if the stock image was like that.

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

No branches or pull requests

5 participants