Windows Service end of starting process notification (2003,2008) - c++

I have a service (C++) that during its startup might sleep for 10 minutes (error case).
in 2003 - it worked fine, when I migrated the code to 2008 product, Windows Services notify me that the service could not start (my application still alive - but from windows perspective after 1 minute it claims there is a problem..)
-> Though the code was migrated to newer version no change in code flow
-> there is only one thread that starts everything.
-> I can't start the application if this error occurs (I must sleep).
-> Is there any change in 2008 behavior?
Thanks.

There are changes in how session-ids are maintained. The interactive logged-in user would get session-id starting with 1 (In Windows 7/2008), which used to be 0 for previous versions of Windows.
Along with that there are restrictions on how services can interact with the desktop. If service creates/shows windows, it will NOT be rendered to session that belongs to current user, but it would be shown via session-id 0' desktop.
You may check this discussion

Related

How to know when the Winlogon desktop is ready for inputs?

I successfully used SendSAS in a service (Local System Account). I call the API four seconds after the service starts. It seems that whatever the boot process duration, Windows manage to cache (sort of) the call: the same code finally shows me a logon screen a few seconds after the power on, on a fast laptop (Win10), and also shows me the logon screen after a very much longer delay on a slow Server (2012R2) running virtualized (wmware).
I am also able to use CreateProcessAsUser (with an updated token) to inject a tiny executable in the Session 1, Station WinSta0, Desktop Winlogon. The process then uses SendInput to "auto-logon" the session (yes, this is an awful think to do do, I am aware of that).
My problem: if the tiny process starts "too early", nothing happens. If the service waits, say, 2 minutes, all is OK.
What API should I use (in the service or in the started process) to find out when the WinLogon desktop is ready to accept keyboard inputs?
I tried WTSGetActiveConsoleSessionId (in the service) and OpenInputDesktop (in the process) hopping that failure would indicate the need to wait, but with no avail.
When your process starts in session 1, attached to the WinSta0\Winlogon desktop, you can periodically test the Control Type of the currently IUIAutomationElement focused element.
The APIs to use are : IUIAutomation::GetFocusedElement and then IUIAutomationElement::GetCurrentPropertyValue for the UIA_ControlTypePropertyId property. When you successfully get a focused element of type UIA_EditControlTypeId, the Windows logon screen is ready to accept inputs.
Don't forget to add a Sleep call between each try.
Tested OK with Windows Server 2008R2 and 2012R2, and with Windows 10.

DuplicateTokenEx for changing windows sessions

I have a service which runs as system (in session 0) that is capable of spawning processes on the desktop (in user's sessions). I'm following the exact method described here: http://www.developerfusion.com/community/blog-entry/8389765/creating-a-process-in-another-user-session/
This code has been working for years, but I recently found out that the windows file I/O on the child programs is acting MUCH worse for the spawned process than if ran manually by a regular user.
The penalty can be seen by launching notepad (from the daemon running in session 0), and trying to open a file through the windows dialog. It takes more than 10 seconds just for the "open" file browser to come up. I used process monitor and saw that the File and registry access had almost 1,000,000 events. When doing the same process on a notepad launched manually, there are ~6,000 events.
I'm assuming I am missing some flag in the token impersonation, but I haven’t been able to find anything online. I ruled out my CreateProcessAsUser code by running it from session 1 vs session 0, and the session 1 code ran the same as the manual launch. Any ideas would be appreciated.
Extra information: This problem may be very specific because I have a roaming profile on the network instead of on the local machine.

CF Service continuously restarts every 25 seconds

After my laptop froze yesterday I rebooted, and now the ColdFusion 9 Application Server service starts and restarts endlessly! Although it's set to start automatically, upon bootup it does not start. So I start it manually. Then I look at the Windows Event Viewer which reports:
The ColdFusion 9 Application Server service for the "coldfusion" server was started. PID is 5788.
That's good. But then, about 9 seconds later, Event Viewer reports:
The ColdFusion 9 Application Server service for the "coldfusion" server is restarting.
16 seconds later, the Event Viewer reports that the service has, in fact, started again. And 9 seconds after that, it reports that the service is starting again.
Unless I manually stop the service, this cycle continues, with the CF service restarting itself every 25 seconds, give or take a second. Needless to say, I can't use ColdFusion. When I try to reach a page, I get error 500: There is no web application configured to service your request
I am running the developer edition of CF9, Windows. Computer behaves normally otherwise.
[Edit]
The coldfusion-out.log includes this:
Server coldfusion ready (startup time: 9 seconds)
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_IN_PAGE_ERROR (0xc0000006) at pc=0x6d6e2424, pid=5456, tid=7724
JRE version: 6.0_17-b04
Java VM: Java HotSpot(TM) Server VM (14.3-b01 mixed mode windows-x86 )
Problematic frame:
C [nio.dll+0x2424]
An error report file with more information is saved as:
C:\ColdFusion9\runtime\bin\hs_err_pid5456.log
If you would like to submit a bug report, please visit:
http://java.sun.com/webapps/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.
The detailed error report, C:\ColdFusion9\runtime\bin\hs_err_pid5456.log, has a ton of information, but I don’t understand much of it. I’ll be happy to post it all if you think you might be able to make heads or tails of it.
In the event that the only solution is to reinstall CF, can you tell me where to find the config files? I know I will need jrun-web.xml (and I know where it is), but where, for example, are the datasource definitions found? I can’t seem to find any folder or file with the settings from the CF Admin. (The CF Admin won’t run, so I can’t view them that way.)

Windows Service stays in Starting state

I have a Windows service written in CPP that I start manually. The service starts up just fine and works ok. However we have recently noticed in the Windows Services GUI that the service shows in the Starting state. Upon examining the Event Viewer it clearly shows that the service has entered the Running state.
Anyone got any nuggets of gold on this one?
Thanks.
The problem turned out to be an unaccounted for call to the SCM to start the service. Deleted the line and the problem went away.

Cannot start server in coldfusion builder 2

I have installed Adobe ColdFusion builder 2 and was able to set it up, using this tutorial
http://www.adobe.com/devnet/coldfusion/articles/setup_dev.html
After I restarted my computer (for some updates to take effect), I am unable start the server I added using ColdFusion Builder (cfserver). I get the following error -
'starting cfusion' has encountered a problem
Ensure that the server is not already running, or another application is not using the WebServer port.
Does anyone know what to do about this? I am completely lost
EDIT: This is the error the console prints out
[cfusion]:07/13 12:50:14 Error [Thread-13] - Platform, Locale, and Platform Name must not be null
If you are using Vista or Windows 7 I used to have a problem with trying to start the ColdFusion server unless I launched CFB with Administrator privileges and ran it in XP Compatability mode.