none
Tray icon for Windows Service

    Question

  • Hi,

    I created a windows service in 2005.

    My service depend on some settings done by user. So i need to implement a System tray icon.
    And a menu in that, to open settings dialog.

    How i can do that, i tried

    .net VC code / I think not much change with C#

    m_menu = gcnew ContextMenu();   
    m_menu->MenuItems->Add(0, 
    gcnew MenuItem("Settings",gcnew System::EventHandler( this ,&sysService::sysServiceWinService::Show_Setting))); 
     
    m_notifyicon = gcnew NotifyIcon(); 
    m_notifyicon->Text = "Right click for context menu"
    m_notifyicon->Visible = true
    m_notifyicon->Icon = gcnew Icon(GetType(), ..\\CommonFiles\\images\\sysService.ico"); 
    m_notifyicon->ContextMenu = m_menu
     

    on OnStart ,  but didn't work
    service successfully installed, but didnt start. Showing service couldn't start, didn't report any error.

    where its wrong ...

    please help me on this ...

    Thanks in advance :)

    Akeeq
    Monday, November 10, 2008 9:55 AM

Answers

  • You can make a windows application start when windows start and be hidded.

    "Some app after we install runs hidden leaving just an icon on tray. thats also services, right ?"
    No. They are windows applications.
    Lucian Baciu, MCTS, http://studentclub.ro/lucians_weblog
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    Monday, November 10, 2008 12:24 PM
  • Regular user should not control life-cycle/state of windows service. Even more, there can be situation, when user does not have necessary rights.

    You can always make your windows application start during system start-up or user log-in.

    Vitaliy Liptchinsky
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    Monday, November 10, 2008 12:34 PM

All replies

  • Hi!

    You actualy should create a Windows Application, not a Windows Service. A Windows Service should not have a GUI of any type. That is because it should also work in an environment with no active desktop. So make it a Windows App with a tray icon.

    Regards,
    Lucian Baciu, MCTS, http://studentclub.ro/lucians_weblog
    Monday, November 10, 2008 10:22 AM
  • Hi,

    Have you set "Allow service to interact with desktop" property of windows service to true (this can be done during installation or in management console)?

    Vitaliy Liptchinsky

    Yes, and basically, windows services should not have any GUI. Even more, this property does not work on Vista (and therefore on Windows Server 2008)
    Monday, November 10, 2008 10:25 AM
  • Hi

    Thanks for reply ..

    Actually i want to work my application like a service.
    Start automatically when windows starts, work behind ... hidden.
    So i started create windows service.

    But user must get full control over my app ... to make it flexible.

    Some app after we install runs hidden leaving just an icon on tray. thats also services, right ?
    Is their any super method.
    How i get at least that icon indicating service is running.


    I also tried "Interact with desktop" HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<myservice>\Type set to bit 0x00000100

    neither  worked


    Akeeq
    Monday, November 10, 2008 12:20 PM
  • You can make a windows application start when windows start and be hidded.

    "Some app after we install runs hidden leaving just an icon on tray. thats also services, right ?"
    No. They are windows applications.
    Lucian Baciu, MCTS, http://studentclub.ro/lucians_weblog
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    Monday, November 10, 2008 12:24 PM
  • Regular user should not control life-cycle/state of windows service. Even more, there can be situation, when user does not have necessary rights.

    You can always make your windows application start during system start-up or user log-in.

    Vitaliy Liptchinsky
    • Marked as answer by Akeeq Monday, November 10, 2008 12:52 PM
    Monday, November 10, 2008 12:34 PM
  • hi


    thanks for reply.

    So most application that see on startup settings are may not be services.
    So i can try developing MFC application and setting it on registry startup items with its exe location.

    It is good practice, right ? I believed that such applications are all services.


    Thanks to both of you.

    Akeeq
    Monday, November 10, 2008 12:52 PM
  • A MFC app could be ok, but I recommend you to develop a Windows Application (.NET application).
    Lucian Baciu, MCTS, http://studentclub.ro/lucians_weblog
    Monday, November 10, 2008 12:54 PM