I have a windows form application. Which i like to run at windows startup. But it should start in minimized to tray mode when started like that. And if the user runs the app - maybe by double clicking the exe- then it should run as normal (not minimized). I know how to minimize app to try using code
Asked
Active
Viewed 1,072 times
1
-
https://stackoverflow.com/a/1732294/17034 – Hans Passant Aug 06 '18 at 07:02
-
How to detect if the app is started by user or by windows startup? – anandhu Aug 06 '18 at 07:13
-
In any kind of "minimized to tray" app you always consider activating the app's UI with the tray icon instead of running it again. But if you really want to then consider that vb.net makes it easy to implement a single-instance app, it is a checkbox in the Project > Properties > Application tab. And if you extra want to then you can have the windows startup shortcut pass an extra argument that you can check with Environment.GetCommandLineArgs(). Do favor KISS, keep it simple. – Hans Passant Aug 06 '18 at 07:26
-
1If you know how to minimise to tray in code then just do that. Have you app accept a commandline argument and include that in the startup shortcut or Registry value. You can test the commandline arguments in the `Load` event handler of the startup form and minimise there if it it's found. – jmcilhinney Aug 06 '18 at 07:36
-
Still not satisfied!! Okey, so i can have normal shortcuts which do not have this argument value, And during installation i can add registry startup entry with this argument right? So when user starts the application using the shortcut (desktop shortcut) then the argument wont be passed and during windows startup the app will start with the arguments passed right? – anandhu Aug 06 '18 at 07:40
-
Every time you start an EXE you use a commandline. Usually it's just the file name/path but you can include one or more arguments in that commandline if you want. The application will then receive those arguments and it's up to it what it does with them. Instead of telling us that you're not satisfied, how about you go and satisfy yourself by doing some reading on the subject and maybe even some testing of your own? – jmcilhinney Aug 06 '18 at 08:27
-
Think you didn get my point. I was asking of it was possible to make the app recieve the argument when started from the startup and to NOT recieve any argument when user starts the application by double clicking the desktop shortcut. – anandhu Aug 06 '18 at 08:34
-
1I think you misunderstood jmcilhinney. You specify what arguments the app should be run with. When double clicking the EXE it will run with no arguments, but when running it at startup you can specify additional arguments that should be passed to the application (you can either use the registry or the Task Scheduler). Also, funnily enough an almost exact same question was asked only a week ago: https://stackoverflow.com/q/51582139 – Visual Vincent Aug 06 '18 at 10:29