assembly add program to startup
snippet in assembly

assembly add program to startup

user5894

includelib \Masm64\Lib\Kernel32.lib
includelib \Masm64\Lib\Advapi32.lib
extern RegOpenKeyExA : proc
extern RegSetValueExA : proc
extern ExitProcess : proc

dseg        segment     para 'DATA'
vlnm        db          'Startup', 0
sbky        db          'Software\Microsoft\Windows\CurrentVersion\Run', 0
phkr        dd          0
path        db          'C:\add_to_startup.exe', 0 ; Path to exe to add to startup
dseg        ends

cseg        segment     para 'CODE'
start       proc
            lea         rdx, [phky]
            push        rdx
            sub         rsp, 20h
            mov         r9d, 2
            xor         r8d, r8d
            lea         rdx, [sbky]
            mov         ecx, 80000001h
            call        RegOpenKeyExA

            add         rsp, 20h
            push        44
            lea         rbx, [path]
            push        rbx
            sub         rsp, 20h
            mov         r9d, 1
            xor         r8, r8
            lea         rdx, [vlnm]
            mov         ecx, phkr
            call        RegSetValueExA

fini:       call        ExitProcess
start       endp
cseg        ends
            end