Hello everybody;
I am looking purebasic code to make autorun application it self... After restart on Windows... Any body knows any sample?
Thanks a LOT!
Make Autorun selfprogram on Windows...
Re: Make Autorun selfprogram on Windows...
Search Windows Service. Or task scheduler automation.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Make Autorun selfprogram on Windows...
I made an analog of my function (insufficiently tested)
Code: Select all
EnableExplicit
; https://www.purebasic.fr/english/viewtopic.php?p=61476#p61476
XIncludeFile "CreateLink.pbi"
; Protected result = 0, hres
; Protected ShellLink.IShellLinkA
; Protected PersistFile.IPersistFile
; https://www.purebasic.fr/english/viewtopic.php?f=12&t=56204
XIncludeFile "Registry.pbi"
UseModule registry
Declare StartUp(flag = 0, sName$ = "", sPathRun$ = "", sArgs$ = "", sDesc$ = "", sIcon$ = "", iIconNum = 0, state = #SW_SHOWNORMAL)
StartUp(0, "test", "C:\Windows\system32\calc.exe", "", "", "C:\Windows\system32\calc.exe", 0) ; Shortcut
StartUp(3, "test", "C:\Windows\system32\calc.exe") ; Registry
Procedure StartUp(flag = 0, sName$ = "", sPathRun$ = "", sArgs$ = "", sDesc$ = "", sIcon$ = "", iIconNum = 0, state = #SW_SHOWNORMAL)
Protected iPos$, sKeyName$, iRes$, sPathLnk$, HK
If Not Asc(sPathRun$)
sPathRun$ = ProgramFilename()
EndIf
If Not Asc(sName$)
sName$ =GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension)
EndIf
If flag & 1
If flag & 2
HK = #HKEY_LOCAL_MACHINE
Else
HK = #HKEY_CURRENT_USER
EndIf
; If #OSArch = "X64"
; sKeyName$ + "64"
; EndIf
sKeyName$ + "\Software\Microsoft\Windows\CurrentVersion\Run"
If flag & 4
sKeyName$ + "Once"
ElseIf flag & 8
sKeyName$ + "OnceEx"
EndIf
If flag & 32
ProcedureReturn DeleteKey(HK, sKeyName$ + "\" + sName$)
EndIf
If ReadValue(HK, sKeyName$, sName$) And flag & 16 ; если существует и флаг 16, т.е. не перезаписывать, то выпрыг
ProcedureReturn 0
EndIf
If sArgs$
sArgs$ = " " + sArgs$
EndIf
; iRes$ = RegWrite(sKeyName$, sName$, "REG_SZ", """ + sPathRun$ + """ + sArgs$)
If WriteValue(HK, sKeyName$, sName$, Chr(34) + sPathRun$ + Chr(34) + sArgs$, #REG_SZ)
ProcedureReturn 1
EndIf
Else
If flag & 2
sPathLnk$ = GetUserDirectory(#PB_Directory_AllUserData) + "Microsoft\Windows\Start Menu\Programs\StartUp\" + sName$ + ".lnk"
Else
sPathLnk$ = GetUserDirectory(#PB_Directory_ProgramData) + "Microsoft\Windows\Start Menu\Programs\Startup\" + sName$ + ".lnk"
EndIf
If flag & 32
ProcedureReturn DeleteFile(sPathLnk$)
EndIf
If flag & 16 And FileSize(sPathLnk$) > 0
ProcedureReturn 1
EndIf
ProcedureReturn CreateLink(sPathRun$, sPathLnk$, sArgs$, sDesc$, "", state, 0, sIcon$, iIconNum)
EndIf
EndProcedure
Re: Make Autorun selfprogram on Windows...
I found very easy way... It works on command prompt, but in the purebasic code It doesnt work
Anybody can find the problem on this code? Doesint work
a$="%allusersprofile%\Microsoft\Windows\"+Chr(34)+"Start Menu"+Chr(34)+"\Programs\StartUp\test.exe C:\Users\Purebasic\AppData\Local\Temp\PureBasic_Compilation0.exe"
RunProgram("mklink",a$,"")
This code doesnt work But if i use this code on below; on command prompt... This works fine... What is the wrong?
mklink %allusersprofile%\Microsoft\Windows\"Start Menu"\Programs\StartUp\test.exe C:\Users\Purebasic\AppData\Local\Temp\PureBasic_Compilation0.exe
Anybody can find the problem on this code? Doesint work
a$="%allusersprofile%\Microsoft\Windows\"+Chr(34)+"Start Menu"+Chr(34)+"\Programs\StartUp\test.exe C:\Users\Purebasic\AppData\Local\Temp\PureBasic_Compilation0.exe"
RunProgram("mklink",a$,"")
This code doesnt work But if i use this code on below; on command prompt... This works fine... What is the wrong?
mklink %allusersprofile%\Microsoft\Windows\"Start Menu"\Programs\StartUp\test.exe C:\Users\Purebasic\AppData\Local\Temp\PureBasic_Compilation0.exe
Re: Make Autorun selfprogram on Windows...
I think you need to run cmd and your mklink as parameter
Re: Make Autorun selfprogram on Windows...
I did try still doesnt work
if i crate .bat file... And if i put the same code inside... Then double click the .bat file... it works fine on .bat file... But doesnt work on purebasic code
I couldnt find the problem
if i crate .bat file... And if i put the same code inside... Then double click the .bat file... it works fine on .bat file... But doesnt work on purebasic code
I couldnt find the problem
Re: Make Autorun selfprogram on Windows...
Thanks a LOT!
Solved...
Thank you again...
Solved...
Thank you again...
Re: Make Autorun selfprogram on Windows...
Maybe this could be helpful
viewtopic.php?f=7&t=45791
viewtopic.php?f=7&t=45791
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home