4 posts in this topic
This function (version 1), was developed solely for applications I needed it for.
It was only tested with Class names that was needed in those scripts.
And so, I didn't want to release it by itself because I knew it needed some more
work before I did that.
Recently, I delved back into it after several years and am now releasing version 2,
which was mostly rewritten over the past several weeks.
What does it do? It retrieves the properties and values pertaining to your computer,
operating system and devices. All you need is a valid Win32 Class Name.
So, here it is -- let me know if you have any issues!
Updated to v2.25, January 14, 2017
I did create these few functions several months ago. I post here, if it can interest someone.
These functions based on WMI queries allow you to manage printers : add / delete printer, driver, port, or obtain configuration, set default printer ... I let you discover it with the code.
Here is the list of the available functions :
And some examples :
#Include "PrintMgr.au3" ; Remove a printer called "My old Lexmark printer" : _PrintMgr_RemovePrinter("My old Lexmark printer") ; Remove the driver called "Lexmark T640" : _PrintMgr_RemovePrinterDriver("Lexmark T640") ; Remove the TCP/IP printer port called "TCP/IP" _PrintMgr_RemoveTCPIPPrinterPort("MyOLDPrinterPort") ; Add a driver, called "Samsung ML-451x 501x Series", and driver inf file is ".\Samsung5010\sse2m.inf" _PrintMgr_AddPrinterDriver("Samsung ML-451x 501x Series", "Windows NT x86", @scriptDir & "\Samsung5010", @scriptDir & "\Samsung5010\sse2m.inf") ; Add a TCP/IP printer port, called "MyTCPIPPrinterPort", with IPAddress = 192.168.1.10 and Port = 9100 _PrintMgr_AddTCPIPPrinterPort("MyTCPIPPrinterPort", "192.168.1.10", 9100) ; Add a printer, give it the name "My Printer", use the driver called "Samsung ML-451x 501x Series" and the port called "MyTCPIPPrinterPort" _PrintMgr_AddPrinter("My Printer", "Samsung ML-451x 501x Series", "MyTCPIPPrinterPort") ; Set the printer called "My Printer" as default printer _PrintMgr_SetDefaultPrinter("My Printer") ; Connect to the shared printer "\\192.168.1.1\HPDeskjetColor") _PrintMgr_AddWindowsPrinterConnection("\\192.168.1.1\HPDeskjetColor") ; List all installed printers #Include <Array.au3> $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) ; List all printers configuration #Include <Array.au3> $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration() _ArrayDisplay($aPrinterConfig) ; List all installed printer drivers #Include <Array.au3> $aDriverList = _EnumPrinterDriver() _ArrayDisplay($aDriverList) ; Retrieve the printer configuration for the printer called "Lexmark T640" #Include <Array.au3> $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration("Lexmark T640") _ArrayDisplay($aPrinterConfig) ; Add a local printer port (for a file output) _AddLocalPrinterPort("c:\temp\output.pcl") ; Remove the local port _RemoveLocalPrinterPort("c:\temp\output.pcl") Current version download link :
I'm hoping someone can help me out here.
I have the need to run a program with admin credentials (#RequireAdmin), and then get the SID of the locally logged in account. Not the admin account.
If you look at the attached script, Line 16 uses the @UserName variable and returns the SID for the admin account I used to launch the app.
I want to use line 17 which passes the result of the _GetUsername function which is a username using ($UserName) to the WMIService.
I'm getting " The requested action with this object has failed.:" error message.
Any suggestions would be appreciated!
Hello, I found a VB snippet which I would love to use in AutoIt
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Process") For Each objItem in colItems Wscript.Echo objItem.Name Wscript.Echo objItem.CommandLine Next Despite my best efforts, I am not able to understand a thing from that piece of code . All I know is that it outputs the Name and Commandline of all the processes currently running (Let's see if I am right).
Can anyone help me with convert this into AutoIt? Thanks in Advance!
How to enumerate all properties in an object variable (wmi) when I don't know their names? [SOLVED!]By Irios
First post here, please be gentle
I've spent hours and hours trying to figure out this puzzle. It's impossible to google for because I don't know the precise terminology to use. All msdn links I find are either dead or has been removed like 10 years ago.
Here is a tiny code example:
$objWMIService = ObjGet("winmgmts:") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface Where Name like '%intel%'") For $objItem In $colItems ConsoleWrite($objItem.PacketsPersec & @CRLF) Next In that example I'm using the asterix * and it retrieves all properties in the "Win32_PerfRawData_Tcpip_NetworkInterface" class. But I'm only utilizing "PacketsPersec" in the example.
How could I enumerate all the properties without defining their names beforehand?
(FYI, I do know their names, but the script doesn't know the names)
In other words; how can I use "SELECT *" on any class and output all properties, one by one? Without having to manually specify each property with $objItem.<propertyname> ?
As comparison, using wmic in a cmd shell ...
wmic path Win32_PerfRawData_Tcpip_NetworkInterface Where "Name like '%intel%'" get /value
...and it lists all properties in "Names=Value" manner.
This is sort of the same function I'm looking for. How could I do the same in Autoit?
EDIT: I cannot run a powershell or cmd to "solve" the problem. I need to find a way to do this "internally" in Autoit. I.e. by calling the WMI service directly with ObjGet(winmgmts:) or connect to the WMI system with CreateObject("WbemScripting.SWbemLocator"). Performance is a major factor.