Detecting User Logon

M

Michael Bird

I have an app that starts when the system starts up, so it is already
running when the user logs in. The app sits in the system tray with a
NotifyIcon.

If I run launch the app manually once I'm logged in, everything is fine.

If the app starts automatically at system startup, when I log in, it doesn't
put its notify icon into the system tray. I assume there is some windows
message I should be looking for to re-show my notify icon, but I am not sure
what it would be.

Does anyone know what I need to do here?

Thanks.
 
G

Gabriele G. Ponti

Michael,

How do you start your application? Do you have a shortcut in the Startup
folder, via a registry entry, or is your application a service?

Gabriele
 
G

Gabriele G. Ponti

Make sure that the user used to execute the task has the proper permissions.

I was wondering, why you are using a task to start your application at
logon?
 
M

Michael Bird

It started as a regular scheduled app and then turned into a "run it 24/7"
app late in the development. Turning it into a service at this point would
take moretime than we probably have, especially since it has a small
windowed UI and we've never done that before with a task.
 
G

Gabriele G. Ponti

Michael,

If in fact your application is running (check with the Task Manager), but
the tray icon doesn't show, then you can try handling the "TaskbarCreated"
message.

This sample should get you started:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace RegisterWindowMessageTest
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private int msg;

[DllImport("USER32.DLL")]
private static extern int RegisterWindowMessage(String lpString);

public Form1()
{
InitializeComponent();

msg = RegisterWindowMessage("TaskbarCreated");
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.notifyIcon1.Icon =
((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "notifyIcon1";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

protected override void WndProc(ref Message m)
{
if(m.Msg == msg)
{
notifyIcon1.Visible = true;
}
else
{
base.WndProc(ref m);
}
}
}
}

Regards,

Gabriele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top