Page 1 of 1

Wmic command placed in a batch file is not responding and refuse to work without administrator privilegies

Posted: 16 Mar 2020 03:19
by BoQsc
I came across this weird behaviour with Wmic:
  • Running WMIC from manually opened command prompt without administrator privilegies - works properly and output is delivered as expected.
  • Running WMIC from batch file without administrator privilegies - Wmic is stuck in the permanent loop without any output.
  • Running WMIC from batch file with administrator privilegies - Wmic is showing output and everything is as expected.
Example file:

Code: Select all

@ECHO OFF
WMIC
pause
Another Example file:

Code: Select all

@ECHO OFF
WMIC Path Win32_LocalTime Get Day
pause

Re: Wmic command placed in a batch file is not responding and refuse to work without administrator privilegies

Posted: 16 Mar 2020 04:50
by Eureka!
Did you call your script WMIC.cmd/.bat?
That would explain this behaviour exactly.

I make a habit out of adding the file extension to programs used in scripts to avoid this (replace WMIC with WMIC.exe)

But it is always better to avoid naming your scripts the same as an already existing program.

Re: Wmic command placed in a batch file is not responding and refuse to work without administrator privilegies

Posted: 16 Mar 2020 05:04
by BoQsc
Eureka! wrote:
16 Mar 2020 04:50
Did you call your script WMIC.cmd/.bat?
That would explain this behaviour exactly.

I make a habit out of adding the file extension to programs used in scripts to avoid this (replace WMIC with WMIC.exe)

But it is always better to avoid naming your scripts the same as an already existing program.

I simply double clicked the script using GUI.
But it seems that adding .exe extension to the wmic command resolved the problem.

Thank you.