龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VB开发 >

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

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
两点关键: 1检测是Windows关闭引起的QueryUnload事件。 2改写SoftwareMicrosoftWindowsCurrentVersionRunOnce 声明: DeclareFunctionRegCloseKeyLib"advapi32.dll"Alias"RegCloseKey"(ByValhKeyAsLong)AsLong DeclareFunctionRegCreate
两点关键:
  1检测是Windows关闭引起的QueryUnload事件。
  2改写SoftwareMicrosoftWindowsCurrentVersionRunOnce
  
  声明:
  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,"SoftwareMicrosoftWindowsCurrentVersionRunOnce",hKey)
  CallRegSetValueEx(hKey,"MyApp",0&,REG_SZ,ByValstrRunCmd,Len(strRunCmd) 1)
  CallRegCloseKey(hKey)
  Endif
  EndSub->

精彩图集

赞助商链接