Link to home
Start Free TrialLog in
Avatar of dtomyn
dtomyn

asked on

Scheduled Task - SysTray application

I have a VB 6 systray application that seems to work perfectly fine when started manually (i.e. double-clicking the exe).  What I would like is for the application to start via a scheduled task and appear in the system tray.  It would appear as though I simply cannot create a scheduled task to start the application and have it appear in the system tray.

So, what I guess I am asking is... has anybody created a system tray application that will appear when started via a scheduled task?  Will changing it to be a service help?

Thanks
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

I just scheduled an app that runs in the systray and it ran just fine.

Do you get any error messages?

Does the entry in the scheduler have a "Next Run Time", "Last Run Time" or "Status"?

Idle_Mind
The problem is that the scheduler service (as well as the services service) only have access to the console desktop. By default, the local login refers to that desktop, but as from Windows XP, this is no longer the case.
If your scheduler run as LOCALSYSTEM without the check "interact with desktop", that could be a step forward.

In any other case, you will need to develop 2 applications:
1) started by the scheduler
2) one sitting (all the time) in the systray (maybe hidden while the first one is not running), and displaying/interacting as needed

I have done this now 3 times for real-world projects, and it is working fine. This way, you can even have the systray icon be deployed on remote servers for supervising users that have to look at my application/services...

CHeers
dtomyn,

Have you created a SERVICE or just an application that resides in the SYSTEM TRAY?

Idle_Mind
Avatar of dtomyn
dtomyn

ASKER

Idle_Mind...
This is just a regular VB 6 exe.  It is not a service currently (I suppose I could make it a service, but at this point I would rather not).

angelIII...
The OS is Windows 2000 so I am not sure if I am running into what you are describing above.  I believe that this is the case though since it would definitely make sense (and is what I was guessing was the case).  A couple of questions for you:
1) Can you be a bit clearer as to what you mean by "without the check interact with desktop"?  That is I don't know where this option is.
2) I am curious as to your comment regarding having 2 applications.  How do you get the application sitting all the time in the systray to start with?  That is, I am not sure I am following exactly what you are saying since I would think I would have the exact same problem.

Thanks again
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtomyn

ASKER

Also, the scheduled task itself looks fine.  i.e. when I start it up it has a status of "Running" (I currently have the task itself disabled therefore it has no next run date).
Avatar of dtomyn

ASKER

Just saw your code posting.  I'll check out the code now...
Avatar of dtomyn

ASKER

Idle_Mind,
Thanks for the time in posting some code.  However, this still does not work for me.  That is, when I run the exe by itself it works, but if I schedule it to run it works in terms of it running, but it does not show up in the system tray.  i.e. I know it is running since I the scheduled tasks say "Running" and I see it in the task manager if I choose "Show processes from all users".
NOTE: I am running Windows 2000 Server on both my development machine and my destination machine (it behaves the same way on both machines).  Also, what account are you running your scheduled task under?  It is currently scheduled under my own account.
I am running WinXp Pro with an Administrator account.  When I scheduled the application I had to type in the the password form my account.

Idle_Mind
Avatar of dtomyn

ASKER

Hmmm... I don't have access to a Win XP machine right now.  I will install Visual Studio 6 on my XP laptop tonight and try this out then.  I am wondering if there is a difference between XP and 2000 Server in regards to this.  BTW, my account is a local admin on the box.
Idle_Mind's comment at 1:21PM applies to Windows 2000 also.  You need to provide the account name and password the scheduled task will run under.  From my perspective the first thing to do is sort out whether it's a problem with your program or something to do with the Task Scheduler.  Can you schedule and run any tasks at all?  If not, then it's a scheduling issue.  If other tasks will run from the scheduler, then can you create a copy of your program, one that doesn't use the system tray, and see if it'll run as a scheduled task.  If it does, then it's something to do with the code that puts the task in the tray.  Otherwise, it's something with the program itself.  
Avatar of dtomyn

ASKER

I realize you have to provide the account name and password in order for the scheduled task to run.  That is not what I am commenting on.  Instead, when I run my application or the code that Idle_Mind posted earlier it does not create a system tray when ran via a scheduled task.  If I start it manually everything works fine.  If I start it via the scheduled task the application runs but the system tray icon never appears (likely because the process has its own sort of "virtual desktop" that the icon goes to).  The application itself though IS running as I can see it in the Task Manager (but only after checking the option to see all processes).

