[RESOLVED] wmi_info & remote commands

Share your tips or issues concerning the WAPT Console or WAPT Agent here
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
Empbilly
Messages: 79
Registration: January 15, 2018 - 8:59 PM

March 23, 2018 - 5:56 PM

Hi folks,

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

Code: Select all

wmi_info(keys=['Win32_NetworkAdapter'])['name']['index']
Last edited by empbilly on March 26, 2018 - 9:28 PM, edited 1 time.
User avatar
dcardon
WAPT Expert
Messages: 1930
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

March 23, 2018 - 7:17 PM

Hi Empbilly,
empbilly wrote: March 23, 2018 - 5:56 PM Hi folks,

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

Code: Select all

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: Select all

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
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
Empbilly
Messages: 79
Registration: January 15, 2018 - 8:59 PM

March 23, 2018 - 8:45 PM

From the example above, I could make a script that disable via wapt, for example a computer wireless card?
User avatar
dcardon
WAPT Expert
Messages: 1930
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

March 24, 2018 - 11:33 PM

Hi Empbilly,
empbilly wrote: March 23, 2018 - 8:45 p.m. 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: Select all

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
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
Empbilly
Messages: 79
Registration: January 15, 2018 - 8:59 PM

March 26, 2018 - 7:46 PM

Okay. I'm trying to make the script below work. The problem is the accent on the text "Conexhaso 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: Select all

# -*- 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"
Empbilly
Messages: 79
Registration: January 15, 2018 - 8:59 PM

March 26, 2018 - 9:27 PM

Now it works!!! :D

Code: Select all

# -*- 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"
User avatar
vcardon
WAPT Expert
Messages: 278
Registration: Oct 06, 2017 - 10:55 p.m.
Location: Nantes, France

March 26, 2018 - 9:34 PM

Hello Empbilly,

I see portuguese comments in your script to disable wifi connections, 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
Empbilly
Messages: 79
Registration: January 15, 2018 - 8:59 PM

March 27, 2018 - 02:14

I see portuguese comments in your script to disable wifi connections, 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 campuses, the vast majority do not have an intermediary to advanced skills in English.
Locked