Real Software Forums
http://forums.realsoftware.com/

Run Your Application On Startup
http://forums.realsoftware.com/viewtopic.php?f=21&t=39465
Page 1 of 1

Author:  sinner [ Sat Jun 18, 2011 4:22 pm ]
Post subject:  Run Your Application On Startup

Hi all for all you that wanted to know how to do this. Here is a way to make your application run when your computer starts up!

1. Make a method called DisplayName in your app class to get your programs name
2. Add the the code below to a pushbuttons action event

App Method

Function DisplayName() As String
#If DebugBuild Then
Return NthField( NthField( App.ExecutableFile.Name , ".exe" , 1 ) , "Debug" , 2 )
#Else
Return NthField( App.ExecutableFile.Name , ".exe" , 1 )
#EndIf
End Function


Pushbutton code

Dim Reg As RegistryItem

Reg = New RegistryItem("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run")

Reg.Value( App.DisplayName ) = SpecialFolder.CurrentWorkingDirectory.AbsolutePath + App.DisplayName +".exe"

Author:  RicSum [ Fri Dec 23, 2011 6:11 pm ]
Post subject:  Re: Run Your Application On Startup

If I wanted a button, which removes the app fom the startup menu, how is that done?

Author:  sinner [ Sat Dec 24, 2011 9:11 am ]
Post subject:  Re: Run Your Application On Startup

RicSum wrote:
If I wanted a button, which removes the app fom the startup menu, how is that done?


Put this code in a checkboxs action event. For example when users checkbox is checked it will add the startup item. When the user unchecked the box it will remove it

Sub AddToStartUp( Enabled As Boolean )
Dim Reg As RegistryItem
Reg = New RegistryItem("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run")

Select Case Enabled

Case True 'Add Item
Reg.Value( App.DisplayName ) = SpecialFolder.CurrentWorkingDirectory.AbsolutePath + App.DisplayName +".exe"

Case False 'Remove Item
Reg.Delete(App.DisplayName)
End Select
End Sub


Call

Call AddToStartUp(True)


Note:
the DisplayName method may break in new releases of RealStudio

Author:  Anonymouz [ Sat Jan 07, 2012 7:59 pm ]
Post subject:  Re: Run Your Application On Startup

What if we're using a Mac?

Author:  npalardy [ Sat Jan 07, 2012 10:30 pm ]
Post subject:  Re: Run Your Application On Startup

Anonymouz wrote:
What if we're using a Mac?

1) You have the user select your app and add it to their login items that run when they log in
2) You ask their permission and add it automatically to their login items (and take careful care to do it right for each version of OS X)

If you want it to be done at system start up you'd need to add a plist to the system wide LaunchAgents so launchd starts it up

Author:  sinner [ Sun Oct 07, 2012 8:48 am ]
Post subject:  Re: Run Your Application On Startup

I wanted to add something to this topic

I noticed this when using the CurrentWorkingDirectory path changes when i reboot my system and let my system end my application. When windows starts my program from the registry run even the CurrentWorkingDirectory changes to UserHome directory for some reason idk why this happens just make sure to compare your path with the CurrentWorkingDirectory if you use this special folder.

Here is an example

#If DebugBuild Then
f=GetFolderItem(SpecialFolder.Applications.TrueChild(App.DisplayName+"\Data\MyDataFile").AbsolutePath)
#Else
If SpecialFolder.CurrentWorkingDirectory.AbsolutePath = SpecialFolder.UserHome.AbsolutePath Then
f=GetFolderItem(SpecialFolder.Applications.TrueChild(App.DisplayName+"\Data\MyDataFile").AbsolutePath)
Else
f=GetFolderItem(SpecialFolder.CurrentWorkingDirectory.TrueChild("Data\MyDataFile").AbsolutePath)
End
#EndIf


Note:
I have my app change the start up path in my APP close event. If you have your startup path change with a check box/push button and not a open/close event then more then most likely you wont have to use the following code above.

Hope this helps

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/