?
Solved

Batch File: Network Card (disable feature)

Posted on 2011-10-27
12
Medium Priority
?
1,528 Views
Last Modified: 2012-05-12
Hi there,

I need to disable the following management feature of all NICs on remote PCs:
"Allow the computer to turn off this device to save power"

I need to fix or replace the WMIC command lines and to complete the batch file.

Thanks for all you help.
Rene

@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET LogFile=%~dpn0.log
FOR /F %%A IN ('net view ^| FINDSTR -I "\\PC \\Wrk"') DO (
	SET PC=%%A
	SET PC=!PC:\\=!
	FOR /F %%B IN ('WMIC /NODE:!PC! list NIC') DO (
		FOR /F %%C IN ('WMIC /NODE:!PC! Read status /NIC:%%B "Allow the computer to turn off this device to save power"') DO (
			ECHO %%A %%B %%C
			ECHO %%A %%B %%C>>"%LogFile%"
			IF %%C EQU CHECKED WMIC /NODE!PC! unckeck /NIC:%%B "Allow the computer to turn off this device to save power"
		)
	)
)
PAUSE
EXIT

Open in new window

0
Comment
Question by:ReneGe
  • 8
  • 4
12 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 37046471
@Rene,

I took a slight look at this, and I think it likely involved changing a value in the registry rather than via WMIC.  WMIC NIC could be used to enumerate the nics, but there will be more of them than are physical, so likely need to filter by something like "PhysicalAdapter" flag, but not sure.  Once you have that you can get the index of the card, and use that to update the registry, as in the links below.  I'm not sure if this varies in Win7/Vista versus earlier.

I don't have time to poke at this more right now, but wanted to pass along some of the research I had done in case you did.

http://support.microsoft.com/?kbid=837058
http://community.spiceworks.com/scripts/show/240-script-to-enable-wake-on-lan-windows
http://www.hofferle.com/archives/302

~bp

0
 
LVL 10

Author Comment

by:ReneGe
ID: 37046560
That should do: http://support.microsoft.com/?kbid=837058
Will post my script when done.
Thanks Bill
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37046698
Sorry I don't have more time to build something today, but let me know if you get stuck along the way.

And can you try to make you scripts look more like mine, yours are so hard to read sometimes :-)

~bp
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Author Comment

by:ReneGe
ID: 37047837
Here is my working script.

I did not find a way to make a clean display.

Also, I would like to REG ADD in Hex, not Dec.

When you have time, would you mind tweeking it up?


Thanks and cheers,
Rene
@ECHO OFF
SET LogFile=%~dpn0.log

FOR /F %%a IN ('NET VIEW ^| FINDSTR -i "\\PC \\WRK"') DO (
   FOR /f "delims=" %%A IN ('Reg query "%%a\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"') DO (
      FOR /F "tokens=3" %%B IN ('Reg query "%%A" /V "PnPCapabilities" ^| FINDSTR -i "PnPCapabilities"') DO (
         ECHO "%%a" "%%A" "%%B"
         ECHO %date% %time% "%%a" "%%A" "%%B">>"%LogFile%"
         IF /i "%%B" NEQ "0x38" (
            REG add "%%A" /v PnPCapabilities /t reg_dword /d "56" /f
            FOR /F "tokens=3" %%C IN ('Reg query "%%A" /V "PnPCapabilities" ^| FINDSTR -i "PnPCapabilities"') DO (
               ECHO "%%a" "%%A" "%%C"
               ECHO %date% %time% "%%a" "%%A" "%%C">>"%LogFile%"
            )
         )
      )
   )
)
PAUSE
EXIT

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 37047987
I found that some NIC REG settings did not include "PnPCapabilities". So changed what I am looking for, in order to determine if it is a NIC. Do you have a better suggestion than "DuplexMode"?

Thanks,
Rene
@ECHO OFF
SET LogFile=%~dpn0.log
IF EXIST "%LogFile%" DEL "%LogFile%"
FOR /F %%a IN ('NET VIEW ^| FINDSTR -i "\\PC \\WRK"') DO (
   FOR /f "delims=" %%A IN ('Reg query "%%a\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"') DO (
      FOR /F "tokens=3" %%B IN ('Reg query "%%A" /V "DuplexMode" ^| FINDSTR -i "DuplexMode"') DO (
         FOR /F "tokens=3" %%C IN ('Reg query "%%A" /V "PnPCapabilities" ^| FINDSTR -i "PnPCapabilities"') DO (
            TITLE "%%a" "%%C"
            ECHO "%%a" "%%A" "%%C"
            ECHO %date% %time% "%%a" "%%A" "%%C">>"%LogFile%"
            IF /i "%%C" NEQ "0x38" (
               REG add "%%A" /v PnPCapabilities /t reg_dword /d "56" /f
               FOR /F "tokens=3" %%D IN ('Reg query "%%A" /V "PnPCapabilities" ^| FINDSTR -i "PnPCapabilities"') DO (
                  ECHO "%%a" "%%A" "%%D"
                  ECHO %date% %time% "%%a" "%%A" "%%D" *** FIXED ***>>"%LogFile%"
               )
            )
         )
      )
   )
)
PAUSE
EXIT

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 37048149
Finally, the logic does not work that well. I will post a new version later.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37065687
Here is a version that works.

Not exactly what I wanted, but hey, this is not me on a mission to save the world, at least this time :)

1-Do you have an idea to make it's display cleaner?
2-How can I enter the value of REG ADD in hex, not DEC?

Thanks for your help,
Rene

@ECHO OFF
SET LogFile=%~dpn0.log
IF EXIST "%LogFile%" DEL "%LogFile%"
FOR /F %%A IN ('NET VIEW ^| FINDSTR -i "\\PC"') DO (
   FOR /f "delims=" %%B IN ('Reg query "%%A\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"') DO (
      FOR /F "tokens=3" %%C IN ('REG QUERY "%%A\%%B" /V "BusType" ^| FINDSTR -i BusType') DO (
         IF %%C EQU 5 (
            ECHO.
            ECHO.
            ECHO %%A
            ECHO ---------------------------------------------------
            FOR /F "tokens=3" %%D IN ('REG QUERY "%%A\%%B" /V "PnPCapabilities" ^| FINDSTR -i PnPCapabilities') DO (
               IF "%%D" NEQ "0x38" (
                  ECHO %date% %time% "%%A\%%B\PnPCapabilities" [%%D]
                  ECHO %date% %time% "%%A\%%B\PnPCapabilities" [%%D]>>"%LogFile%"
               )
            )
            REG ADD "%%A\%%B" /v PnPCapabilities /t reg_dword /d "56" /f
            FOR /F "tokens=3" %%D IN ('REG QUERY "%%A\%%B" /V "PnPCapabilities" ^| FINDSTR -i PnPCapabilities') DO (
               ECHO %date% %time% "%%A\%%B\PnPCapabilities" [%%D]
               ECHO %date% %time% "%%A\%%B\PnPCapabilities" [%%D]>>"%LogFile%"
            )
            ECHO.
         )
      )
   )
)
PAUSE
EXIT

Open in new window

0
 
LVL 10

Author Closing Comment

by:ReneGe
ID: 37067060
Thanks Bill :)
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37067488
ReneGe

I found this example that seems to demonstrate adding a value using hex.

REG ADD "HKCU\Software\Microsoft\Windows Mail\Mail" /v "Font Size" /t REG_DWORD /d 0x00000009 /f

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37067591
Thanks. I'll try this tomorrow.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37071081
So it seems that adding to "0x" to the number makes it HEX.

Thanks Bill :)
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37071106
Yeppers.

~bp
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Introduction to Processes
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question