Editing device manager using powershell

时间:2015-07-28 23:19:55

标签: powershell device-manager wasp

Part of my work routine involves frequently enabling/disabling network adapters in the device manager, which is tedious and time consuming. I am learning PowerShell, and want to write a simple script that automatically enables/disables the network adapter.

I am trying to use the WASP snap-in, which doesn't seem too difficult, but I cannot get it to work.

So far I have:

    # Launch the Device Manager
    $deviceManager = Show-ControlPanelItem -Name "Device Manager"

    # Display all currently open windows. Device Manager should display as 'mmc'
    Select-Window | ft -auto

    # Select Device Manager as the active window
    Select-Window mmc | Set-WindowActive

    # Send input to device manager
    Select-Window mmc | Send-Keys "{TAB}"
    Select-Window mmc | Send-Keys "n"

If the keyboard inputs are read properly, Network Adapter should be highlighted in Device Manager. Instead, the device manager is opened and is active, but otherwise nothing happens.

What am I doing wrong? How do I send keyboard input properly using WASP? WASP is not required, I am open to other tools if a superior option is available.

1 个答案:

答案 0 :(得分:3)

Try working with #include <stdio.h> #include <stdint.h> //#define inf_int volatile unsigned long long #define inf_int uint64_t int main(int argc, char *argv[]){ inf_int zero = 0; inf_int one = 1; inf_int infinity = ~0; printf("value of zerao, one, infinity = %lu, %lu, %lu\n", zero, one, infinity); __asm__ volatile ( "addq $1, %0 \n\t" : "=r" (zero) ); __asm__ volatile ( "addq $1, %0 \n\t" : "=r" (one) ); __asm__ volatile ( "addq $1, %0 \n\t" : "=r" (infinity) ); printf("value of zero, one, infinity = %lu, %lu, %lu\n", zero, one, infinity); return 0; } instead:

This will give you a list of your adapters:

WMI

You can use a filter on Get-WmiObject -Class Win32_NetworkAdapter to isolate a single adapter and assign the object to a variable:

Name

Then, you should be able to call $adapter = Get-WmiObject -Class Win32_NetworkAdapter -filter "Name LIKE '%MyAdapterName%'" , disable, enable, etc. on the object:

reset

Good luck!