So, just to be clear then, I have no issues scheduling tasks.  The problem is scheduling a task that is a VB 6 application that puts an icon in the system tray.
Idle_Mind's last post said "I am running WinXp Pro with an Administrator account.  When I scheduled the application I had to type in the the password form my account." and your reply "I don't have access to a Win XP machine right now.  I will install Visual Studio 6 on my XP laptop tonight and try this out then." led me to believe that that you might not know that you have to supply account information in Windows 2000 also.  Sorry that I misunderstood.

I'm on a Windows 2000 box right now myself and I just tried Idle_Mind's sample code as a scheduled task.  It worked fine.  The icon appeared in the tray right on schedule.  So we know that Idle_Mind's code works on a 2000 machine.  Since neither it nor your app works properly on your PC, it seems to me that it's something about it, the PC or its configuration.  Or perhaps something to do with VB on that PC.  If you'd like to test that possibility, then I've placed a compiled version of Idle_Mind's code on my web site at this address: http://www.mindspring.com/~d_lee/.  It's called STrayTest.Exe.  You can download it, schedule it, and see what happens.  If it works you'll see a stop sign appear in your system tray.
You have gone above and beyond the call of duty BlueDevilFan.  Even if you don't solve this problem, I hope you at least get an Assist on this question.

=)
Idle_Mind
Thanks!  You did the hard part though.  I'm just following along with troubleshooting ideas.
Avatar of dtomyn

ASKER

Thanks for testing on a Win 2000 machine.  This can then only lead me to believe that there is some configuration that is preventing the icon in the system tray from displaying.  I will test myself on my own Win 2000 machine (once I find an install disk so that I can install in my Virutal PC environment on my laptop).
Avatar of dtomyn

ASKER

Well, I tested it on my own Win 2000 and just like everyone is saying, it works.  So, now I am baffled as to why it does not work on these work machines.  I will update and award points once I figure this out (or someone helps me to figure this out).
Sorry if I'm adding more smoke than fresh air, but it looks like folks were confused about what AngelIII said -- and it made sense from my past experience with some scheduled tasks.

I understand that dtomyn's application isn't a service.  The Task Scheduler, however, *is* a service and that service has to run under a user ID.  This is a different thing than the user ID and password you give Task Scheduler when you schedule a task.

Under Windows 2000, go Start | Programs | Administrative Tools | Services.  Find "Task Scheduler", right-click it, and select Properties.  There will be four tabs, the second of which is Log On.  Under that tab is a radio button to select either "Local System account" or "This account".  If the "Local System account" radio button is selected, there is a checkbox to allow the *service* to interact with the local desktop.  This is the option that AngelIII was talking about and may be the "variable" that's allowing some machines to show the application in the tray and other machines to not.  Since it's the *service* that's launching the application, I would think that the service would have to be able to get at the local desktop, even if the application is running with a different user's permissions.

Again, my apologies if this makes things more confusing or if I'm just flat wrong.  Good luck!
aParser,

That doesn't appear to be the problem.  I can uncheck the "Allow service to interact with desktop" checkbox and when the scheduler launches the program the program's icon still shows up in the system tray.  So at least on my system that checkbox has no effect on the icon appearing.
You're absolutely right, BlueDevilFan.  Using your test application, I verified your results, but I also did want to maybe help clarify what AngelIII was talking about.

In my test, however, I did (somewhat) duplicate dtomyn's anomaly.  I tried running the task under two different user IDs (from the Run as: setting of the scheduled task).  The first time, as myself, the scheduled item showed up in my tray.  The second, with the task running as a different user ID, the item did NOT show in the tray, but DID show in the task list.

Dtomyn, is it at all possible that in the cases where the item wasn't showing up in the tray, that you were logged in as a different user from the username you used to schedule the task? possibly even the same username, but in one case a domain user ID versus a local user ID?
Recommend accepting Idle_Mind http:#11853016
Avatar of dtomyn

ASKER

Honestly, none of the comments helped me.  As a result, I would prefer to delete this question, but if I hear objections I guess I will accept somebody's answer.  However, since none of them were a solution to my problem I will have to grade it low.

Any comments?

As for the solution I implemented... well, it was decided that it was not worth trying to come up with a solution to this one.  As a result, we took a completely different approach.
"Honestly, none of the comments helped me."
The comments must've helped some.  In your 08/23/2004 12:20PM post you said, "Well, I tested it on my own Win 2000 and just like everyone is saying, it works."  That sounds like you felt the work done up to that point had helped demonstrate that the code works and it's possible to do what you wanted to do.  Certainly Idle_Mind's sample code helped get to this point.  
Avatar of dtomyn

ASKER

I suppose it helped in that others have shown that they could get it working and that I could get it working, but I already had code that worked (the code posted was just more of the same).  The issue seems to be a security one.
Anyway, I am glad that people at least tried to help, so I will give the points to Idle_Mind.