Startup Program

Archives Forums/Win32 Discussion/Startup Program

William Drescher(Posted 2008) [#1]
How do I set up a program to start when windows starts?


MrTAToad(Posted 2008) [#2]
The easiest would be to put the program (or a link to it) into the startup folder.


Dabhand(Posted 2008) [#3]
#include <windows.h>

BOOL SetStartupRegValue(const char *value, const char *valueData)
{
	HKEY hKey;   

	if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, KEY_ALL_ACCESS, &hKey ) != ERROR_SUCCESS)
	{
		return(FALSE);
	}
	
	if (RegSetValueEx(hKey,value,0,REG_SZ,(LPBYTE) valueData,(strlen(valueData)+1))//"C:\\test.exe",13) != ERROR_SUCCESS)
	{
		RegCloseKey( hKey );
		return(FALSE);
	}
 
	RegCloseKey( hKey );
	return(TRUE);
}


A bit of old code there... shouldnt be too hard to max it up! :)


plash(Posted 2008) [#4]
As dabhand's code shows, you can also add the url to the "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" key in the registry, once I'm finished with this current project I'll post a converted version.


plash(Posted 2008) [#5]
Uses this: http://www.blitzbasic.com/codearcs/codearcs.php?code=1991

Function SetStartupRegValue:Int(Value:String, ValueData:String) 
  Local temp:tregkey = OpenRegKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run") 
	
	If temp
		
		If temp.SetString(Value, valuedata) 
		   Return True
			
		EndIf
		
	EndIf
	
   Return False
   
End Function

Print SetStartupRegValue("testapp", "c:\test.exe") 
Input() 
End