; NVIDIA Display Driver uninstaller
killapp nvCplUI.exe
call Uninstall

[UninstallSilent]
Set ForceNoReboot=yes
call UninstallSilentReboot

[UninstallSilentReboot]
Set Silent=yes
call Uninstall
Delreg {UninstRegkey}\NVIDIA Display Driver
del {current Script}
del {Current Parser Path}

[Uninstall]
; echo Uninstall
SysCallAndWait MsiExec /x{3D3E663D-4E7E-4577-A560-7ECDDD45548A} /quiet /norestart
SysCallAndWait MsiExec /x{275E55FA-1CB3-4B53-924B-3B43AA701FB6} /quiet /norestart
DelBoot {sysdir}\pvsonydll.dll
DelBoot {syswow64dir}\pvsonydll.dll
SysCallAndWait MsiExec /x{F4469132-EA9F-444A-BFFB-323C7413E951} /quiet /norestart
SysCallAndWait MsiExec /x{4C0A8D65-4286-4B58-87FE-18AD24289285} /quiet /norestart
SysCallAndWait MsiExec /x{71807498-D8E2-41C6-84CD-8ED7A076B6EC} /quiet /norestart
SysCallAndWait {syswow64dir}\nViewSetup -s -uninstall
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeys
; echo InfPath : {InfPath}
CheckPath INFCHECK={windir}\Inf\{InfPath}
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Class\{*}, call EnumClassForDelete
if {INFCHECK}=TRUE then call RunDpinst

;Deleting the class key associated with this driver
enumregcmd {DisplayClassKeys}\{*}, call DeleteClasskeys

[DeleteClasskeys]
set CurrentClassKey = {Current Root Key}\{Current Reg Key}
if !{CurrentClassKey}%Properties then DelReg {CurrentClassKey}

; echo Old Version = {Version}
set OldVersion={Version}
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeys
; echo New Version = {Version}
if {Version}={OldVersion} then call ManualRemove

call CleanUp

; Hack to trigger a reboot
Copy {current Script},{sysdir}\deleteme.txt
DelBoot {sysdir}\deleteme.txt

[ManualRemove]
RemoveDevice pci,VEN_10DE,Display

[RunDpinst]
SysCallAndWait {sysdir}\dpinst.exe /u {windir}\Inf\{InfPath} /s

[CleanUp]
; echo Cleaning stuff up

; echo deleting the "Portal" game related items
del {windir}\nvidia icons\Portal_32x32.ico
del {windir}\nvidia icons\Portal_48x48.ico
GetFolderPath Desktop=25
del {Desktop}\Play Portal Now.lnk
; make sure the TMM persistence files are deleted on uninstall in all cases.
DelBoot {pgmdir}\nvModes.dat
DelBoot {pgmdir}\nvModes.001
DelBoot {pgmdir}\nvUnsupRes.dat

set NVIDIADriverFound=FALSE
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeys
if {InBoxDriverFound}=TRUE then call LeaveInBox
if {NVIDIADriverFound}=FALSE then call DeleteAll

set NVIDIADriverFound=FALSE
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeysForDelete

[EnumClassForDelete]
set ClassBaseKey={Current Root Key}\{Current Reg Key}
enumregcmd {ClassBaseKey}\{*},call MatchClasskey


[MatchClasskey]
set ClassSubKey={Current Root Key}\{Current Reg Key}
GetReg InfName={ClassSubKey}\InfPath
if {InfPath}={InfName} then set DisplayClassKeys={ClassBaseKey}


[EnumVideoKeysForDelete]
set Found0000=FALSE
set Service
set MyBaseKey={Current Root Key}\{Current Reg Key}
enumregcmd {MyBaseKey}\{*},call CheckNVIDIAVideoKeys
if {Service}%nv then if {Found0000}=FALSE then DelReg {Current Root Key}\{Current Reg Key}

[EnumVideoKeys]
set MyBaseKey={Current Root Key}\{Current Reg Key}
enumregcmd {MyBaseKey}\{*},call CheckNVIDIAVideoKeys

[CheckNVIDIAVideoKeys]
set DriverDesc=FOOBAR
; echo Current Root Key : {Current Root Key}
; echo Current Reg Key : {Current Reg Key}
GetReg DriverDesc={Current Root Key}\{Current Reg Key}\DriverDesc
; echo DriverDesc: {DriverDesc}
if {DriverDesc}%NVIDIA then set NVIDIADriverFound=TRUE
if {DriverDesc}%NVIDIA then if {DriverDesc}%Microsoft then set InBoxDriverFound=TRUE
if {DriverDesc}%NVIDIA then GetReg InfPath={Current Root Key}\{Current Reg Key}\InfPath
if {DriverDesc}%NVIDIA then GetReg Version={Current Root Key}\{Current Reg Key}\DriverVersion
if {DriverDesc}%NVIDIA then GetReg CoInstaller={Current Root Key}\{Current Reg Key}\Uninstall\CoInstaller
; echo Version: {Version}
GetReg Service={Current Root Key}\{Current Reg Key}\Service
if {Current Reg Key}%0000 then set Found0000=TRUE


[DeleteAll]
; echo No NVIDIA driver.  Deleting all NVIDIA files.
delboot {sysdir}\nvapi.dll
delboot {sysdir}\nvapi64.dll
delboot {sysdir}\nvd3dum.dll
delboot {sysdir}\nvd3dumx.dll
Delboot {sysdir}\drivers\nvlddmkm.sys
Delboot {sysdir}\drivers\nvbridge.kmd

delboot {syswow64dir}\nvapi.dll
delboot {syswow64dir}\nvd3dum.dll
call LeaveInBox

DelReg HKCR\VirtualStore\MACHINE\SOFTWARE\NVIDIA Corporation\Global
DelRegE HKCR\VirtualStore\MACHINE\SOFTWARE\NVIDIA Corporation
DelReg HKLM\Software\NVIDIA Corporation\Global\NvCplApi
DelReg HKCU\Software\NVIDIA Corporation\Global\NvCplApi
DelReg HKLM\Software\NVIDIA Corporation\Global\NVTweak
DelReg HKCU\Software\NVIDIA Corporation\Global\NVTweak
DelReg HKLM\Software\NVIDIA Corporation\Global\MediaCenterTray
DelReg HKLM\Software\NVIDIA Corporation\Global\Hybrid\Action
DelReg HKLM\Software\NVIDIA Corporation\Global\Hybrid
DelRegE HKCU\Software\NVIDIA Corporation\Global
DelRegE HKLM\Software\NVIDIA Corporation\Global
DelReg HKLM\Software\NVIDIA Corporation\Installer
Delreg {UninstRegkey}\NVIDIA Display Driver
DelReg HKLM\Software\NVIDIA Corporation\NVAPI
DelReg HKLM\SYSTEM\{*ControlSet}\Services\nv\NVAPI
DelReg HKLM\SYSTEM\{*ControlSet}\Services\nvlddmkm\NVAPI
DelReg HKLM\SYSTEM\{*ControlSet}\Services\nvlddmkm


[LeaveInBox]
; echo NVIDIA Inbox driver found.  Leaving InBox Files

call UninstallSedona

UninstallService NVSvc

delboot {sysdir}\nvwgf2um.dll
delboot {sysdir}\nvwgf2umx.dll
Delboot {sysdir}\nvmctray.dll
Delboot {sysdir}\nvoglv32.dll
delboot {sysdir}\nvoglv64.dll
Delboot {sysdir}\nvsvc.dll
Delboot {sysdir}\nvsvcr.dll
Delboot {sysdir}\nvsvc64.dll
Delboot {sysdir}\nvmccs.dll
Delboot {sysdir}\nvmccsrs.dll
Delboot {sysdir}\nvvsvc.exe
Delboot {sysdir}\nvcolor.exe
Delboot {sysdir}\nvapps.xml
Delboot {sysdir}\nvwsapps.xml
Delboot {sysdir}\nvcod.dll
Delboot {sysdir}\nvcodins.dll
Delboot {sysdir}\nvcodh.dll
Delboot {sysdir}\nvcodhins.dll
Delboot {sysdir}\nvudisp.exe
DelBoot {sysdir}\{CoInstaller}
DelBoot	{sysdir}\nvcuda.dll
Delboot {sysdir}\nvcuvenc.dll
Delboot {sysdir}\nvcuvid.dll
DelBoot {wrkdir}\nvapps.xml
DelBoot {wrkdir}\nvwsapps.xml
DelBoot {wrkdir}\NvStarted
DelBoot {wrkdir}\NvSetnative



delboot {syswow64dir}\nvwgf2um.dll
Delboot {syswow64dir}\nvcuda.dll
Delboot {syswow64dir}\nvcuvenc.dll
Delboot {syswow64dir}\nvoglv32.dll
Delboot {syswow64dir}\nvapps.xml
Delboot {syswow64dir}\nvwsapps.xml
Delboot {syswow64dir}\nvcuvid.dll

delreg HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NvMediaCenter
delreg HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NvCplDaemon
delreg HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NvSvc
delreg HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\RestoreProfile
delreg HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\RestoreGlobals



[UninstallSedona]
; echo Uninstalling Sedona
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvshext.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvcpl.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvsvs.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvsvsr.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvmccs.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvmccss.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvdisps.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvgames.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvmobls.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvvitvs.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvwss.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvsvc.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvsvc64.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvvsvc.exe

Delboot {sysdir}\nvshext.dll
Delboot {sysdir}\nvcpl.dll
Delboot {sysdir}\nvdisps.dll
Delboot {sysdir}\nvgames.dll
Delboot {sysdir}\nvmccss.dll
Delboot {sysdir}\nvmccs.dll
Delboot {sysdir}\nvmobls.dll
Delboot {sysdir}\nvvitvs.dll
Delboot {sysdir}\nvwss.dll
Delboot {sysdir}\nvhotkey.dll
Delboot {sysdir}\oemdspif.dll
Delboot {sysdir}\nvsvs.dll
Delboot {sysdir}\nvsvsr.dll
Delboot {sysdir}\NvPVEnc.ax

Set current file
DirAndApply {windir}\help\nvcpl\nvcpl*.cab,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nvdsp*.chm,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nv3d*.chm,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nvmob*.chm,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nvwks*.chm,Delboot {current file}
Set current file
DirAndApply {wrkdir}\*.NVP,Delboot {current file}

Set ServersPresent=0
EnumRegNamesCmd HKLM\Software\NVIDIA Corporation\NVControlPanel\RegisteredServers, set ServersPresent=1
EnumRegNamesCmd HKLM\Software\NVIDIA Corporation\Global\NVControlPanel\RegisteredServers, set ServersPresent=1
if {ServersPresent}=0 then call UninstallSedonaClient

[UninstallSedonaClient]
; echo Uninsatlling Sedona Client
Delboot {sysdir}\nvcpl.exe
Delboot {sysdir}\nvcplui.exe
Delboot {sysdir}\nvcpl.cpl
Delboot {sysdir}\nvcpluir.dll
Delboot {sysdir}\nvexpbar.dll
Delboot {sysdir}\nvdispsr.dll
Delboot {sysdir}\nvgamesr.dll
Delboot {sysdir}\nvmccssr.dll
Delboot {sysdir}\nvmoblsr.dll
Delboot {sysdir}\nvvitvsr.dll
Delboot {sysdir}\nvwssr.dll

Set current file
DirAndApply {windir}\help\nvcpl\nvcpl*.chm,Delboot {current file}
Del {windir}\help\nvcpl
DelReg HKLM\Software\NVIDIA Corporation\NVControlPanel
DelRegE HKLM\Software\NVIDIA Corporation
DelReg HKCU\Software\NVIDIA Corporation\NVIDIA Control Panel
DelReg HKCU\Software\NVIDIA Corporation\NVControlPanel
DelRegE HKCU\Software\NVIDIA Corporation
DelReg HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\NVHotkey


set Shortcutpath={CommonPrograms}\NVIDIA Corporation\NVIDIA Control Panel
set ShortcutName=Control Panel.lnk
call DelShortCut
delboot {CommonPrograms}\NVIDIA Corporation

[DelShortCut]
del {Shortcutpath}\{ShortcutName}
delboot {Shortcutpath}
