Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Mar 23, 2017 5:07 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Run Your Application On Startup
PostPosted: Sat Jun 18, 2011 4:22 pm 
Offline
User avatar

Joined: Sat May 27, 2006 3:27 pm
Posts: 480
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"


Top
 Profile  
 
 Post subject: Re: Run Your Application On Startup
PostPosted: Fri Dec 23, 2011 6:11 pm 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
If I wanted a button, which removes the app fom the startup menu, how is that done?

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
 
 Post subject: Re: Run Your Application On Startup
PostPosted: Sat Dec 24, 2011 9:11 am 
Offline
User avatar

Joined: Sat May 27, 2006 3:27 pm
Posts: 480
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


Last edited by sinner on Sun Oct 07, 2012 11:54 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Run Your Application On Startup
PostPosted: Sat Jan 07, 2012 7:59 pm 
Offline

Joined: Sat Jan 07, 2012 7:57 pm
Posts: 1
What if we're using a Mac?


Top
 Profile  
 
 Post subject: Re: Run Your Application On Startup
PostPosted: Sat Jan 07, 2012 10:30 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
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

_________________
Norman Palardy (Real Software)


Top
 Profile  
 
 Post subject: Re: Run Your Application On Startup
PostPosted: Sun Oct 07, 2012 8:48 am 
Offline
User avatar

Joined: Sat May 27, 2006 3:27 pm
Posts: 480
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group