How to start app at Windows startup?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Srdjan
Posts: 26
Joined: Mon Aug 04, 2008 7:17 am

How to start app at Windows startup?

Post by Srdjan » Thu Nov 19, 2009 9:46 am

Hi

Is it possible to create app shortcut in Startup folder under Windows Start menu? I want to start my app everytime Windows start.

Thanks

hliljegren
Posts: 111
Joined: Sun Aug 23, 2009 7:48 am
Contact:

Re: How to start app at Windows startup?

Post by hliljegren » Thu Nov 19, 2009 10:32 am

Srdjan wrote:Hi

Is it possible to create app shortcut in Startup folder under Windows Start menu? I want to start my app everytime Windows start.

Thanks
I'm not a Windows user but I can't see any reason why it should not work as Revolution apps are "ordinary" Windows apps, but then it starts at "login" and not at windows start-up. I guess there must be a registry setting you can use to auto-start your app also.

Srdjan
Posts: 26
Joined: Mon Aug 04, 2008 7:17 am

Post by Srdjan » Thu Nov 19, 2009 10:44 am

Well, you are right. I must correct myself. I need to start app at login :-)
I think that copying app shortcut into Startup folder is the easiest way. I just want to find the way how to get Startup folder address and to place shortcut there.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Nov 19, 2009 10:56 am

Hi Srdjan,

check this page for "specialfolderpath()" codes on Windows
http://www.sonsothunder.com/devres/revo ... ile010.htm
and then check "create alias" in the Rev documentation :)
"alias" = Shortcut!

Best

Klaus

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Nov 19, 2009 11:14 am

http://www.sonsothunder.com/devres/revo ... ile010.htm is the bible for specialFolderPath codes.

If you put a shortcut to your program into specialFolderPath(7) then the application should run on startup of the correctly logged in user. To start up when any of the users of that machine logs in then you can use specialFolderPath(24).

To create the shortcut link you can use some vbscript:

Code: Select all

On Error Resume Next
result = "OK"
Set oWS = CreateObject("WScript.Shell")
If Err <> 0 then
  result = "Error creating shell"
End If
If result = "OK" then
  sLinkFile = "<path for the destination of the shortcut>.lnk"
  Set oLink = oWS.CreateShortcut(sLinkFile)
  If Err <> 0 then
    result = "Error creating shortcut link file"
  End If
End If
If result = "OK" then
  oLink.TargetPath = "<path to your application>.exe"
  oLink.Description = "<uh... a description>"
  oLink.IconLocation = "<path to your icon file, which naturally will be the same as your application that has the embedded icon>.exe,0"
  'the trailing 0 is the index number of the icon to use inside the icon file. I confess I 
  'don't know what the difference is when there's only one icon for your application.
  'I have used index 0 or 1 interchangeably, while my applications contain 16 versions
  'of the same icon at different sizes and bit depths. Windows seems to display the right
  'resolution version of it whatever. At least for me, in my present experience.
  oLink.WindowStyle = 1
  oLink.Save
  If Err <> 0 then
    result = "Error creating shortcut icon"
  End If
End If
Set oWS = nothing
If you replace the sLinkFile path with the value returned from specialFolderPath(7) then that will create your shortcut in the current user's startup path. You can place the link in other locations, by replacing that path with the value returned from another specialFolderPath, such as (16) for the user's desktop, or (23) for all users' desktops. Having replaced the correct values in the script, you can get RunRev to

Code: Select all

do <thescript> as "vbscript"
and check the result to see what errors there may be - in theory, none, and you should find the shortcuts created in the correct location.

If you want the application to start without anyone having to log on, then you would need to install it as a service and/or mess with the registry.


HTH
SparkOut

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Nov 19, 2009 11:27 am

Or of course (duh!) get RunRev to do the complicated stuff!

Code: Select all

put the defaultFolder into theFolder
set the defaultFolder to specialFolderPath(7)
create alias "MyShortcut.lnk" to file <path to my file>
'make sure you include the .lnk extension to the name on Windows
set the defaultFolder to theFolder
I must admit, I'd not got that to work properly with the icons before, but I just tested and it's fine. Will save me bothering in future!
Thanks Klausimausi!

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Thu Nov 19, 2009 12:39 pm

Hi srdjan,

You might wanna try making it run via the registry. IMHO, its a more professional way of doing it... A quick code I can think of right about now is like below:

Code: Select all

get setRegistry("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\My_App",thePathToYourProgram)
Don't worry about messing up your registry, because you only need to change My_App to your own liking then just put the path of your program into the variable thePathToYourProgram or just use your own. You don't need to mess with the other parts of the code.. ^^
Parañaque, Philippines
Image
Image

Srdjan
Posts: 26
Joined: Mon Aug 04, 2008 7:17 am

Post by Srdjan » Fri Nov 20, 2009 9:42 am

Wow!
Thank you guys very much!
Now I need time to go thru all examples mentioned here.

Best regards

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Fri Nov 20, 2009 10:54 am

shadowslash wrote:You might wanna try making it run via the registry. IMHO, its a more professional way of doing it...
Not wishing to suggest there's anything wrong with your approach, but IMHO I don't think it can be claimed to be more professional. If anything, I would err on the side that it's more of a "quick and dirty" way, that is effective, but is rather reminiscent of "hacker techniques" and as such, could easily flag up as malware on the client system (as could any, of course, but I hope you see why I'm slightly dubious about starting something from the registry without going through a proper installation procedure).

jsims
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 25
Joined: Thu Apr 30, 2009 1:45 pm
Contact:

Re: How to start app at Windows startup?

Post by jsims » Fri Nov 20, 2009 9:03 pm

Additionally, depending on the security environment the OP is deploying to, changes to the registry may very likely be locked out. However, it is usually less likely for the Startup folder to be locked down. At least, that has been my personal experience having worked in a pretty strict environment (Centers for Disease Control and Prevention).

Take care.
- John

Post Reply