Remote desktop idle time - c#

We have an application that requires to be continously run but it can't run as a service so we run it in Windows 2003 console session. After migration to Windows 2008 and with the session 0 isolation, the GPO causes the session to teminate after the session is idle for 30 minutes.
I wrote a little C# application to simulate key press using sendkeys.send and sendwait but the remote desktop session still gets connected. Any source code or idea to keep the session permentantly active other than changing the GPO as this isn't possible for the time being?

I think there are prob two options you could look at for obtaining the desired effect.
1) SrvAny.exe - this is a tool provided by Microsoft, that will take any exe and run it from the services control panel. While there is no version that officially supports server 2008, the version that works on server 2003 works just fine. I've used it to run dropbox has a service in the past.
Here is a tutorial that does something similar with dropbox Dropbox as a service on server 2008
2) Write a stub application that will run as a service and do nothing more than launch the exe from the vendor.
I realize this is not what you asked persay, but it would give you the desired effect.

Related

Is it possible to run selenium as a windows service using C#? [duplicate]

So that we may perform front-to-back web UI testing, we are using Selenium and ChromeDriver to automate page loads/interaction as part of our testing pack.
This is behaving as expected during developer testing (on a developer's local machine), but we are struggling to perform these checks as part of our continuous integration build.
Our server plant is *NIX based, and all of our CI infrastructure runs on these machines. So that we may test Chrome under Windows (our delivery mechanism), we have configured a Selenium Grid. When the CI tests run, they access the grid, in order to locate a Windows node to run the tests on.
We have had a Windows desktop provisioned solely for the purpose of running these tests. This contains our standard enterprise build of Windows 7. This machine will be periodically rebooted in-line with the IT department's update policy.
In an effort to ensure the Selenium server is always running, we have added the Selenium Server (running in "node" mode) as a Windows service. The selenium Server is configured to start-up ChromeDriver to invoke the simulated user-interaction.
However, when running the tests from CI they fail due to timeout. Our working theory is, the system user that is running the service cannot create interactive windows. A web search has raised reference to the "Session 0" problem, but with little to no constructive advice on how to move forward.
Starting the Selenium Server process manually from an interactive session is not a viable solution, as this is leading to brittle tests - which are failing due to an infrastructure problem, rather than a genuine test regression.
How can we have an instance of Selenium Server started via a Windows Service whenever the system reboots, that is capable of launching Chrome instances?
It could be easily done with NSSM.
Installation of services looks like these:
nssm install seleniumhub java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role hub -hubConfig C:\selenium\hub.json
nssm install seleniumnode java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role node -nodeConfig C:\selenium\node.json
It provides easily way to remove service if needed:
nssm remove seleniumnode confirm
Add destination to nssm to your PATH variable and run from console as admin
UPDATE April 2021
NSSM is not supported for more than 3 years. So please consider other options like winsw or any other. WinSW does the same job as NSSM and allows to keep run configuration in xml.
You cannot run Selenium Grid as a windows service ever since Windows Vista. Microsoft calls it "Session 0 Isolation". You could do it in Windows 2000 or XP but since the time that Vista came out, Microsoft no longer will let Grid interact with the desktop (or any other UI programs for that matter). Regardless of the fact that you still see that "interact with desktop" checkbox, it is a red herring. So, you MUST run Selenium Grid in the foreground on that server in order for it to get access to the session. If it is running Windows Server, you could in theory have multiple sessions and leave Grid running in the foreground on one of the non-zero user sessions.
Right now you can't help it - it used to work fine in session 0 but for the past few days after chrome update only works for interactive sessions.
Related bugs:
https://code.google.com/p/selenium/issues/detail?id=8029
https://code.google.com/p/chromium/issues/detail?id=422218
My preferred solution to this problem (and my default choice for running Selenium Grid as a service) is to use a simple tool called AlwaysUp. It has a free 30 day trial to try it out.
What to do:
Download AlwaysUp
Configure AlwaysUp to start the Selenium Grid node on startup
Configure AlwaysUp to run the Selenium node as a specific user (not the default System user)
This way the the node will run as a service, survive machine restarts and work with the latest version Chrome.
If the user account you use to login to the machine is different from the user account you specify to run the node as a service then you will not see the browsers pop up on the desktop as they are running in a different user session. The end result is that it is almost identical to running as a normal service but gets round the Session 0 issue.
Yeah, you should use NSSM. Important is, that you add your windows account in the "Log on" tab, or any other valid account. If you run your node with the "Local System account" option, you will get the session 0 problem. With a normal user session, the nodes run smoothly invisible in the background :)
we don't use selenium GRID, we were disappointed with its stability. We use a "Jenkins Grid", that is jenkins slaves nodes on various servers.
The slaves are services with the interact with desktop flag. They run as services with NSSM, and the SERVICE_INTERACTIVE_PROCESS flag. Making sure that NoInteractiveProcess is set to 1 (cf https://learn.microsoft.com/en-us/windows/desktop/services/interactive-services).
We don't have the fancy features of the grid (that is balancing according the browser types slots). Instead, we have Jenkins balancing the test jobs using a slave node or another.
Initially we did not use the interact with desktop flag, having browsers to run without "real" display, but the behavior was not very stable (especially with resize commands).
Hope this helps.
As I explained on this thread, I found that using a small paid tool FireDaemon Pro saved me a lot of time from trying to configure NSSM and other free tools.
It works well in the background, and restarts Selenium along with the server, which was my main requirement for running Selenium Standalone Server as a Windows Service.
This free tool would probably do it:
http://yajsw.sourceforge.net/
For that to work, you need a wrapper.conf file and a script to run the YAJSW wrapper. I takes time to read the documentation, but it is a free solution.
I wrote an example shared here, that installs JBoss7 as a Windows service.
Of course, you can simplify my example by a lot.

Where is app pool located in visual studio?

I'm having trouble finding the app pool, I need to set my app pool to allow my crystal report to run properly. On my computer where I develop the application, it works properly but when I try to run the program on another computer it won't run, I've read similar articles about it here, but I can't finish the last part, where #Matt Palmerlee said that I need to set the application pool for it to work properly.
You are not using IIS server because your project looks like for local machine only.
The location of app pool is in IIS server looks like the answer above which is you don't need it i guess.
If your project did not run from other PC:
Install the version of crystal report like the version of your development side.
Use 32-bit crystal report run time.
Hope it helps
You may need to carry out a bit more troubleshooting, but if you need to configure the application pool, here's how to get there:
Open IIS (Internet information services) normally by clicking the start button and typing IIS
Application pools are the second node. Find the pool your application is using and change the properties.
Advanced settings:

How to deploy and run window service in AWS for cron jobs?

I wanted to run .NET window service/c# script as background process in AWS and I'm very new for AWS, So if anybody can suggest that how can I schedule my window service over the AWS to execute it every day based on time set?
The simplest way is to test and develop you C# windows server locally, and then use RDP to connect to the EC2 instance and re-install it there.
There is nothing special about running an EC2 instance - its just another Windows server (in this case) that you can install whatever you want on it.
Thats the basic minimum you need to do; of course, once you learn more about AWS there is probably a lot more you could do, i.e. setup automated deployments so that when you update your service it gets deployed automatically, autoscaling it, load-balancing it, taking snapshots and backing it up etc -
But, just to get up and running, just install the windows service like you would on any other windows machine and you can build from there.

Deploy a backend application on a Windows Server

I'm making an application in C# with VS 2012 that checks a database every 15 seconds and perform some actions when it finds data. Right now I've created a Console Application so I can debug it easely but during relese this application needs to run in a IIS server.
How can I do that? I've read this question but it looks like some sort of workaround because to run it I need to perform these steps. Right now I'm reading the docs about Windows Service Application, Is this the right way?
EDIT Sorry but I've never used Windows server before, so as people pointed out IIS is only a web server, the thing I need to do is run my application in a Windows Server environment
IIS is a web-server and accordingly it should be used for hosting web applications.
Develop a windows service which does the job of checking the database in intervals and invoke a web service (which you can host in IIS)
If your application is performing some data query and manipulation on the server then I would recommend the approach to host it in a windows service.
Some advantages to this are:
The service will start and run independently of a user logging into the server.
You can configure the service to recover should it experience an exception (ideally not!).
The service will start automatically (if configured) when the server restarts.
You can configure which user group (or user) the service should run under so you have a more granual approach to security.
As it's running as a seperate process, you can monitor its memory and processor utilisation.
Debugging is slightly more cumbersome but not difficult, one approach I've used is to install the service locally, start it and then attach to it via the debugger. This question describes another approach I've also used.

Web browser print from service running on windows 2012

We have a automated printing service running as System account printing web urls.
The idea is using WebBrowser to load page and call Print upon it finished loading.
This works fine on Server 2003 , 2008r2 etc but does not work on Server 2012 ONLY IF it was running as a service. running as a console application works fine.
The problem:
It would load web pages fine and would call Print() , Print() will return but nothing gets printed on the default printer: no print job at all.
I thought it would be account problem so I tried to run service as the same logged on user but still does not work, if that user run application as console app then it would work fine. So default printer and user account get ruled out.
I don't think it is a code problem (it must be though) as it works for older Windows versions running as service.
It seems something fundamental got changed for a service process in server 2012.
Update 1. It may relates to How do I print an HTML document from a web service?
However it works fine for me prior server 2012.
Update 2. It does not work even the whole print happens in a separate process, i.e. my service launches a process to do print, it does not work either. Everything works fine if I run same code in console mode. It is definitely not a threading problem but rather something deep in server 2012.
Now the questions are:
What is changed? Why it stopped working?
At http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/fdcfa0fa-50aa-4a61-be79-5b4c8f65fbf7/ we see that this was reported to Microsoft and confirmed as a bug in Windows 8 and Windows Server 2012.
This bug is triggered when trying to print from a 32bit process in non-standard user session (like e.g. a service).
According to Microsoft, this a bug was resolved in Windows 8.1 and Windows Server 2012 R2. However, we could still reproduce it on Windows 8.1.
On the same site, a workaround is given by Microsoft. This workaround solved the problem for us on Windows 8.1. It probably also works on Windows 8 and Windows Server 2012.
The workaround goes as follows:
Open Regedit and go to HKEY_CLASSES_ROOT\CLSID{BA7C0D29-81CA-4901-B450-634E20BB8C34}
Check the value of the "AppID" Registry Entry. In our case this was {AA0B85DA-FDDF-4272-8D1D-FF9B966D75B0}
Now go to HKEY_CLASSES_ROOT\AppID{AA0B85DA-FDDF-4272-8D1D-FF9B966D75B0} (or the respective value you found on your system)
Under this registry key, delete the entries with the name "AccessPermission", "LaunchPermission" and "RunAs"
Since this is a bug in Windows, you cannot fix it in your code. The workaround might have side effects, but we haven't seen any so far in our scenario.

Categories