Page 1 sur 1

[RESOLVED] wmi_info & remote commands

Publié : 23 mars 2018 - 17:56
par empbilly
Hi folks,

How can I declare the wmi_filter option? Can it be as below?

Code : Tout sélectionner

wmi_info(keys=['Win32_NetworkAdapter'])['name']['index']

Re: wmi_info

Publié : 23 mars 2018 - 19:17
par dcardon
Hi Empbilly,
empbilly a écrit : 23 mars 2018 - 17:56 Hi folks,

How can I declare the wmi_filter option? Can it be as below?

Code : Tout sélectionner

wmi_info(keys=['Win32_NetworkAdapter'])['name']['index']
wmi_info gives out a data structure out of wmi module. You can just print the data structure or its inner parts:

Code : Tout sélectionner

wmi_data = wmi_info(keys=['Win32_NetworkAdapter'])['Win32_NetworkAdapter']
print wmi_data
print(wmi_data[0].keys())
for item in wmi_data:
    print item['Caption']


Cheers,

Denis

Re: wmi_info

Publié : 23 mars 2018 - 20:45
par empbilly
From the example above, I could make a script that disable via wapt, for example a computer wireless card?

Re: wmi_info

Publié : 24 mars 2018 - 23:33
par dcardon
Hi empbilly,
empbilly a écrit : 23 mars 2018 - 20:45 From the example above, I could make a script that disable via wapt, for example a computer wireless card?
wmi_info() just give out a python list/dict datastructure with information for inventory. You cannot do any action out of that wmi_info() function. However you can import wmi python module and use it in your script.

Regarding the specific subject of your question, if you have the name of the interface, then you could use netsh with something like:

Code : Tout sélectionner

netsh interface set interface "network_adapter_name" admin=disable
But it is not always easy to get the network_adapter_name right, especially if your Windows is not an English one and has accent in the name...

Cheers,

Denis

Re: wmi_info

Publié : 26 mars 2018 - 19:46
par empbilly
Okay. I'm trying to make the script below work. The problem is the accent on the text "Conexão local 2" that the "con" variable receives. I tried several ways to decode and encode to utf-8, but without success.

>>> con = 'Conexão local 2'.decode('utf-8')
>>> print con
Conexão local 2
>>> con
u'Conex\xe3o local 2'
>>>

How can I solve this problem?

Code : Tout sélectionner

# -*- coding: utf-8 -*-
from setuphelpers import *
import subprocess

uninstallkey = []

con = 'Conexão local 2'

def install():
    print "Instalando Wi-fi adapter disable"
    try:
        x = subprocess.Popen(["cmd.exe", "/c", "wmic path win32_networkadapter where NetConnectionID='%s' call disable" % (con)], stdout=subprocess.PIPE, shell=True)
        print (x.stdout.read())
    except (RuntimeError, TypeError, NameError):
        print "Erro na execução do cmd.exe"

Re: wmi_info

Publié : 26 mars 2018 - 21:27
par empbilly
Now, it's works!!! :D

Code : Tout sélectionner

# -*- coding: UTF-8 -*-
from setuphelpers import *
import subprocess
import locale

uninstallkey = []

con = u'Conexão de Rede sem Fio'

def install():
    print u"Exercutando Wi-fi card disable"
    try:
        x = subprocess.Popen(["cmd.exe", "/c", "wmic path win32_networkadapter where NetConnectionID='%s' call disable" % (con.encode(locale.getpreferredencoding()))], stdout=subprocess.PIPE, shell=True)
        print (x.stdout.read())
    except (RuntimeError, TypeError, NameError):
        print u"Erro na execução do cmd.exe"

Re: [RESOLVED] wmi_info & remote commands

Publié : 26 mars 2018 - 21:34
par vcardon
Hello Empbilly,

I see portuguese comments in your script to disable wifi connexions, are you writing from Brazil ?

If that's the case, that would be just cool to start having WAPT in South America.

If your language is Portuguese, do you feel it would be useful to have WAPT internationalized in Portuguese, or do you feel that adminsys are sufficiently familiar with English where you live ?

Thanks.

Vincent

Re: [RESOLVED] wmi_info & remote commands

Publié : 27 mars 2018 - 02:14
par empbilly
I see portuguese comments in your script to disable wifi connexions, are you writing from Brazil ?
Yes. I live in Brazil and work in an education institution.

If that's the case, that would be just cool to start having WAPT in South America.
:D

If your language is Portuguese, do you feel it would be useful to have WAPT internationalized in Portuguese, or do you feel that adminsys are sufficiently familiar with English where you live ?
I think it would be great to have, mainly, the wapt documentation in Portuguese. Speaking of the sysadmins of our institution as a whole, more or less about 20 campus, the vast majority do not have an intermediary to advanced skills in English.