Getting blank (black) screenshot with automated screen capture using task scheduler - windows

I am trying to troubleshoot a software bug in which we think an app may not be launching every time it is called. To test this, I created a series of scheduled tasks to launch the app, take a screenshot, and then close the app. These tasks are all run through .bat files.
Everything works fine except for the screenshots. When run as a scheduled task, the .jpg from the screen capture always shows a black box. If I execute the .bat file normally, the screenshot looks fine.
I am using nircmd to send the screen capture command and save it to a folder. The command I am using is as follows:
nircmd.exe savescreenshot "C:\File Path\"~$currdate.MMddyyyy$-~$currtime.HHmmss$.jpg
I am using Windows 7.

The task created is probably running in its own logon session, even if it is running as the same user.
Make your scheduled task run as the currently logged on user.
Keith Brown wrote an old but still valid detailled explaination of the logon session SID. The relevant part is at the middle, under "http://www.microsoft.com/msj/0599/security/security0599.aspx"
You can also poke around the access rigths with EnumWinStaGui.

Related

How can I automatically change the display settings for dual monitors to "mirror" when a user logs out?

I have an situation where users are using a projector as a second monitor (extended desktop where the projector is primary monitor) in classrooms. The issue arises when the user logs out, they do not switch the computer to primary monitor, or change the screen display settings back to mirror. The result is faculty not seeing a log in screen when attempting to log into our computers since the primary monitor is the projector.
I have thought of using a batch file using DisplaySwitch.exe /clone, this will change the display settings to mirror. Seeing as this script needs to be run on log out, I used Windows Group Policy to run on user log out. This isn't working for me, and after some investigation I believe it is because the batch file is unable to finish as Windows is terminating the script before completion. I could be wrong on the reasoning for it not working. I have also replicated the script in VBscript and PowerShell and wasn't able to get either to run on log out.
So, is there a way to automatically change the display settings on a Windows system to "mirror" or "duplicate" when a user logs out?
#echo off
title Script to mirror screen
echo Switching to mirror screen
DisplaySwitch.exe /clone

OS X LaunchAgent - Run when desktop ready?

I've created a bash script which does some complex stuff, including some bits of Applescript which involves clicking pop ups, its to run on every new account created on the machine to set up some browser extensions for users (Adblock etc)
The script runs when manually invoked just fine, but when put as a LaunchAgent is erratic at best. It seems to run whilst the create account login/password screen is up - it opens a welcome PDF for a start off and sometimes when you log in, preview is already open without the file.
Othertimes you log in and nothing happens for a good 50 seconds. Occasionally its behaviour is erratic too.
The script needs to run as a launchagent as it runs once per new account - the script actually deletes the launchagent plist at the end so it can't run again. Is there anyway to delay the running of the script to have it start once the desktop is fully loaded? Perhaps once the dock has appeared. I'm going to assume its trying to run too early, it can't open Preview or Safari, it tries to delete the plist which is in use and then just ends up in a confused loop. Obviously not the cleanest way to run.

Word COM in scheduled task on Windows Server

I have an application that uses COM to automate Word. It needs to run even when a user is not logged in. I achieved this on Windows 7 by making it run as a scheduled task which runs at startup and doesn't require a user to be logged on. I also had to use the 'hack' where you add a 'Desktop' folder in 'C:/Windows/SysWow64/config/systemprofile'.
I tried this same method in Windows Server 2012, but it doesn't work. I can see in the task scheduler that the application is starting an instance of Word. However, it then appears to 'hang' and nothing happens. I think perhaps the invisible instance of Word is showing an error message which causes the whole thing to hang, as I cannot dismiss the message.
Has anyone else had trouble getting COM to work on windows server? Is there any way of showing hidden instances of Word to see if an error dialog is showing? Or any other way of diagnosing what the problem is?
I know ideally we would have an app that created the word documents without using COM, but this is not an option at the moment.
Does your app work when run as a logged-in user?
In the past I've run into what sound like similar problems, when running programs that try to use COM interfaces; some tasks work, but others simply don't function unless run as a logged-in user with an interactive desktop.
For me the simplest solution was to set up the machine to log in as a user at boot (which you can set up in the control panel - or I think there might also be a sysinternals tool that supports configuring that nowadays), then make sure that task scheduler/Jenkins/whatever you use launches the app as the logged-in user.

MSMQ Trigger opens executable as background process

I'm using a Microsoft Message Queuing (MSMQ) Trigger to launch a standalone executable on Windows 8.1. The exe was not launching so I tried opening Notepad instead (thanks John). That did not work either so I peaked at the Task Manager and noticed that it was opening as a Background Process.
My question is: why does the application open as a background process and how do I prevent this?
Is it possible to add a launch Parameter, for example?
Edit
I should note that I'm okay with the exe running in the background once my application goes live. I would like to prevent it from doing so during development, however.

Selenium grid 2 over cygwin

Ok, this is a tricky one. I'm trying to set up a Selenium Grid 2 with some Windows 7 VMs to run Webdriver tests. To automatize the whole process I use some ant script that connects to the VMs through ssh to start/stop/reconfigure the nodes.
Everything works great, the nodes can register with the hub host and execute the test. Only problem is that I don't see any browser window during the test run. I can see the process and I see the test log being executed, but there is no graphical interface.
On the other hand, if I start the node manually through Windows, everything is normal.
I suppose the problem is that processes executed under cygwin cannot start Windows displays, but in that case, shouldn't throw an error? The other option I'm thinking is that Webdriver is using HTMLunit as a fallback, but then... why do I see the firefox process as long as the test lasts and consuming CPU and memory?
Through ssh, you only exchange with Windows stdin, stdout and stderr streams. The ssh connection is tunneling those streams and nothing else. You don't see Windows Desktop interface, but the Desktop object exists on the Windows machine, the programs (here the browsers) are connected to it, and all GUI interactions are live in there.
If the GUI doesn't require any user interaction, everything is fine that way. The dialog boxes are created, the program runs, once it finishes, the dialog boxes are destroyed by the application and the application closes. Nothing is blocking in terms of GUI our application.
If you program requires an user action in the created yet invisible dialog boxes, your program will be there waiting for your interaction to move forward. You will see the process in the task manager, doing nothing but waiting. As you don't have access to the Windows Desktop where the dialog boxes are created and virtually 'displayed', the program seems to hang.
A typical case 2 is if you remote run a program waiting for a user to do something, say notepad. You can launch notepad, it will be spawned and then it will wait for you to type some text or close it.
With your Selenium tests, you are in case 1: all the browsers' interactions needed to make the GUI working are actually done by Selenium server that does the navigation clicks and the program exit for you. Their GUI actually are living by browsing through your test web servers, you just don't see it.
Some further readings from Microsoft website on Desktops and Desktop Creation.
If you want to see the tests and have valid screenshots, you need to have a user logged in and those tests need to run as that user. Everything must run through that single desktop session, so you cannot use RDP to remotely connect to the machine. Your best bet is to use VNC, since that will connect to an already established session.

Resources