WMI Query SID to User - wmi

I'm looking for a simple WQL query that can convert an Windows user SID to a username.
There are multiple methods that show this being done through wmic or powershell, I am using a python module which is capable of running WQL queries against some local namespace - and would just need a query.
I am using WBEMTest for testing.

Select * FROM win32_accountSID

Related

Can I run a Python script in PowerBI on pre-existing data tables?

I see in the tutorials how to import data using Python. However, is it possible to manipulate a table or create a new one using Python? For example, I import data using Sharepoint. I can't wrap SQL in Python because the databases are only accessible through intranet, which PowerBI is not part of. Therefor, I need to input the data using one of PowerBI's connectors, but I'd like to manipulate the tables using Pandas. Is this possible?
You can use Python scripts to manipulate existing data. This can be done in the "Transform" tab under the Edit queries section. There is an option to select "Run Python Script". Once you select this option a dialog box will open and you can write the Python script you want. If you run into any issues you can refer to the following video:
https://www.youtube.com/watch?v=pF_JZk_ghCM
Hope this helps.

DB / TABLE specific query results location

How can I create a query result location specific to a database / table when I am querying data using AWS console. At the moment I see "query results location" in settings but it seems to be a global setting which is applicable to all databases. Is there a way to tweak the below table creation script or use any other mechanism to specify db / table specific results location when querying using aws console?
my query
CREATE EXTERNAL TABLE IF NOT EXISTS SAMPLE (
customer_id String,
customer_name String
)
STORED AS PARQUET
LOCATION 's3://<bucket>/files/';
The closest you can get is to use the new Work Groups feature. Create a new work group and set its result location, and use this work group when running queries from the console.
It won't be something you would do per query, but I'm not sure if that is what you're asking for.
Running queries from the console is more limited than using the API, as you probably know when using the StartQuertExecution API call you can specify the output location for that specific query to be any location on S3, but when the console is an application that abstracts away all of that and is not really made to support the full API.

Trying find state for services in Win32_Service

I am using wbemtest.exe to execute WQL queries. My goal is to obtain the state of services in Win32_Service class. My query is select State from Win32_Service where DisplayName="Windows Defender". The result I am expecting is Win32_Service.State=Stopped/Running, but it is showing Win32_Service=<no key>. If I do select * from Win32_Service where DisplayName="WIndows Defender", I obtain the only Win32_Service.Name=WinDefend". Thanks in advance.

WQL Subquery as field value, CIMV2 WMI WQL query for WMI-Filter

I need help on a WMI query for a Group Policy WMI-Filter. I'm querying the win32_group namespace within the root\CIMV2 WMI provider.
I am doing a search for a Local Security group (like "Administrators") on several window's computer (XP-8, server 03-12). When the query runs on a computer I would like it to inject the computer name into the equivalency field for the Domain.
The base WQL statement looks like this:
SELECT * FROM win32_group
WHERE Domain="currentComputerName" and Name="Administrators"
My goal is to run a WQL statement along these lines, but it is a bad WQL statement:
SELECT * FROM win32_group
WHERE Domain=(SELECT Name FROM Win32_ComputerSystem) and Name="Administrators"
It is important that I am able to inject the current computer's name for the Domain. These computers are part of a Active Directory (AD) domain. By default the win32_group will search all of the AD Domain's groups in addition to the Local Computer's security group (if omitting the Domain parameter). By specifying the local machine name as the domain the query's performance is multitudes faster - which is essential for its purpose.
I have tried some query variations in WBEMTEST with no luck. Does anybody have any ideas on how to inject the computer's name into the WQL WMI Query? Is there possibly a constant that I could use, like HOSTNAME at the command prompt?
Thank you for your help!
What language are you writing this in? Or to be clear, what programming or scripting language you are using to run these WMI queries?
In PowerShell, you could do this by running the following code:
Get-WMIObject -Query "SELECT * FROM Win32_Group WHERE Domain='$env:USERDOMAIN' AND Name='Administrators'"

How to query a DB table from C++

I have C++ code, and from it I need to access the DB and make a query in table (with name NECE_TABLE, which has 2 columns - IntID and Status).
Here I need to get "status" column value from DB table (NECE_TABLE) using the IntID from C++ code.
Any help will be greatly helpful. Thanks in advance
Your question is very vague, but in summary you need to:
Use an appropriate client library supported by your database to connect to that database using some user credentials with appropriate permissions for SELECTing from your table
Execute a SQL select to fetch the data you want
There's some confusion as to which database you're using.
If you're using Oracle, you can use the OCCI client library to connect to the database and execute SQL statements. See section 2 of the linked document, where it describes connecting to a database and executing SQL queries.
Take a look at this link - it's a simple tutorial on how to get started with MySQL and C++. You say you are using vanilla SQL in your tags, but the two should be compatible as long as you stick to the more basic queries.