; Let's uninstall everything in reverse sequence that we installed
; Uninstall network management
killapp nvNetUtils.exe
set NAM_GUID={8797FC40-AE6F-4AF3-9485-0A51668A46CE}
Call UninstallNAM
set NAM_GUID={1F6423DE-7959-4178-80E0-023C7EAA5347}
Call UninstallNAM
Call UninstallNewNAM


; Uninstall function driver
call functiondriveruninst

; Uninstall bus driver
call busdriveruninst


del {sysdir}\capabilitytable.exe
DelRegE HKCU\Software\NVIDIA Corporation
DelReg HKLM\System\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\Descriptions\NVIDIA nForce Networking Controller
DelBoot {current Script}


[busdriverUninst]
Set Display Name=Nvidia Network Bus Enumerator 
; Remove any NVIDIA device driver if present
UninstallService nvnetbus
RemoveDevice pci,VEN_10DE&DEV_008C, any
RemoveDevice pci,VEN_10DE&DEV_00DF, any
RemoveDevice pci,VEN_10DE&DEV_0038, any
RemoveDevice pci,VEN_10DE&DEV_0057, any
RemoveDevice pci,VEN_10DE&DEV_0269, any
RemoveDevice pci,VEN_10DE&DEV_0373, any
RemoveDevice pci,VEN_10DE&DEV_0389, any
RemoveDevice pci,VEN_10DE&DEV_03EF, any
RemoveDevice pci,VEN_10DE&DEV_03E6, any
RemoveDevice pci,VEN_10DE&DEV_0452, any
RemoveDevice pci,VEN_10DE&DEV_0453, any
RemoveDevice pci,VEN_10DE&DEV_054E, any
RemoveDevice pci,VEN_10DE&DEV_054F, any
RemoveDevice pci,VEN_10DE&DEV_0086, any
RemoveDevice pci,VEN_10DE&DEV_00E6, any
RemoveDevice pci,VEN_10DE&DEV_0037, any
RemoveDevice pci,VEN_10DE&DEV_0056, any
RemoveDevice pci,VEN_10DE&DEV_0268, any
RemoveDevice pci,VEN_10DE&DEV_0372, any
RemoveDevice pci,VEN_10DE&DEV_03E5, any
RemoveDevice pci,VEN_10DE&DEV_03EE, any
RemoveDevice pci,VEN_10DE&DEV_0450, any
RemoveDevice pci,VEN_10DE&DEV_0451, any
RemoveDevice pci,VEN_10DE&DEV_054C, any
RemoveDevice pci,VEN_10DE&DEV_054D, any
RemoveDevice pci,VEN_10DE&DEV_07DC, any
RemoveDevice pci,VEN_10DE&DEV_07DE, any
RemoveDevice pci,VEN_10DE&DEV_07DD, any
RemoveDevice pci,VEN_10DE&DEV_07DF, any
RemoveDevice pci,VEN_10DE&DEV_0760, any
RemoveDevice pci,VEN_10DE&DEV_0761, any
RemoveDevice pci,VEN_10DE&DEV_0762, any
RemoveDevice pci,VEN_10DE&DEV_0763, any
RemoveDevice pci,VEN_10DE&DEV_0AB0, any
RemoveDevice pci,VEN_10DE&DEV_0AB1, any
RemoveDevice pci,VEN_10DE&DEV_0AB2, any
RemoveDevice pci,VEN_10DE&DEV_0AB3, any

; Now try to delete files used by Bus driver
DelOemInfs nv*,Version,CatalogFile,nvnetbus.cat,version,Provider,%NVDA%
DelIniIfMatched {windir}\inf\internet\NVidiaNetbus.inf,Version,CatalogFile,nvnetbus.cat,version,Provider,%NVDA%

DelBoot {sysdir}\nvnetbus.sys
DelBoot {sysdir}\nvnrm.sys
DelBoot {sysdir}\nvsnpu.sys

; Also delete them from {sysdir}\drivers folder
DelBoot {sysdir}\drivers\nvnetbus.sys
DelBoot {sysdir}\drivers\nvnrm.sys 
DelBoot {sysdir}\drivers\nvsnpu.sys
DelBoot {sysdir}\drivers\nvtcp.sys
DelBoot {sysdir}\drivers\nvnetvfd.sys


DelBoot {sysdir}\bdco1.dll
DelBoot {sysdir}\bdcoXins.dll
DelBoot {sysdir}\bdco1ins.dll
DelBoot {sysdir}\NVCONRM.DLL

; also delete the coinstaller
DelBoot {sysdir}\nvcoe.dll

Delreg HKLM\SYSTEM\{*ControlSet}\Class\{1a3e09be-1e45-494b-9174-d7385b45bbf5}
Delreg HKLM\SYSTEM\{*ControlSet}\control\class\{1A3E09BE-1E45-494B-9174-D7385B45BBF5}

