Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show notifyicon after logon

Status
Not open for further replies.

SBGibson

Programmer
Apr 18, 2001
125
IT
Hi guys,
I've coded a windows application that will be scheduled to start "at system boot".
This app use a notifyicon to give access at all functions. It works fine during normal use but if I restart the PC the app is launched correctly without logging but when I log in the notifyicon is not showed.
How can I restore the notifyicon of my application?
I tried with notifyIcon.visible=true into a timer that starts every 30 seconds but it doesn't work.
There's some way to do that?
I would like to avoid the conversion of my app into a service.

Stevie B. Gibson
 
I think you should register the application to run at startup by registering it in the LocalMachine registry.
Here is a function that you can use to set or remove run on startup
Code:
public static void SetRunOnStartup(string path, bool remove)
{
	RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
	if (!remove)
		key.SetValue("MyAppName", path);
	else
		key.DeleteValue("MyAppName", false);

	key.Close();
}
//How to use
Code:
string localPath = localPath = System.Environment.CurrentDirectory;
localPath+="\\"+Assembly.GetExecutingAssembly().GetName().Name+ ".exe";	
SetRunOnStartup(localPath, false);
With that, the icon will be always in the systray.
You can hide it or not depending on the user that is logged in.
obislavu
 
But in this way the application starts only if a user logs in, not at boot.

Stevie B. Gibson
 
Why do you want to avoid it being a service? The purpose of a service is to allow your application to start and provide service to others without someone logging into the machine it runs on.

Perhaps what you really need is for two parts. The service, and a client that provides the other functionality you are looking for to the user. Sounds like your current application is perfectly suited to be split into these two parts now.
 
Some quick way to convert a standard apps to a service?

Stevie B. Gibson
 
Well, there's the easier way and there's the secure way. The easier way is to take advantage of the "Allow service to interact with the desktop" option under services. This allows your app to remain graphical and not split apart.

However, there are some security risks with that. The recommended Microsoft way would be to cut out the code you use that is graphical and make that a standalone application, then take the rest and create it as a background service. Then pick your favorite form of IPC to communicate between them. (Usually TCP Sockets / Remoting, but sometimes people pick other creative methods.
 
Well, there's the easier way and there's the secure way. The easier way is to take advantage of the "Allow service to interact with the desktop" option under services. This allows your app to remain graphical and not split apart.

It works only with win XP or if you are already connected. If the service starts when no user is logged on in a win2k machine and then some user log-on the service is still unable to display anything. :(

Stevie B. Gibson
 
Hm, I thought for sure it was an NT based thing..
As a work-around for the win2k you could add a shortcut to the startup folder for "All Users" that can awaken the service's GUI. I believe this is how my Anti-virus works, because it has the startup folder shortcut, but if I shut down the service and re-start it, then I get the GUI again without having to click that icon.

If at all possible, try not to run the service with very high privileges.
 
I'm modifing my app to work as many services I've seen. Starting from service manager it runs only the core, when the user log on the service is called with a command line parameter that awake the GUI.
Now I've a problem with the context menu doesn't appear if I don't run the GUI in a separate thread. I'm working on it.

Stevie B. Gibson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top