[RESOLVED] wmi_info & remote commands

Share here your tips or issues concerning WAPT Console or WAPT Agent / Venez ici partager vos problèmes et astuces concernants la console et l'agent WAPT
Règles du forum
* Questions can be asked in English or in French. If the thread is started in English, stick to English, if it is started in French, stick to French.
* Vous pouvez poser vos questions en Français ou en Anglais. Si un sujet est commencé en français, merci de répondre en français. Si un sujet est commencé en anglais, merci de répondre en anglais.
Avatar de l’utilisateur
empbilly
Messages : 66
Inscription : 15 janv. 2018 - 20:59

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']
Dernière modification par empbilly le 26 mars 2018 - 21:28, modifié 1 fois.
Avatar de l’utilisateur
dcardon
Expert WAPT
Messages : 286
Inscription : 18 juin 2014 - 09:58
Localisation : Nantes
Contact :

23 mars 2018 - 19:17

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
Denis Cardon - Tranquil IT Systems
Communiquez autour de vous sur WAPT! Envoyez nous vos url de blog et d'articles dans la catégorie votre avis du forum, nous les mettrons en avant sur le site WAPT
Avatar de l’utilisateur
empbilly
Messages : 66
Inscription : 15 janv. 2018 - 20:59

23 mars 2018 - 20:45

From the example above, I could make a script that disable via wapt, for example a computer wireless card?
Avatar de l’utilisateur
dcardon
Expert WAPT
Messages : 286
Inscription : 18 juin 2014 - 09:58
Localisation : Nantes
Contact :

24 mars 2018 - 23:33

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
Denis Cardon - Tranquil IT Systems
Communiquez autour de vous sur WAPT! Envoyez nous vos url de blog et d'articles dans la catégorie votre avis du forum, nous les mettrons en avant sur le site WAPT
Avatar de l’utilisateur
empbilly
Messages : 66
Inscription : 15 janv. 2018 - 20:59

26 mars 2018 - 19:46

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"
Avatar de l’utilisateur
empbilly
Messages : 66
Inscription : 15 janv. 2018 - 20:59

26 mars 2018 - 21:27

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"
Avatar de l’utilisateur
vcardon
Expert WAPT
Messages : 81
Inscription : 06 oct. 2017 - 22:55
Localisation : Nantes, FR

26 mars 2018 - 21:34

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
Vincent CARDON
Tranquil IT
Avatar de l’utilisateur
empbilly
Messages : 66
Inscription : 15 janv. 2018 - 20:59

27 mars 2018 - 02:14

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.
Répondre