I have a webservice that prints to a printer.
If the type of printer selected is one like the Office XPS printer or printing to a file such that user input is requested, the call from the client to the webservice hangs indefinitely.
I am running on Windows 7 and IIS 7 and there is no user input prompted for explicitly (ie not dialog box appears) and nothing appears in the event logs.
I am confused as to why the webservice call from the client to the service does not time out, as the service is running in release mode so the timeout is supposed to take effect.
I've searched around a lot on MSDN and here to no avail.
Any help greatly appreciated.
Related
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.
I am making a program that opens a website called Smashladder (https://www.smashladder.com/netplay?tab=matches), initiates matchmaking and then opens the emulator and basically does all the steps to connect to the opponent. When you match with someone, it sends a desktop notification (at least mine does). I want to have the program halt until the notification is sent then continue the program. How would I be able to have that information in a bool form (i.e notification was sent (t/f))?
edit: This is being made on windows 10.
So I wanted to create a windows service that runs a few commands in a batch file.
However, while I assume I can redirect stdout from the subprocess and read out an error message, I can't seem to find out how I would get that to display to the screen.
when starting a windows service, it gives errors when the service fails to start, so ideally I would like to just use the interface that pops up the other service errors rather than popping up some window of my own or writing a log file.
I used this to get started but it doesn't seem to have anything on error processing.
http://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus
He just outputs to a debugger. I can definitely do that, but ideally the person starting the service would want to know if there was an error starting.
Yes, you can redirect the STDOUT of the spawned process. MSDN has an article on that topic:
Creating a Child Process with Redirected Input and Output
You can use ReportEvent(), EventWrite(), or TraceEvent() to write log messages to the System Event Log (which is located within Windows' Control Panel), depending on which logging API you decide to use. Refer to MSDN for more details:
Event Logging
Windows Event Log
A service is a background task, it should not display its own UIs. Use the system Event Viewer to view log messages. The popup the user sees if the service fails to start is not displayed by the service itself, but by the Service Control Manager.
Starting with Windows Vista, services do not run in the same desktop session as logged in users (Session 0 Isolation), so they cannot display their own UI anymore. If your service must display a popup message, it can use WTSSendMessage() for that. For more complex UIs, it is best to implement that as a separate non-service GUI app that runs in the user's session, and then the service can launch/communicate with that app as needed.
When i double click on my server exe it runs as a console application and i can see the logs in console.
I have made a windows service using the code given at http://code.msdn.microsoft.com/windowsdesktop/CppWindowsService-cacf4948
Using this the server runs in background but i cant see the console. Can anyone tell me how can i send messages to the console from a service??
Thanks!
Got it! I print my logs from my service to a pipe handle and i just wrote a simple pipe client which reads the file and displays it in the console.
If anyone needs the code then ill post it here
Thanks!
Starting from Windows Vista the services are executed in a different session so most communications will not work.
http://msdn.microsoft.com/en-us/library/windows/hardware/gg463353.aspx
Microsoft have some ways to communicate with services as described here (only first paragraph).
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683502%28v=vs.85%29.aspx
i wrote a program in c++ of win32, unicode; it uses socket to read data from another program;
i tested it in a local pc; i compiled it with vs2008;
when used as a console mode, it works properly in both winxp and win7;
when used as a ntservice, it works in xp, but fails in windows7;
in win7, that is, its socket is work well, and it can output logs used logcplus, but it can not access another program's api to read data; meanwhile, its logs cannot show in debugview, though i output logs used OutputDebugString under debug mode;
http://technet.microsoft.com/zh-cn/query/bb203962(v=VS.71) says:
Session 0 Isolation
Services have always run in session 0. Before Windows Vista, the first user to log on was also assigned to session 0. Now, session 0 is reserved exclusively for services and other applications not associated with an interactive user session. (The first user to log on is connected to session 1, the second user to log on is connected to session 2, and so on.) Session 0 does not support processes that interact with the user.
This change means that a service cannot post or send a message to an application and an application cannot send or post a message to a service. In addition, services cannot display a user interface item such as a dialog box directly. A service can use the WTSSendMessage function to display a dialog box in another session.
if it is the reason, how to resolve it?
thanks