Batch script to delete network driver

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
kennedydid911
Posts: 11
Joined: 08 Aug 2016 09:40

Batch script to delete network driver

#1 Post by kennedydid911 » 08 Aug 2016 09:47

Hey,

i want a batch script that deletes this: Image driver and than shuts down the computer.

How can someone achieve that?

Thanks.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch script to delete network driver

#2 Post by aGerman » 08 Aug 2016 14:16

I don't know where you made this screen shot. Displayed names may differ from names that command tools return.
Run the following line in a cmd.exe window and tell us what output you get:

Code: Select all

wmic sysdriver where "displayname like 'VIA Rhine%'" get displayname

Regards
aGerman

kennedydid911
Posts: 11
Joined: 08 Aug 2016 09:40

Re: Batch script to delete network driver

#3 Post by kennedydid911 » 09 Aug 2016 03:46

Image

This is the result if I run this code.

kennedydid911
Posts: 11
Joined: 08 Aug 2016 09:40

Re: Batch script to delete network driver

#4 Post by kennedydid911 » 09 Aug 2016 04:11

I want to imitate deleting the driver from the device manager like this:
Image

If I do this:
Image
it doesn't really help, I want Windows to reinstall the driver when I boot the PC, so, I mean, completely uninstall it.

I'm really new to this thing.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Batch script to delete network driver

#5 Post by Squashman » 09 Aug 2016 08:36

kennedydid911 wrote:Image

This is the result if I run this code.

Did you know that you can copy and paste from the cmd Window and then just edit the text you want to obfuscate. Alot easier then editing an image file and then uploading it to a file sharing site.

Code: Select all

C:\Users\Squashman>wmic sysdriver where "displayname like 'Intel%'" get displayname
DisplayName
Intel AGP Bus Filter

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to delete network driver

#6 Post by foxidrive » 09 Aug 2016 09:56

Microsoft has a command-line tool to perform tasks like those done in device manager
It's called devcon.exe

kennedydid911
Posts: 11
Joined: 08 Aug 2016 09:40

Re: Batch script to delete network driver

#7 Post by kennedydid911 » 09 Aug 2016 12:05

I want to run that batch script whenever my PC shuts down, is this possible with that devcon.exe?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to delete network driver

#8 Post by foxidrive » 09 Aug 2016 14:36

kennedydid911 wrote:I want to run that batch script whenever my PC shuts down, is this possible with that devcon.exe?


Devcon doesn't change when a batch script runs. ;)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch script to delete network driver

#9 Post by aGerman » 09 Aug 2016 15:54

That's not a matter of devcon. Do you want to automatically trigger a batch script that deletes the network adapter when you shut down your PC? Or would you rather run a script manually that deletes the network adapter and afterwards shuts down you PC?

Regards
aGerman

kennedydid911
Posts: 11
Joined: 08 Aug 2016 09:40

Re: Batch script to delete network driver

#10 Post by kennedydid911 » 10 Aug 2016 09:51

That automatic triggering method would be ideal, but if the only solution is a batch file on my desktop to shut down my PC, I would be happy with that too.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch script to delete network driver

#11 Post by aGerman » 10 Aug 2016 10:31

OK a fast script could probably run in the time between triggering the shutdown and the shutdown itself. Without any warranty ...
I assume you already downloaded devcon.exe.

- Create folder "C:\scripts"
- Copy devcon.exe into this folder.
- Save this code into this folder as "at_shutdown.bat" :

Code: Select all

@echo off &setlocal
cd /d "%~dp0"
for /f "delims=:" %%i in ('devcon.exe listclass net^|find "VIA Rhine"') do for /f %%j in ("%%i") do devcon.exe remove "%%j"

(Do not change any of these folder/file names!)


