Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post

Link to post

Share on other sites

iamtheky 570

That service is also intentionally disabled by many STIGs, with no rights available to a script to turn it on. I think the latest Gold Disc even contains the powershell package, the feature is just not enabled and installed by default. But (when dealing with hardened envrionments) I would assume neither were available and aim for the registry, or offline package install and reimage.

Share this post

Link to post

Share on other sites

JLogan3o13 961

I encountered what boththose is referencing in a hospital client a year or so ago. Had a script that relied heavily on WMI but was something they'd turned off through their hardening process. I think it is still an exception to the rule, however, as I see it enabled in 99% of the places I work.

Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Similar Content

Hello,
In Windows 10 PowerShell, one can do this to change the metric for a NIC in Windows 10:
Get-NetAdapter | Where-Object -FilterScript {$_.InterfaceAlias -Eq "Ethernet 2"} | Set-NetIPInterface -InterfaceMetric 2
I know I can script the above PowerShell line (and it works!), but I wanted to try something I hadn't done before after looking into jguinch's most excellent Network configuration UDF. I wanted to make use of the SetIPConnectionMetric method in the WMI classes. There is an example VBscript here but this is not for Windows 10. Using AutoIT would also give better control over capturing error return codes than with PowerShell.
But I cannot get my script to work! The return from SetIPConnectionMetric() is 0, which would indicate success. Yet the change does not happen. I also tried WMI methods using .put_ but this fails.
Anyone more experienced than I have ideas to make this work?
#RequireAdmin
_SetNicInterfaceMetric2("Ethernet 2", "2")
Func _SetNicInterfaceMetric2($NIC_NAME, $METRIC)
Local $s_setIndx = 0
$objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
$colNICItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & $NIC_NAME & "'", "WQL")
If IsObj($colNICItems) Then
For $objItem In $colNICItems
$s_nicIndex = $objItem.Index
Next
ConsoleWrite("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'" & @CRLF)
$colNAC = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'", "WQL")
If IsObj($colNAC) Then
For $objNetCard In $colNAC
If $METRIC <> $objNetCard.IPConnectionMetric Then
ConsoleWrite("Metric was set to " & $objNetCard.IPConnectionMetric & ". Setting to " & $METRIC & "." & @CRLF)
$s_isSet = $objNetCard.SetIPConnectionMetric($METRIC)
ConsoleWrite("SetIPConnectionMetric Result = " & $s_isSet & @CRLF)
Else
ConsoleWrite("Metric is already set to " & $METRIC & @CRLF)
EndIf
Next
EndIf
EndIf
EndFunc ;==>_SetNicInterfaceMetric2

Hello.
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 an UDF for managing printers.
Features are :
- add, remove or rename a printer
- add or remove a driver
- add or remove a TCP/IP printer port
- add or remove a LPR printer port
- connect to a remote printer
- enum printers and there configuration and properties
- pause resume or cancel all jobs of a printer
- checks if a printer exists
- print a test page
- set the default printer

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
Download: _WMI_InstancesOf_v2.25.au3