Last active
August 23, 2025 12:33
-
-
Save ukoloff/ea6c23d1572fb5b50e97d6683d0cb13f to your computer and use it in GitHub Desktop.
WMI samples using JScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check Admin rights | |
| var out = GetObject("winmgmts://./root/default:StdRegProv") .EnumKey(1 << 31 | 3, "S-1-5-20") | |
| WScript.Echo("Admin =", !out) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enum Network adapters asynchronously | |
| +function(){ | |
| var wmi = GetObject("winmgmts://./root/CIMv2") | |
| var sink = WScript.CreateObject("WbemScripting.SWbemSink", ">") | |
| var done | |
| wmi.ExecQueryAsync(sink, "SELECT * FROM Win32_NetworkAdapter Where PhysicalAdapter = True") | |
| +function() | |
| { | |
| this['>OnObjectReady'] = onObjectReady | |
| this['>OnCompleted'] = onCompleted | |
| }() | |
| while(!done) | |
| WScript.Sleep(100) | |
| function onObjectReady(adapter) | |
| { | |
| WScript.Echo("- " + adapter.NetConnectionID); | |
| } | |
| function onCompleted() | |
| { | |
| done = true | |
| } | |
| }() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enum Network adapters | |
| var wmi = GetObject("winmgmts://./root/CIMv2") | |
| var net = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter Where PhysicalAdapter = True") | |
| for (var e = new Enumerator(net); !e.atEnd(); e.moveNext()) | |
| { | |
| var z = e.item() | |
| WScript.Echo("- " + z.NetConnectionID); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enum Registry keys | |
| var reg = GetObject("winmgmts://./root/default:StdRegProv") | |
| var inx = reg.Methods_("EnumKey").InParameters.SpawnInstance_() | |
| inx.hDefKey = 0x80000003 // HKEY_USERS | |
| inx.sSubKeyName = "S-1-5-20" | |
| var out = reg.ExecMethod_("EnumKey", inx) | |
| WScript.Echo("Value =", out.ReturnValue) | |
| if(!out.ReturnValue) | |
| WScript.Echo('Keys = ', out.sNames.toArray().join(', ')) |
Author
What error specifically?
And how do you run this script? Try: cscript admin.js
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this GetObject function is giving me error.
is there something extra to be included?