winexeを使用してWindowsシステムで「wmic」コマンドを実行する

winexeを使用してWindowsシステムで「wmic」コマンドを実行する

winexeを使用してLinuxのWindowsシステムでコマンドを実行します。たとえば、

winexe -A authfile //syspc4.domain.com "ipconfig /all"

上記は、Windowsシステムでcmd.exeを実行し、「ipconfig / all」と入力したのと同じ内容を印刷すると予想されます。

私の究極の目標は、Windowsシステムのシリアル番号とモデル名をリモートで(Linuxで)取得することです。これは、Windows(Windows XP)システムのローカルcmd.exeで次の2つのコマンドを使用して簡単に実行できます。

wmic bios get serialnumber
wmic computersystem get model

ただし、winexeを介してこのコマンドを実行しようとすると機能しません。 Enterキーを押した後は何も起こりません。エラーもなく、何もありません。 ctrl + cを押して終了するまで停止したようです。

私が試したコマンドは次のとおりです。

winexe -A authfile //syspc4.domain.com "wmic bios get serialnumber"
winexe -A authfile //syspc4.domain.com "cmd wmic bios get serialnumber"
winexe -A authfile //syspc4.domain.com "cmd /c wmic bios get serialnumber"
winexe -A authfile //syspc4.domain.com "cmd"
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\WINDOWS\system32>wmic bios get serialnumber

すべての場合に応答がありません。 winexe --helpを少し見てみると、ロギングオプションが表示されますが、そのオプションを設定しても何らかの出力ログはありません。

誰かがかなり多くの質問をした他のフォーラムで、次のスレッドを見つけました。精密私のように彼も当然答えを得ませんでした。 http://www.linuxquestions.org/questions/linux-software-2/winexe-780343/

編集する:デバッグがオンの場合、ここで中断されます。

winexe -d 6 -A authfile //syspc4.domain.com "wmic bios get serialnumber"

...
IN: async_open(\pipe\ahexec, 2)
IN: async_open_recv
CTRL: Sending command: get version
CTRL: Sending command: run wmic bios get serialnumber
CTRL: Recieved command: std_io_err 15C40030
IN: async_open(\pipe\ahexec_stdin15C40030, 2)
IN: async_open(\pipe\ahexec_stdout15C40030, 2)
IN: async_open(\pipe\ahexec_stderr15C40030, 2)
IN: async_open_recv
IN: async_open_recv
IN: async_open_recv

**hangs forever here**

Then ctrl+c:

^CAborting...
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: on_ctrl_pipe_error - NT_STATUS_PIPE_DISCONNECTED

しかし、奇妙なことは、コマンドが失敗しなくても(例えばipconfig / all)、まったく同じ結果が出るということです。

...
IN: async_open(\pipe\ahexec, 2)
IN: async_open_recv
CTRL: Sending command: get version
CTRL: Sending command: run ipconfig /all
CTRL: Recieved command: std_io_err 15C40031
IN: async_open(\pipe\ahexec_stdin15C40031, 2)
IN: async_open(\pipe\ahexec_stdout15C40031, 2)
IN: async_open(\pipe\ahexec_stderr15C40031, 2)
IN: async_open_recv
IN: async_open_recv
IN: async_open_recv

Windows IP Configuration
...
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: smb_raw_read_recv - NT_STATUS_PIPE_DISCONNECTED
ERROR: on_ctrl_pipe_error - NT_STATUS_PIPE_DISCONNECTED

答え1

WMI クライアントはここで使用されます。http://www.orvant.com/packages/Linux で直接 WMIC コマンドを実行できます。ただし、このバージョンは非WQLクエリをサポートしていないため、WQLコマンドと同等のコマンドを使用する必要があります。

答え2

最新のwinexeコード(2013年11月の日付の「現在」のgitリポジトリ、別名「winexe-waf」)をテストすると停止しません。私はUnstableのSamba 4.0.10パッケージを使ってDebian Wheezyにwinexeを構築し、それを実行しました。winexe -U "<user>%<pwd>" //192.168.1.2 'wmic bios get serialnumber'ここで、192.168.1.2は、Windows 7 Professional SP1を実行しているVirtualBox仮想マシンのIPアドレスです。出力は次のとおりです。

$ winexe -U "<user>%<pwd>" //192.168.1.2 'wmic bios get serialnumber'
SerialNumber
0

$ winexe -U "<user>%<pwd>" //192.168.1.2 'wmic computersystem get model'
Model
VirtualBox

答え3

winexeデバッグをオンにしてこのコマンドを試してみましょう。デバッグレベルを上げることができます(0、1、2、3など)。

はい

ここではコマンドをそのまま実行し、スイッチのみを追加します-d 3

$ winexe -A authfile -d 3 //syspc4.domain.com "wmic bios get serialnumber"

ERROR: Unable to open credentials file!
[param/loadparm.c:587:init_globals()] Initialising global parameters
[param/loadparm.c:2462:lp_load()] lp_load: refreshing parameters from /dev/null
[param/params.c:556:pm_process()] params.c:pm_process() - Processing configuration file "/dev/null"
[param/loadparm.c:1343:lp_add_hidden()] adding hidden service IPC$
[param/loadparm.c:1343:lp_add_hidden()] adding hidden service ADMIN$
[auth/credentials/credentials_krb5.c:171:cli_credentials_set_ccache()] failed to get principal from default ccache: No such file or directory: open(/tmp/krb5cc_500): No such file or directory
[winexe/winexe.c:304:main()] winexe version 0.80
This program may be freely redistributed under the terms of the GNU GPL
[auth/auth.c:447:auth_register()] AUTH backend 'winbind_samba3' registered
[auth/auth.c:447:auth_register()] AUTH backend 'winbind' registered
[auth/auth.c:447:auth_register()] AUTH backend 'name_to_ntstatus' registered
[auth/auth.c:447:auth_register()] AUTH backend 'fixed_challenge' registered
[auth/auth.c:447:auth_register()] AUTH backend 'unix' registered
[auth/auth.c:447:auth_register()] AUTH backend 'anonymous' registered
[auth/auth.c:447:auth_register()] AUTH backend 'sam' registered
[auth/auth.c:447:auth_register()] AUTH backend 'sam_ignoredomain' registered
[auth/gensec/gensec.c:1229:gensec_register()] GENSEC backend 'krb5' registered
[auth/gensec/gensec.c:1205:gensec_register()] gensec subsystem fake_gssapi_krb5 is disabled
[auth/gensec/gensec.c:1229:gensec_register()] GENSEC backend 'schannel' registered
[auth/gensec/gensec.c:1229:gensec_register()] GENSEC backend 'spnego' registered
[auth/gensec/gensec.c:1205:gensec_register()] gensec subsystem gssapi_spnego is disabled
[auth/gensec/gensec.c:1229:gensec_register()] GENSEC backend 'gssapi_krb5' registered
[auth/gensec/gensec.c:1229:gensec_register()] GENSEC backend 'gssapi_krb5_sasl' registered
[auth/gensec/gensec.c:1229:gensec_register()] GENSEC backend 'ntlmssp' registered
[lib/util/util.c:334:interpret_addr()] sys_gethostbyname: Unknown host. syspc4.domain.com
[lib/socket/interface.c:103:add_interface()] added interface ip=192.168.1.110 nmask=255.255.255.0
[winexe/winexe.c:322:main()] ERROR: Failed to open connection - NT_STATUS_NO_MEMORY

関連情報