All I want to do is to make an exe that starts with windows.However,I'd like to do that in code,is it possible? If yes,how?
Make an exe start with windows?
You can make a program run at start up by adding a string value to the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\CurrentVersion\Run or HKEY_CURRENT_USER\Software\Microsoft\CurrentVersion\Run
You can also add a shortcut to the program's exe in the "Start Menu\Startup" special folder - although that location is windows-version-specific, you should use the shell library to look up what the proper path of that folder is, and also create the link. The shell library can do this all for you quite easily.
If you do create a self-starting program, be sure to test it with a variety of virus-checkers to ensure that its behaviour is not flagged as malicious in any way. Lots of malware does this. If you create a self-starting program without obviously being an "installer" or prompting the user, it may think you are malware.
Just for completeness, I'll add that you can also do this with the Task Scheduler API using a boot trigger.