自动开始上次关机时关闭的应用
2006-02-27 11:42:15 来源:WEB开发网核心提示:两点关键:1检测是Windows关闭引起的QueryUnload事件。2改写Software\Microsoft\Windows\CurrentVersion\RunOnce声明:DeclareFunctionRegCloseKeyLib"advapi32.dll"Alias"RegClo
两点关键:
1检测是Windows关闭引起的QueryUnload事件。
2改写Software\Microsoft\Windows\CurrentVersion\RunOnce
声明:
DeclareFunctionRegCloseKeyLib"advapi32.dll"Alias"RegCloseKey"(ByValhKeyAsLong)AsLong
DeclareFunctionRegCreateKeyLib"advapi32.dll"Alias"RegCreateKeyA"(ByValhKeyAsLong,ByVallpSubKeyAsString,phkResultAsLong)AsLong
DeclareFunctionRegSetValueExLib"advapi32.dll"Alias"RegSetValueExA"(ByValhKeyAsLong,ByVallpValueNameAsString,ByValReservedAsLong,ByValdwTypeAsLong,lpDataAsAny,ByValcbDataAsLong)AsLong'NotethatifyoudeclarethelpDataparameterasString,youmustpassitByValue.
在主Form中增加:
PublicConstREG_SZ=1
PublicConstHKEY_CURRENT_USER=&H80000001
PRivateSubForm_QueryUnload(CancelasInteger,UnloadModeasInteger)
DimhKeyAsLong
DimstrRunCmdAsString
IfUnloadMode=vbAppWindowsThen
strRunCmd=App.Path&"\"&App.EXEName&".EXE"
CallRegCreateKey(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\RunOnce",hKey)
CallRegSetValueEx(hKey,"MyApp",0&,REG_SZ,ByValstrRunCmd,Len(strRunCmd) 1)
CallRegCloseKey(hKey)
Endif
EndSub->
1检测是Windows关闭引起的QueryUnload事件。
2改写Software\Microsoft\Windows\CurrentVersion\RunOnce
声明:
DeclareFunctionRegCloseKeyLib"advapi32.dll"Alias"RegCloseKey"(ByValhKeyAsLong)AsLong
DeclareFunctionRegCreateKeyLib"advapi32.dll"Alias"RegCreateKeyA"(ByValhKeyAsLong,ByVallpSubKeyAsString,phkResultAsLong)AsLong
DeclareFunctionRegSetValueExLib"advapi32.dll"Alias"RegSetValueExA"(ByValhKeyAsLong,ByVallpValueNameAsString,ByValReservedAsLong,ByValdwTypeAsLong,lpDataAsAny,ByValcbDataAsLong)AsLong'NotethatifyoudeclarethelpDataparameterasString,youmustpassitByValue.
在主Form中增加:
PublicConstREG_SZ=1
PublicConstHKEY_CURRENT_USER=&H80000001
PRivateSubForm_QueryUnload(CancelasInteger,UnloadModeasInteger)
DimhKeyAsLong
DimstrRunCmdAsString
IfUnloadMode=vbAppWindowsThen
strRunCmd=App.Path&"\"&App.EXEName&".EXE"
CallRegCreateKey(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\RunOnce",hKey)
CallRegSetValueEx(hKey,"MyApp",0&,REG_SZ,ByValstrRunCmd,Len(strRunCmd) 1)
CallRegCloseKey(hKey)
Endif
EndSub->
更多精彩
赞助商链接