Installing wmic in Ubuntu 12.04 (LTS) 64-Bit Desktop

WMIC is a useful tool in the world of remote management, and more specifically tracking the performance of Windows machines, so I thought I’d show how I got it installed on Ubuntu 12.04 LTS – Desktop. This should work fine on most other versions of Ubuntu as well, but please comment if it did not.

Step 1 – Install autoconf which is used in the compilation process

sudo apt-get install autoconf

Step 2 – Download the ‘wmic’ source (I will work in my ‘Downloads’ directory)

cd ~/Downloads
wget http://www.openvas.org/download/wmi/wmi-1.3.14.tar.bz2

Step 3 – Untar the source

tar -xvf wmi-1.3.14.tar.bz2

Step 4 – Go into the directory and add a line of text to the top of ‘GNUmakefile’

#Go into the directory where the files were untarred to
cd wmi-1.4.14/ #or whatever version you installed
 
#Edit 'GNUmakefile' and add the following at the top (just after the License Info)
ZENHOME=../..

Step 5 – Compile

sudo make
 
#Now grab a magazine or something - this can take a few minutes
 
#After a while you 'might' get something like this - I did
.....
cp: target `../../lib/python' is not a directory
make: *** [pywmi-installed] Error 1
 
#wmic is already compiled and usable at this stage so it's not an issue. Proceed to Step 6

Step 6 – Test wmic

#In the ~/Downloads/wmi-1.3.14/ directory you will find a file named 'bin'. Create a copy of this file and name it wmic
cp bin wmic
 
#Test it 
#./wmic -U[user]%[password] //[host/ip] "[WMI Query]"
./wmic -Utestuser%tstpass //172.16.2.2 "SELECT * FROM Win32_OperatingSystem"
 
#Output should be similar to this:
CLASS: Win32_OperatingSystem
BootDevice|BuildNumber|BuildType|Caption|CodeSet|CountryCode|CreationClassName|CSCreationClassName|CSDVersion|CSName|CurrentTimeZone|Debug|Description|Distributed|EncryptionLevel|ForegroundApplicationBoost|FreePhysicalMemory|FreeSpaceInPagingFiles|FreeVirtualMemory|InstallDate|LargeSystemCache|LastBootUpTime|LocalDateTime|Locale|Manufacturer|MaxNumberOfProcesses|MaxProcessMemorySize|Name|NumberOfLicensedUsers|NumberOfProcesses|NumberOfUsers|Organization|OSLanguage|OSProductSuite|OSType|OtherTypeDescription|PAEEnabled|PlusProductID|PlusVersionNumber|Primary|ProductType|QuantumLength|QuantumType|RegisteredUser|SerialNumber|ServicePackMajorVersion|ServicePackMinorVersion|SizeStoredInPagingFiles|Status|SuiteMask|SystemDevice|SystemDirectory|SystemDrive|TotalSwapSpaceSize|TotalVirtualMemorySize|TotalVisibleMemorySize|Version|WindowsDirectory
\Device\HarddiskVolume1|3790|Uniprocessor Free|Microsoft(R) Windows(R) Server 2003, Enterprise Edition|1252|1|Win32_OperatingSystem|Win32_ComputerSystem||WIN2003-VM-HS|120|False||False|168|2|779280|2348260|3127540|20121101081525.000000+120|1|20121101090258.411875+120|20121105103817.505000+120|0409|Microsoft Corporation|4294967295|2097024|Microsoft Windows Server 2003 Enterprise Edition|C:\WINDOWS|\Device\Harddisk0\Partition1|5|46|4|Sintrex Integration Services (Pty) Ltd|1033|274|18|(null)|False|(null)|(null)|True|3|0|0|Test User|69763-011-6394922-43753|0|0|2527020|OK|274|\Device\HarddiskVolume1|C:\WINDOWS\system32|C:|0|3575072|1048052|5.2.3790|C:\WINDOWS

Step 7 – Copy wmic to /usr/bin so you can use it from anywhere

 
sudo cp wmic /usr/bin/

That’s it, it should work now from anywhere.

Leave a Reply to mike Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Comments

  1. Enusberg

    Great guide, thanks heaps for this!

    Something you might just to make a note of, I had to actually run ‘sudo cp wmic /usr/bin’ before I could test wmic.

    Reply
    1. Glad I could help. This caused me a fair bit of head scratching as well. I find it irritating that such a useful tool is not available in the repositories.

      I did mention the copy in step 7 though … 🙂

      EDIT: Wait I see what you mean, Step 6. I’ll fix that, thanks!

      Reply
  2. mike

    It work. Dumb question though, will this allow me to grab info from the ubuntu desktop? gather information about the ubuntu desktop from the windows machine?

    Reply
    1. Hi Mike,

      No, I would recommend you use SNMP (via the net-snmp agent or similar) to retrieve Ubuntu/Linux information from another machine, be it either Windows or another Linux host.

      I’ll see if I can put up an article regarding this at some stage.

      Reply
  3. Hussain

    Hello,

    Thank you for the details.
    It installed correctly, but after I run it gives me following error

    **********************
    hus@hus-desktop:~/Downloads/wmi-1.3.14$ ./wmic1 -Uadmin%Monday\)\)\) //10.10.11.50 “SELECT * FROM Win32_OperatingSystem”
    [wmi/wmic.c:196:main()] ERROR: Login to remote object.
    NTSTATUS: NT code 0x80041003 – NT code 0x80041003
    **********************

    Please suggest your views.

    Reply
  4. vijay

    It wont’s work for me…..when i run i got the erro below

    Failed to parse ./librpc/idl/atsvc.idl at ./pidl/pidl line 583.
    make[1]: *** [idl] Error 1
    make[1]: Leaving directory `/home/vijay/Downloads/wmi-1.3.14/Samba/source’
    cd Samba/source ; \
    cp bin/winexe ../../bin ; \
    cp bin/wmic ../../bin ; \
    cp bin/shared/*async_wmi_lib.so.0* ../../lib/python
    cp: cannot stat ‘bin/winexe’: No such file or directory
    cp: cannot stat ‘bin/wmic’: No such file or directory
    cp: cannot stat ‘bin/shared/*async_wmi_lib.so.0*’: No such file or directory
    make: *** [pywmi-installed] Error 1

    cp bin wmic
    cp: cannot stat ‘bin’: No such file or directory
    Please Help

    Reply
    1. Ursino

      You have to edit Samba/source/Makefile and add -ffreestanding to the compiler.

      Why?
      http://gcc.gnu.org/gcc-4.8/porting_to.html


      Pre-processor pre-includes

      The GCC pre-processor may now pre-includes a file that defines certain macros for the entirety of the translation unit. This allows fully conformant implementations of C99/C11 and other standards that require compiler or compiler + runtime macros that describe implementation availability.

      On linux, is pre-included.

      This subtle change means that some more creative uses of the pre-processor may now fail, with the following diagnostic:

      /usr/include/stdc-predef.h:0: error: Syntax error near ‘3’
      As a workaround, the stdc-predef.h preinclude can be disabled with the use of -ffreestanding. For non C/C++ code, use the pre-processor flag -P.”

      This is working for me

      Reply
    2. Ursino

      Hi Vijay,

      my response below. The response is -ffreestanding

      Reply
      1. Joel

        Hey Ursino,

        Is there any way you can elaborate on how to correctly use the -ffreestanding flag? I am hitting the exact issue vijay ran into on Ubuntu 14 LTS.

        What is the syntax that needs to be added to Samba/source/Makefile? I tried simply adding “-ffreestanding” as well as “CFLAGS=-ffreestanding” but to no avail. Additionally, these edits are overwritten every time I try and compile with make, so are you sure Samba/source/Makefile is the right place for that?

        Thanks so much!

        Joel

        Reply
        1. gwyn

          This worked for me with Ubuntu 14.04 LTS:

          make “CPP=gcc -E -ffreestanding”

          Reply
          1. Wheeler

            Thans a lot gwyn! This solves my problem as well 🙂

  5. Alberto

    Hi,

    I’m testing this solution on my lab environment, and i’m having the same issue/error than Vijay. I have this directory structure:

    root@FRONTEND:/usr/local/wmi-1.3.14# ls -ltr
    total 16
    -rw-r–r– 1 root staff 724 oct 10 20:19 pyinclude.py
    drwxr-sr-x 7 root staff 4096 oct 10 20:21 Samba
    -rw-r–r– 1 root staff 2033 oct 10 20:30 GNUmakefile
    drwxr-sr-x 6 root staff 4096 oct 10 20:31 pysamba

    There is no file called “Samba/source/Makefile”. What i’m doing wrong?

    And this is the error:

    root@FRONTEND:/usr/local/wmi-1.3.14# make
    cd Samba/source ; \
    ./autogen.sh ; \
    CPPFLAGS=”-I/usr/include/python2.7″ \
    ./configure –without-readline –enable-debug ; \
    make proto bin/wmic bin/winexe libraries ; \
    touch pywmi-build
    ./autogen.sh: running script/mkversion.sh
    ./autogen.sh: 51: ./autogen.sh: ./script/mkversion.sh: Permission denied
    /bin/sh: 3: ./configure: Permission denied
    make[1]: se ingresa al directorio `/usr/local/wmi-1.3.14/Samba/source’
    make[1]: *** No hay ninguna regla para construir el objetivo `proto’. Alto.
    make[1]: se sale del directorio `/usr/local/wmi-1.3.14/Samba/source’
    cd Samba/source ; \
    cp bin/winexe ../../bin ; \
    cp bin/wmic ../../bin ; \
    cp bin/shared/*async_wmi_lib.so.0* ../../lib/python
    cp: no se puede efectuar `stat’ sobre «bin/winexe»: No existe el fichero o el directorio
    cp: no se puede efectuar `stat’ sobre «bin/wmic»: No existe el fichero o el directorio
    cp: no se puede efectuar `stat’ sobre «bin/shared/*async_wmi_lib.so.0*»: No existe el fichero o el directorio
    make: *** [pywmi-installed] Error 1

    Thank in advance¡¡

    Regards.

    Reply
  6. Justin

    trying to follow your directions using my Raspberry Pi.
    I made it to step 5.

    for the last 30 minutes, the last line of the terminal screen has looked like this

    “Compiling librpc/gen_ndr/ndr_srvsvc.c”

    Is that normal?

    Reply
    1. Apologies, I was out of town for a week. That doesn’t seem normal. Did it eventually finish?

      Reply
      1. Justin

        no, the processor on the raspberry pi couldn’t handle it and froze aha.

        Reply
  7. x86

    # sudo make “CPP=gcc -E -ffreestanding”

    make[1]: Entering directory ‘/home/x86/Downloads/wmi-1.3.14/Samba/source’
    Can’t use ‘defined(@array)’ (Maybe you should just omit the defined()?) at ./pidl/pidl line 583.
    Makefile:28880: recipe for target ‘idl’ failed
    make[1]: *** [idl] Error 1
    make[1]: Leaving directory ‘/home/x86/Downloads/wmi-1.3.14/Samba/source’
    cd Samba/source ; \
    cp bin/winexe /bin ; \
    cp bin/wmic /bin ; \
    cp bin/shared/*async_wmi_lib.so.0* /lib/python
    cp: impossível obter estado de ‘bin/winexe’: Arquivo ou diretório não encontrado
    cp: impossível obter estado de ‘bin/wmic’: Arquivo ou diretório não encontrado
    cp: impossível obter estado de ‘bin/shared/*async_wmi_lib.so.0*’: Arquivo ou diretório não encontrado
    GNUmakefile:42: recipe for target ‘pywmi-installed’ failed
    make: *** [pywmi-installed] Error 1

    I can not compile … can anyone help me ?
    I estyou using Ubuntu 16.04 LTS

    Reply
    1. Vee

      If you get the error Can’t use ‘defined(@array)’ (Maybe you should just omit the defined()?) at ./pidl/pidl line 583.
      (you are probably using Perl version 5.22+) then you need to edit line 583 of Samba/source//pidl/pidl and remove the “defined” from the start of the line (just like the error message says)

      Reply
  8. Thibz

    Hello there !
    I hope that subject was not fall , Actually I am using this pluggin on Raspbian Jessie on the RPI 3.
    I had well installed that plugin with your command line 3 mounth ago ( make “CCP=gcc -E -ffreestanding” ).
    Now, I have to reinstall it and the error was comming again and she dont want leave the shell so, I have try some actions:
    at the beggining the error was :
    make[1]: Entering directory ‘/usr/lib/nagios/plugins/wmi-1.3.16/Samba/source’
    Creating lib/util/util_proto.h
    Creating lib/charset/charset_proto.h
    Creating param/proto.h
    Creating libcli/util/proto.h
    defined(@array) is deprecated at ./pidl/pidl line 583.
    (Maybe you should just omit the defined()?)
    Compiling ./librpc/idl/atsvc.idl
    /usr/include/stdc-predef.h:0: Syntax error near ‘3’
    Failed to parse ./librpc/idl/atsvc.idl at ./pidl/pidl line 583.
    Makefile:28880: recipe for target ‘idl’ failed
    make[1]: *** [idl] Error 1
    make[1]: Leaving directory ‘/usr/lib/nagios/plugins/wmi-1.3.16/Samba/source’
    defined @$pidl || die “Failed to parse $idl_file”;

    I launch the commande and i get the advice to remove the defined at the beginning of the line . So I do it and I have this error after the error was :
    touch pywmi-build
    make[1]: Entering directory ‘/usr/local/nagios/plugins/wmi-1.3.16/Samba/source’
    Creating lib/util/util_proto.h
    Creating lib/charset/charset_proto.h
    Creating param/proto.h
    Creating libcli/util/proto.h
    Compiling ./librpc/idl/atsvc.idl
    /usr/include/stdc-predef.h:0: Syntax error near ‘3’
    Can’t use an undefined value as an ARRAY reference at ./pidl/pidl line 583.
    Makefile:28880: recipe for target ‘idl’ failed
    make[1]: *** [idl] Error 1
    make[1]: Leaving directory ‘/usr/local/nagios/plugins/wmi-1.3.16/Samba/source’

    and after this, I have completely comment out the line, the “make “CCP=gcc -E -ffreestanding” has continue a bit his works with many error all about the IDL, and that error was comming :

    The following command failed:
    Use of uninitialized value in pattern match (m//) at ./script/cflags.pl line 15, line 1212.
    gcc -Ilib/replace -Ilib/talloc -Ilib/tdb/include -Iheimdal_build -Iheimdal/lib/roken -Ilib/socket_wrapper -Iheimdal/lib/des -Iheimdal/lib/com_err -Iheimdal/lib/asn1 -Iheimdal/lib/krb5 -Iheimdal/lib/hdb -Iheimdal/lib/gssapi/spnego -Iheimdal/lib/gssapi -Iheimdal/lib/gssapi/krb5 -I heimdal/lib/gssapi/mech -g -I./include -I. -I./lib -I./lib/replace -D_SAMBA_BUILD_=4 -DHAVE_CONFIG_H -I/usr/lib/python2.7 -fPIC -c wmi/wbemdata.c -o wmi/wbemdata.o
    Use of uninitialized value in pattern match (m//) at ./script/cflags.pl line 15, line 1212.
    Makefile:29001: recipe for target ‘wmi/wbemdata.o’ failed
    make[1]: *** [wmi/wbemdata.o] Error 1
    make[1]: Leaving directory ‘/usr/local/nagios/plugins/wmi-1.3.16/Samba/source’

    So now I am lost.. Maybe some one can give me a way to follow for fix that.
    Best regards,
    Thibz

    Reply