• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why does this throw exception when called twice from java?

 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JNI DLL that checks to see if a user has locked their desktop. The code is below. When i use this code from Java at a command-line, everything works perfectly every time. I can lock the desktop and it returns "true" every time. However, when I install it as an NT service (with Tanuki), it works the first time and then throws an exception the second time. I have no idea why. So I have two questions:

1. Any idea why it throws an error the second time it's called?
2. Where do i find the meaning of the error code returned by SwitchDesktop?

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does GetLastError return?

If it's a standard error code, you can use the ErrorLookup tool that comes with VC++. Or you can look up the error codes here. If you want to get an error string from Windows, you can use the FormatMessage api. It might help you but sometimes WIndows error messages are cryptic. Usually, if I get a cryptic error message, I google the message that leads me to message boards where people have asked the same question.

My hunch is that once you call SwitchDesktop, the desktop stays switched, and next time when you call it, Windows gives error. That's just a hunch. You will have to get the error message to say for sure.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming I'm printing the error properly, it's 18.

I do:

char msg[256];
wsprintf( msg, "Error: %d", errorNumber);

then I print it to system.out and it says 18.

however, when I look that up in the MSDN link you provided, it says that means "ERROR_NO_MORE_FILES" which obviously isn't right. So the error must be defined elsewhere. any ideas?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is, why doesn't it throw an exception the first time you use it?

To me it doesn't make sense for a Windows service to be asking about the desktop, because it doesn't really have a desktop. It does make sense for a logged-in user to do what you're asking, but given that there's Remote Desktop Connection available, it's possible for there to be several logged-in users on a Windows machine at one time. Which of their desktops would the service be asking about?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
My question is, why doesn't it throw an exception the first time you use it?

To me it doesn't make sense for a Windows service to be asking about the desktop, because it doesn't really have a desktop. It does make sense for a logged-in user to do what you're asking, but given that there's Remote Desktop Connection available, it's possible for there to be several logged-in users on a Windows machine at one time. Which of their desktops would the service be asking about?



Good point, so yes, why does it work the first time? Any ideas what might be going on there?
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan, can you check if the screensaver is running when your get the error?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jayesh Lalwani:
Dan, can you check if the screensaver is running when your get the error?



No screensaver. I have screensaver turned off.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
My question is, why doesn't it throw an exception the first time you use it?

To me it doesn't make sense for a Windows service to be asking about the desktop, because it doesn't really have a desktop. It does make sense for a logged-in user to do what you're asking, but given that there's Remote Desktop Connection available, it's possible for there to be several logged-in users on a Windows machine at one time. Which of their desktops would the service be asking about?



I'm still confused about this, then, from two aspects:

1. Is it an undocumented "feature" that the first time your nt service (running as system) goes into a locked desktop, it acts as the user it started under? (makes no sense)

2. How then would I determine a locked desktop from something running as System? Is it possible? Would the following work?

* NT Service tries to open and switch to desktop "Default" of user "A"

Would this have the same result? And would if that were done, and worked, what if at the same time another service is checking to see if User "A" is logged on, would it return true?
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic