[英]How to disable Windows to create an automatic restore point when installing my kernel driver?
我開發了NDIS 6.x LWF內核驅動程序,並使用NSIS 2.46將其包裝到安裝程序中。 我發現安裝Windows之后,Windows將自動創建一個名為Device Driver Package Install: Nmap Project Network Service
的系統還原點。
但是,實際上,事實證明Windows創建的此還原點不是很好。 我嘗試回滾到該還原點,但我的軟件仍然存在,包括驅動程序.sys
文件和對系統的其他修改(例如,創建諸如Windows Loopback Adapter
)。
這是可以理解的,因為我的安裝程序確實在安裝驅動程序之前做了一些修改,而Windows僅在安裝驅動程序時才拍攝快照。 因此,不包括我在安裝驅動程序之前所做的更改。
因此,我決定在安裝程序的所有實際安裝步驟之前由我自己創建一個還原點(使用NSIS提供的SysRestore
)。
而且我想禁用Windows為驅動程序自動創建還原點 。 最好的辦法是什么? 謝謝!
SysRestore插件使用BEGIN_SYSTEM_CHANGE
調用SRSetRestorePoint
,但是根據MSDN,您可以使用BEGIN_NESTED_SYSTEM_CHANGE
調用它,僅創建一個還原點。 我不知道這是否僅適用於單個進程,或者是否也適用於您可能用於安裝驅動程序的任何子進程,但也許值得一試。 該代碼可能看起來像這樣:
!define MAX_DESC 64
!define MAX_DESC_W 256
!define STATEMGRSTATUS i,l
!define RESTOREPOINTINFOA i,i,l,&m${MAX_DESC}
!define RESTOREPOINTINFOW i,i,l,&w${MAX_DESC_W}
!if "${NSIS_CHAR_SIZE}" <= 1
!define RESTOREPOINTINFO "${RESTOREPOINTINFOA}"
!else
!define RESTOREPOINTINFO "${RESTOREPOINTINFOW}"
!endif
!define BEGIN_NESTED_SYSTEM_CHANGE 102
!define END_NESTED_SYSTEM_CHANGE 103
!define DEVICE_DRIVER_INSTALL 10
Section
System::Call 'KERNEL32::LoadLibrary(t "$SysDir\SrClient.dll")'
Var /Global SRSTATUS
System::Call '*(${STATEMGRSTATUS})i.s'
Pop $SRSTATUS
System::Call '*(${RESTOREPOINTINFO})(${BEGIN_NESTED_SYSTEM_CHANGE},${DEVICE_DRIVER_INSTALL},0,&t${MAX_DESC} "Installed driver XYZ")i.r0'
System::Call 'SrClient::SRSetRestorePoint(ir0,i$SRSTATUS)i.r1'
IntCmpU $1 0 "" +2 +2
System::Call '*$SRSTATUS(${STATEMGRSTATUS})(0)' ; Make sure nStatus is ERROR_SUCCESS
System::Free $0
DetailPrint "SRSetRestorePoint(BEGIN_NESTED_SYSTEM_CHANGE) returned $1"
; TODO: Install driver here
System::Call '*$SRSTATUS(${STATEMGRSTATUS})(.r0,.r1)' ; Extract nStatus and llSequenceNumber
IntCmpU $0 0 "" norpt norpt ; Did the first call to SRSetRestorePoint succeed?
System::Call '*(${RESTOREPOINTINFO})(${END_NESTED_SYSTEM_CHANGE},${DEVICE_DRIVER_INSTALL},r1)i.r0'
System::Call 'SrClient::SRSetRestorePoint(ir0,i$SRSTATUS)i.r1'
System::Free $0
DetailPrint "SRSetRestorePoint(END_NESTED_SYSTEM_CHANGE) returned $1"
norpt:
System::Free $SRSTATUS
SectionEnd
我不知道這是否是最好的方法,但是您始終可以停止系統還原服務。 在我看來,這是一個微妙的問題,可能比用戶對驅動程序安裝程序的預期要大。
無論如何,您應該事先將此信息告知您的用戶,並在完成后重新啟動服務。
Section
# Stop the service
nsExec::Exec 'net.exe STOP "srservice"'
# Install kernel driver
SectionEnd
# Restore original setting
Function startSysRestore
nsExec::Exec 'net.exe START "srservice"'
FunctionEnd
# Things go right
Function .onInstSuccess
Call startSysRestore
FunctionEnd
# Things might go wrong
Function .onUserAbort
Call startSysRestore
FunctionEnd
Function .onInstFailed
Call startSysRestore
FunctionEnd
編輯:此答案的先前版本描述了如何禁用ServiceRestore服務
WSR有幾種替代方法可以執行相同的功能(例如Comodo Time Machine,Shadow Defender,RollbackRx等),您最好使用它們來拍攝快照,因為我敢肯定它們不會受到相同的限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.