Now create a scheduled task that will run the batch file in the SYSTEM account (elevated, you don't even see the window flashing up) if the shutdown was triggered (Event ID 1074). If you don't know how to do that you can run the following code via right click -> "Run as Administrator".

Code: Select all

@echo off &setlocal
cd /d "%~dp0"
for /f "tokens=2 delims=:" %%i in ('chcp') do set /a oemcp=%%~ni
>nul chcp 1252
set "taskname=run_at_shutdown"
set "xmlfile=run_at_shutdown.xml"

set "line_01=<?xml version="1.0" encoding="UTF-16"?>"
set "line_02=<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">"
set "line_03=  <RegistrationInfo>"
set "line_04=    <Author>aGerman @ DosTips</Author>"
set "line_05=    <URI>\run_at_shutdown</URI>"
set "line_06=    <Description>Run Script At Shutdown</Description>"
set "line_07=  </RegistrationInfo>"
set "line_08=  <Triggers>"
set "line_09=    <EventTrigger>"
set "line_10=      <Enabled>true</Enabled>"
set "line_11=      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="System"&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='User32'] and EventID=1074]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>"
set "line_12=    </EventTrigger>"
set "line_13=  </Triggers>"
set "line_14=  <Principals>"
set "line_15=    <Principal id="Author">"
set "line_16=      <UserId>S-1-5-18</UserId>"
set "line_17=      <RunLevel>HighestAvailable</RunLevel>"
set "line_18=    </Principal>"
set "line_19=  </Principals>"
set "line_20=  <Settings>"
set "line_21=    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>"
set "line_22=    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>"
set "line_23=    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>"
set "line_24=    <AllowHardTerminate>false</AllowHardTerminate>"
set "line_25=    <StartWhenAvailable>false</StartWhenAvailable>"
set "line_26=    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>"
set "line_27=    <IdleSettings>"
set "line_28=      <StopOnIdleEnd>false</StopOnIdleEnd>"
set "line_29=      <RestartOnIdle>false</RestartOnIdle>"
set "line_30=    </IdleSettings>"
set "line_31=    <AllowStartOnDemand>true</AllowStartOnDemand>"
set "line_32=    <Enabled>true</Enabled>"
set "line_33=    <Hidden>false</Hidden>"
set "line_34=    <RunOnlyIfIdle>false</RunOnlyIfIdle>"
set "line_35=    <WakeToRun>false</WakeToRun>"
set "line_36=    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>"
set "line_37=    <Priority>5</Priority>"
set "line_38=  </Settings>"
set "line_39=  <Actions Context="Author">"
set "line_40=    <Exec>"
set "line_41=      <Command>C:\Windows\System32\cmd.exe</Command>"
set "line_42=      <Arguments>/c "C:\scripts\at_shutdown.bat"</Arguments>"
set "line_43=    </Exec>"
set "line_44=  </Actions>"
set "line_45=</Task>"

<nul >"%xmlfile%" set /p "=ÿþ"
>>"%xmlfile%" cmd /u /q /c "for /f "tokens=1* delims==" %%i in ('set line_') do echo %%j"
>nul chcp %oemcp%
schtasks /create /xml "%xmlfile%" /tn "%taskname%" /f
del "%xmlfile%"
pause

Regards
aGerman

kennedydid911
Posts: 11
Joined: 08 Aug 2016 09:40

Re: Batch script to delete network driver

#12 Post by kennedydid911 » 11 Aug 2016 04:28

If I create a scheduled task before shutting down the PC the script does not delete the driver.

So I tried just running the at_shutdown.bat, and I get this message: No devices removed.

What should I do next?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch script to delete network driver

#13 Post by aGerman » 11 Aug 2016 11:12

Code: Select all

@echo off &setlocal
cd /d "%~dp0"
devcon listclass net
pause

Run that script in "C:\scripts" as administrator and please post the line of interest.

Regards
aGerman

kennedydid911
Posts: 11
Joined: 08 Aug 2016 09:40

Re: Batch script to delete network driver

#14 Post by kennedydid911 » 12 Aug 2016 02:43

Code: Select all

Listing 10 device(s) for setup class "Net" (Network adapters).
ROOT\MS_AGILEVPNMINIPORT\0000                               : WAN Miniport (IKEv
2)
ROOT\MS_L2TPMINIPORT\0000                                   : WAN Miniport (L2TP
)
ROOT\MS_NDISWANBH\0000                                      : WAN Miniport (Netw
ork Monitor)
ROOT\MS_NDISWANIP\0000                                      : WAN Miniport (IP)
ROOT\MS_NDISWANIPV6\0000                                    : WAN Miniport (IPv6
)
ROOT\MS_PPPOEMINIPORT\0000                                  : WAN Miniport (PPPO
E)
ROOT\MS_PPTPMINIPORT\0000                                   : WAN Miniport (PPTP
)
ROOT\MS_SSTPMINIPORT\0000                                   : WAN Miniport (SSTP
)
PCI\VEN_1106&DEV_3106&SUBSYS_747C1462&REV_8B\4&1F7DBC9F&0&48F0: VIA Rhine III Fa
st Ethernet Adapter
ROOT\*ISATAP\0000                                           : Microsoft ISATAP A
dapter
Press any key to continue . . .

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch script to delete network driver

#15 Post by aGerman » 12 Aug 2016 09:53

Hmm. Looks correct :? Maybe the device has to be disabled beforehand.
You may run another test with a little more verbose output.

Code: Select all

@echo off &setlocal
cd /d "%~dp0"

devcon listclass net|find "VIA Rhine"
ECHO(

for /f "delims=:" %%i in ('devcon listclass net^|find "VIA Rhine"') do for /f %%j in ("%%i") do (
  ECHO devcon disable "%%j"
  devcon disable "%%j"
  ECHO devcon remove "%%j"
  devcon remove "%%j"
)
pause

Regards
aGerman

Post Reply