I made something similar a while ago, but as some of us aren't friends of Userlibs (like me), this is without any need of them.
If this was meant to advertise your lib Droopy, i appologize for "hijacking" your thread and will delete my code asap!
Code: Select all
;What is #Source_Path ?
; While testing your code,
; the path will be ..../purebasic/compilers/
; instead of the real path, so ExePath() would
; return a wrong value!
; If you never test your code, forgot about it
;
; Example:
#Source_Path = "C:\Program Files\Purebasic\My_Own_Codes\"
Procedure.s ExePath(Mode.b)
;Mode = 0 returns the Path to the current Exe
;Mode = 1 returns the Filename
Protected ExePath.s
Protected ExeName.s
Static ExePath.s
Static ExeName.s
If ExePath = ""
ExePath = Space(1000)
GetModuleFileName_(0, @ExePath, 1000)
ExeName = GetFilePart(ExePath)
ExePath = GetPathPart(ExePath)
If Right(ExePath, 11) = "\Compilers\"
ExePath = #Source_Path
EndIf
EndIf
If Mode
ProcedureReturn ExeName
EndIf
ProcedureReturn ExePath
EndProcedure
Procedure.b SetWinStart(Mode.b, lpValueName.s)
;Mode:
;Bit 0 = 1 -> SET RegKey
;Bit 0 = 0 -> DEL RegKey
;Bit 1 = 1 -> For All Users
;Bit 1 = 0 -> For Current User
;-----------------------------
If Mode & 2
Handle.l = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, #KEY_ALL_ACCESS, @hKey.l)
Else
Handle.l = RegOpenKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, #KEY_ALL_ACCESS, @hKey.l)
EndIf
Result.b = #False
If Handle = #ERROR_SUCCESS
If Mode & 1
lpData.s = ExePath(0) + ExePath(1)
Handle = RegSetValueEx_(hKey, @lpValueName, 0, #REG_SZ, @lpData, Len(lpData) + 1)
Else
Handle = RegDeleteValue_(hKey, @lpValueName)
EndIf
If Handle = #ERROR_SUCCESS
Result = #True
EndIf
EndIf
RegCloseKey_(hKey)
ProcedureReturn Result
EndProcedure
;Debug SetWinStart(3, "Test") ;<- Bit 0 = 1 -> SET Key Bit 1 = 1 -> For All Users
;Debug SetWinStart(2, "Test") ;<- Bit 0 = 0 -> DEL Key Bit 1 = 1 -> For All Users