Programmatically start application on login - windows

What's the best way to programmatically start an application on login for Windows? I know you can do it by adding an item to the startup folder in the start menu, but I want to have an option in my application to turn it off and on.

This is how you could do it in C#:
Registry.SetValue(#"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
"MyStartUp",
#"C:\StartUpApp.exe");
You basically need to add a registry entry. The above one works on start-up. There are a few more. I recommend that you download a tool like Autoruns to see all possible locations.

How about installing your program as a Windows service? Services can be switched between 'disabled', 'manual' and 'automatic', and you can access services from within your code (even from a Java application) and manipulate its state.
Just a thought.
Yuval =8-)

Related

How do programs that don't appear in the startup folder auto-execute on startup?

Just out of curiosity I was wondering how this is done. I know you can probably manually make a program startup using windows scheduler, but for something download from the interwebs, such as Discord, how does it autonomously give itself the ability to run on startup without actually being in the startup folder?
I found the answer elsewhere on this site, here is the link and a quote
https://stackoverflow.com/a/20781275/9546874
Add a new startup application Open your registry and find the key [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run].
For each program you want to start automatically create a new string value using a descriptive name, and set the value of the string to the program executable.
For example, to automatically start Notepad, add a new entry of "Notepad"="c:\windows\notepad.exe".
Some applications do not appear in the startup folder but start up automatically anyway. Programmers have the ability to disable their application showing up in the startup folder. To answer your question, it's a decision made by the dev team behind the application.
Here is a link to disable those applications using the shell: Disable items not in the Startup folder
This article goes into depth about how windows uses registry keys to open applications upon startup.
If you would like to disable discord's auto startup, this is how.

put application in startup

I am planning to start my application whenever the user starts the computer. ASFA I know, there are two options available to me:
put the application link to startup folder
Keep a the startup-registry location updated with application path
However, the problem is, AVs like Kasperesky reports the registry paths (if added by an app) as keyloggers. Just wanted to hear from you people, which is better? Adding a shortcut to startup folder or using the registry way.
I really would prefer that you didn't force my app to start whenever I reboot. So, if you really insist, then please put it in the Startup folder and don't hide it in the Windows registry where I will never be able to find it. There may be times when I need this thing not to start up every time, so please let me do the choosing by putting the shortcut where I can see it and manage it. Otherwise, if it gives me too much trouble, I may just start up Control Panel > Add or Remove Programs, and you really don't want that, do you?

Active windows in Windows and QWidget::activateWindow()

The Qt documentation for QWidget::activateWindow() states:
On Windows, if you are calling this
when the application is not currently
the active one then it will not make
it the active window. It will change
the color of the taskbar entry to
indicate that the window has changed
in some way. This is because Microsoft
does not allow an application to
interrupt what the user is currently
doing in another application.
However, Skype appears to defy this rule. If Skype is running but is not the active application, I can launch it from the start menu and it brings the existing instance to the foreground, activates it and grabs input focus.
And how can I do this?
(NOTE: This is specific to how QtSingleApplication works)
The solution is stupidly simple for my issue. Simply call AllowSetForegroundWindow(ASF_ANY); at the beginning of the application, and the original process will thus be allowed to bring itself to the foreground by use of SetForegroundWindow(). No strange hacks, just one line of code to add and no need to modify QtSingleApplication either.
I don't think you can do it reliably with the Qt API alone.
There are multiple solutions for windows. E.g. here, and here, and here.
The method I've used before is to declare a shared memory section, and write the application's window handle there. Later, when a second instance of your program is started, you can find the window handle of the first and activate it.
I don't think you have the issue of windows preventing you from doing this in this case, because your second instance is the active application, so it is allowed to 'pass focus' to other windows.
Use Single Application in Qt Solutions
For some applications it is useful or
even critical that they are started
only once by any user. Future attempts
to start the application should
activate any already running instance,
and possibly perform requested
actions, e.g. loading a file, in that
instance.
you can set the setWindowOpacity from 0 to 1 .the only thing is you may open it all the time

Customizable Windows right-click file uploader?

I'm looking for a "right-click upload" application like RightLoad - an application that can upload media files to a remote FTP server from the Windows Explorer's context menu. I want to customize the application to serve as a customized image uploading tool to a PHP-based CMS.
The user would upload images and other media files to a defined FTP account (I'm also very open for other methods of transport, as long as they are supported by run-off-the-mill web hosting stacks) that they could then use in the CMS they log in to.
For me to be able to do these customizations, the application would have to be Open Source - RightLoad is "only" Freeware. Alternatively, I'm open for closed-source and commercial suggestions as long as they allow "pre-packaged" server settings that can easily be deployed to the user.
Does anybody know such a tool compatible with at least the most current versions of Windows (XP, Vista, 7)?
Bounty
Thanks all for the great input. In the case at hand, I decided it's easiest for me to stick with RightLoad and create a workflow in which the URL presented by RightLoad after the upload is copy+pasted into the CMS. I am putting a bounty on this because I think it's a worthy question for future generations, and I want to be the first one to put up a 500 bounty under the new bounty system :)
You could just use the send to menu using window's My network Places like this http://techie-buzz.com/how-to/right-click-and-send-to-ftp.html
I think WinSCP might have everything you want:
Open Source under GNU GPL
Windows Explorer's 'Send To' Context Menu
Drag 'n Drop Shell Extension
lots of additional features
and it can be scripted and is more secure than FTP due to using SSH
If you insist on open source, why not create a custom context menu handler and send it using some open source FTP client?
I would have to check the details, if it's really viable, but I would start with it.
I just had an idea, tested and working:
use regedit to edit HKEY_CLASSES_ROOT/*/Shell
add a key in shell called FTP to Mysite, in the default value set it to FTP to Mysite.
then add a key to the FTP key you just created called command, in the command default value use:
C:\Program Files (x86)\Internet Explorer\iexplore.exe http://www.mysite.com?file=%1
what this will do is open IE and the address www.mysite.com?file=C:\path\to\file.jpg
now using $_GET you can get the file address, upload it via php to where ever, even add an interface...
now when the user right clicks on any file, they can upload it via your web site by clicking FTP
1) another software is RightLoad , i use it that this moment!
2) The nice software I used over years, was FLING. It adds Right Click menu in windows explorer... However, I have left the software, because till today (version 2.35) fling DOESNT support SFTP (And nowadays on all sites I use SFTP!!)
3) I DONT like SEND-TO menu! (because I think passwords saved in WINDOWS can be easily stolen by virus..)

How can I add my application in loginwindow.plist Programatically in MAcOs

I want my application to run as soon as user login.
For this I need the modify the /Library/Preferences/loginwindow.plist.
Manually I can do this using Plist Editor but I want to do this in my code.
How can I do this Programatically using C/C++
No, you do not do this by editing loginwindow.plist. Use the LSSharedFileList API, which is in the Launch Services framework within the Core Services umbrella framework.
You should probably create a launchd job instead.

Resources