首页 > 学院 > 开发设计 > 正文

自动开始上次关机时关闭的应用

2019-11-18 17:51:47
字体:
来源:转载
供稿:网友
两点关键:
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->


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表