I needed this for a project, and I didn't find any registry functions in PB and I didn't want to use a lib either...
So I did some searching, and found a great page with some registery functions for VB (which is easy to translate to PB):
http://www.skillreactor.org/cgi-bin/index.pl?registry
I just translated what I needed, and made a little example on how you could add and remove your program from startup:
Code: Select all
; Translated from:
; http://www.skillreactor.org/cgi-bin/index.pl?registry
Procedure SaveValue(hKey.l,strPath.s,strValue.s,strData.s)
Protected hCurKey.l,lRegResult.l
lRegResult = RegCreateKey_(hKey,@strPath,@hCurKey)
lRegResult = RegSetValueEx_(hCurKey,@strValue,0,#REG_SZ,@strData,Len(strData))
If lRegResult <> #ERROR_SUCCESS
;there is a problem
EndIf
lRegResult = RegCloseKey_(hCurKey)
EndProcedure
Procedure DeleteValue(hKey.l,strPath.s,strValue.s)
Protected hCurKey.l,lRegResult.l
lRegResult = RegOpenKey_(hKey,@strPath,@hCurKey)
lRegResult = RegDeleteValue_(hCurKey,@strValue)
lRegResult = RegCloseKey_(hCurKey)
EndProcedure
SaveValue(#HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Run","MyProgram",Chr(34)+ProgramFilename()+Chr(34))
;DeleteValue(#HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Run","MyProgram")
Or a simpler way, didn't test it yet but it should work:
Code: Select all
Procedure StartWithWindows(State.b)
Protected Key.l = #HKEY_CURRENT_USER ;or #HKEY_LOCAL_MACHINE for every user on the machine
Protected Path.s = "Software\Microsoft\Windows\CurrentVersion\Run" ;or RunOnce if you just want to run it once
Protected Value.s = "MyProgram" ;Change into the name of your program
Protected String.s = Chr(34)+ProgramFilename()+Chr(34) ;Path of your program
Protected CurKey.l
If State
RegCreateKey_(Key,@Path,@CurKey)
RegSetValueEx_(CurKey,@Value,0,#REG_SZ,@String,Len(String))
Else
RegOpenKey_(Key,@Path,@CurKey)
RegDeleteValue_(CurKey,@Value)
EndIf
RegCloseKey_(CurKey)
EndProcedure