DelReg HKLM\SYSTEM\{*ControlSet}\Services\nvnetbus
DelReg HKLM\System\{*ControlSet}\Control\SafeBoot\Network\{1a3e09be-1e45-494b-9174-d7385b45bbf5}



[functiondriveruninst]
; Remove Ethernet Function driver if present
UninstallService NVENETFD
RemoveDevice NVNET,VEN_10DE&DEV_008C, any
RemoveDevice NVNET,VEN_10DE&DEV_00DF, any
RemoveDevice NVNET,VEN_10DE&DEV_0038, any
RemoveDevice NVNET,VEN_10DE&DEV_0057, any
RemoveDevice NVNET,VEN_10DE&DEV_0269, any
; Removedevice is asynchronous and bad things happens if we don't wait long enough
sleep 3000

; Now try to delete files used by Ethernet Function driver
DelOemInfs nv*,Version,Class,net,version,Provider,%Nvidia%,Version,CatalogFile,NVENETFD.CAT
DelIniIfMatched {windir}\inf\internet\NVidianvenetfd.inf,Version,Class,net,version,Provider,%Nvidia%,Version,CatalogFile,NVENETFD.CAT

DelBoot {sysdir}\nvenetfd.sys
DelBoot {sysdir}\Drivers\nvenetfd.sys
; Delete co-installers. Can't rely on wildcards since these names are not nv-specific
Del {sysdir}\fdco1.dll
Del {sysdir}\fdco2.dll
Del {sysdir}\fdco3.dll
Del {sysdir}\fdco4.dll
Del {sysdir}\fdco5.dll
Del {sysdir}\fdco6.dll
Del {sysdir}\fdcoXins.dll
Del {sysdir}\fdco1ins.dll


EnumRegCmd HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\{*},call CheckProvider

DelReg HKLM\SYSTEM\{*ControlSet}\Services\nvenetfd
DelReg HKLM\SYSTEM\{*ControlSet}\Services\EventLog\System\nvenetfd

[CheckProvider]
GetReg Description={Current Root Key}\{Current Reg Key}\Description
if {Description}=NVIDIA nForce MCP2S Networking Adapter then DelReg {Current Root Key}\{Current Reg Key}

[UninstallNAM]
; Uninstall network management

getreg UninstallCommand={uninstregkey}\InstallShield_{NAM_GUID}\UninstallString
if {UninstallCommand}%.exe then syscallandwait {UninstallCommand}  /z"/uninstall /noreboot"
set UninstallCommand
; Also check this regkey for Win64 systems
getreg UninstallCommand=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{NAM_GUID}\UninstallString
if {UninstallCommand}%.exe then syscallandwait {UninstallCommand} /z"/uninstall /noreboot"
set UninstallCommand

[UninstallNewNAM]
; Uninstall network management
; get the NAM GUID
GetReg NAM_GUID=HKEY_LOCAL_MACHINE\Software\NVIDIA Corporation\nForce\network management\settings\GUID

;also get the UninstallReboot key
GetReg NAMReboot=HKEY_LOCAL_MACHINE\Software\NVIDIA Corporation\nForce\network management\settings\UninstallReboot

if {NAMReboot}=1 then Call TriggerNeedReboot

set 64Bit=FALSE
getreg UninstallCommand=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{NAM_GUID}\UninstallString
if {UninstallCommand}%.exe then set 64Bit=TRUE
if {64Bit}=TRUE then call 64bitsec
if {64Bit}=FALSE then call 32bitsec


[32bitsec]
getreg UninstallCommand={uninstregkey}\InstallShield_{NAM_GUID}\UninstallString
if {UninstallCommand}%.exe then syscallandwait {UninstallCommand} -removeonly /z"noreboot" -s
waitonregdel {uninstregkey}\InstallShield_{NAM_GUID},,10000,12, echo Unable to uninstall NAM
set UninstallCommand

[64bitsec]
; Also check this regkey for Win64 systems
getreg UninstallCommand=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{NAM_GUID}\UninstallString
if {UninstallCommand}%.exe then syscallandwait {UninstallCommand} -removeonly /z"noreboot" -s
waitonregdel HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{NAM_GUID},,10000,12, echo Unable to uninstall NAM
set UninstallCommand

[UninstallNetDiag]
; Uninstall network diagnostics
RunOnce {sysdir}\nvnetdiag.nvu
[TriggerNeedReboot]
; Hack to trigger a reboot...borrowed from Display NVU.
Copy {current Script},{sysdir}\deleteme_eth.txt
DelBoot {sysdir}\deleteme_eth.txt
DelBoot {sysdir}\nvnrm.nvu