Screen information while Windows system is locked (.NET) - c#

We have a nightly process that updates applications on a user's pc, and that requires bringing the application down and back up again (not looking to get into changing that process).
The problem is that we are building a Windows AppBar on launch which requires a valid screen, and when the system is locked there isn't one in the Screen class. So none of the visual effects are enabled and it shows up real ugly.
The only way we currently have around this is to detect a locked screen and just spin and wait until the user unlocks the desktop, then continue launching. Leaving it down isn't an option, as this is a key part of our user's workflow, and they expect it to be up and running if they left it that way the night before.
Any ideas?? I can't seem to find the display information anywhere, but it has to be stored off someplace, since the user is still logged in.
The contents of the Screen.AllScreens array:
** When Locked:
Device Name : DISPLAY
Primary : True
Bits Per Pixel : 0
Bounds : {X=-1280,Y=0,Width=2560,Height=1024}
Working Area : {X=0,Y=0,Width=1280,Height=1024}
** When Unlocked:
Device Name : \\.\DISPLAY1
Primary : True
Bits Per Pixel : 32
Bounds : {X=0,Y=0,Width=1280,Height=1024}
Working Area : {X=0,Y=0,Width=1280,Height=994}
Device Name : \\.\DISPLAY2
Primary : False
Bits Per Pixel : 32
Bounds : {X=-1280,Y=0,Width=1280,Height=1024}
Working Area : {X=-1280,Y=0,Width=1280,Height=964}

There is no clean solution for this, Windows doesn't provide a way to detect that the work station is locked and that the "wrong" desktop is active. You can only detect the session switch, sample code is here. To make this work, you're pretty much forced to include this code in the app and have it leave a breadcrumb that it could read back when it starts back up. Be sure to reset it after you used it once so that the app cannot get stuck permanently.

This screen lock problem is dependant on what version you are using, either XP which uses GINA that locks the screen and Vista which uses ContentProvider, both of these mechanisms are ultimately responsible for this.
The only way to see if the screen is locked, is a screensaver kicks in, (this can be easily queried by running a pinvoke to query SystemsParameterInfo, to find out if the Screensaver is active or not - SPI_GETSCREENSAVERRUNNING and SPI_GETSCREENSAVESECURE to determine if that will trigger GINA or Content Provider) when pressing WinKey + L to kick in the screensaver, after the specified period of time, if no activity, then GINA or ContentProvider kicks in and replaces the screen-saver with a lock screen... I have included two relevant links that was posted here about the secure logging information under Windows...
'Invoking the Windows Security Dialog'
'Login into Windows from .NET application'

It would require a little work, however you could utilize EnumDisplayDevices, EnumDisplaySettingsEx, MonitorFromPoint, GetMonitorInfo all from user32 and grab a screen shot of the device.
If the PC is locked, or if there is an active screen saver, then the screen capture is always a beige color. You could check for that condition to know the system is locked. This works on systems being RDPed into also (Thin client to XP VDI for example.)
At least that works in my environment. Code samples can be found by Googling.

Related

Is it possible to develop a lockscreen for windows 10 using c#

Hi i have windows 10 Pro x64 bit and i will like to know if it's possible to develop a lock screen for windows 10 , without using hacks or not safe methods .. That will close the Pc monitor until a key is pressed .
I search the google but i did not find anything about that , other than how to disable it or how to change the background image of the already existing one
No, it is not possible.
The authentication experience in Windows is locked-down, for good reason. The system can be extended (previously using GINA for NT4 through XP, now Winlogon) but only really to allow for new authentication providers, not to change the user-experience.
Of course, you could always build your own full-screen application which mimicks a login screen, and it could be used to invoke the login action and create a session for that user, but if I press Ctrl+Alt+Del on my keyboard or WinKey+L, or choose any of the Logoff options from the start menu then I'll still get the "real" login screen, and that's by-design.
Historical note: Windows XP added the 'Welcome Screen' UX for computers that were not domain-joined. The Welcome Screen UI was a regular userland process which invoked the platform APIs for logging users on and off, and it was loaded into the special local login session. Hypothetically it was possible to replace this screen with another one completely, though I don't believe I ever saw anything beyond a proof-of-concept. There were third-party tools that customized the appearance of the login screen, but they worked by replacing image resources, they didn't actually replace the executable.
...but since Windows Vista the login experience was more controlled and I believe (correct me if I'm wrong) it's all controlled by the core authentication components, so it just isn't possible to replace it - not without seriously modifying the entire Windows security system.

Why does my Blink based browser play hide and seek?

We have a C# tool (that I wrote) that records online broadcasts taking place a custom written (that we wrote) flash app. (There are no DRM or copyright issues here.)
We've coded up a system whereby this tool is installed on a Windows Server 2012 R2 Amazon AWS instance. After we boot the instance, the tool loads, waits for the right time to start recording, launches a browser and passes the command line argument of the URL to access the broadcast. The browser will then load the flash app and the interview audio and video will start arriving at the browser instance on AWS
By way of a virtual audio cable driver, screen / audio capture directshow filters and ffmpeg a screen recording is taken. The C# tool calls ffmpeg and ffmpeg will record the screen reliably for the entire interview, then the tool shuts the whole thing down
The problem I'm having is that both Chrome and Electron browser sometimes simply don't draw themselves on the screen so all ffmpeg ends up recording is a blank desktop and the audio of the broadcast (hence, the browser IS running)
We found this out when recordings started turning up with X hours of merely recording the windows desktop and the tool's main window with a countdown timer.
A screenshotting facility was built into the tool and added to its web control interface, and this way we can test whether the browser is visible - a human looks at the screenshot of every broadcast, just after recording has started (the browser is supposed to be on show by this time)
We notice that 50% of the time, the browser isn't drawing itself on screen. By 50% I mean that every other recording that the AWS instance carries out, will be blank: AWS starts, records ok, shuts down. AWS starts again an hour later for a different broadcast, recording is blank, shuts down.. Starts/ok/shutdown. Starts/blank/shutdown. Repeat ad infinitum
What's even more strange is that if I run VNCviewer on my dev machine and connect up to an instance that is having a problem, the instant that the VNC connection is up and the remote desktop is showing on my screen, the browser suddenly appears as if nothing was ever wrong. A screenshot from before the VNC connect shows blank desktop, connect VNC, take another screenshot and the browser is there. All through it the audio is fine - the browser connected to the boadcast is fine, for sure
It's as though Chrome/Electron thinks "you know what, noone is looking at me so I'm not going to bother drawing myself". No screen saver is set, though the power plan has the setting "turn off the display after 15 minutes".
Perhaps Chrome/Electron have a test amounts to "if the display is off, don't draw". I can't explain the inconsistency though - the recorder launches at least 1 hour before it's needed, and sits there idle until it's time to start the browser. You'd hence imagine that the "power off the monitor after 15 mins" setting would reliably have ensured the "monitor" is "off" by the time every recording start comes around
This behaviour doesn't happen with any of the other browsers (but unfortunately the app doesn't and cannot work in them because it uses some weird chrome-only technology/API).
Can anyone suggest anything to look at to help debug this, or anything I can build into the C# tool to overcome the problem? Coding it up to connect to itself via VNC for a few seconds after it has launched the browser.. Well that just tastes nasty.
Naturally, as soon as I connect to the machine via VNC (rather than RDP - RDP isn't usable because the recording context is in a logged on session for a particular user) the problem goes away, which makes it frustratingly hard to debug.
I am not sure what exactly causes your problem, but it sounds like interacting wit the system prevents it. One way to interact with a system is to use the keyboard and this can be automated.
You could try sending a keystroke (like "F15") evey so many seconds in C# using
Windows Input Simulator or maybe SendKeys.Send and
Combine the above with some kind of Timer
Maybe take a quick peek at this app called Caffeine...it presses the "F15" key for you every so many seconds. They claim "F15" generally doesnt trigger anything in windows (since a release they made back in 2010).
Caffeine App

C# Monotouch/Xamarin - Reduce Launch Screen Display Time

Summary
I currently use the standard method for increasing the screen size width to iPhone 5 (by adding a launch image that is the same size as the iPhone 5 screen).
This launch image is added via the info.PList.
It takes a very very long time for this image to fade into the rootViewController.
Questions
What determines the length of time that the launch screen is displayed for?
Can I control/decrease this timeframe?
Can I control the launch screen time programmatically, despite having not added the launch screen image programmatically?
Many thanks.
That's the time while the OS (iOS in this case) is preparing your application to start.
No. You can not. (You can not do anything but specifying the image file in your configuration).
The launch time is the time when OS is preparing your app. The launch time is the time when OS is preparing your app + the time while ...Launching methods finish calls. And right your code gets an access, it (the launching image) is no more shown. However, obviously, you can just show the same image as your default image in your UI and continue doing some custom preparations. But me personally would consider that like 'wasting a chance to already start "entertaining" of users'.
P.S. This question is actually related to Xamarin pretty not much. Except, that considering Xamarin binaries size can just reduce the app launching time. But generally, many similar questions are widely available through "native iOS"/objective-c questions (even here on stackoverflow).
updated:
Actually, thanks Kirk for the correction on the details about FinishedLaunching. But I would really not recommend to play (freeze) much with that method as if your app won't respond in certain time, it will be terminated. Especially, as the freezing will be 100% just wasting time for users.

Automating cursor movements, mouse clicks and keyboard inputs in not helping to show that user is present on system

I have a software installed on my system which basically peeks my activity during working hours. It send a report saying how much time i was away from my system etc.
Since i m .net c# developer hence trying to break this system through my programming skills.
I have basically written up a windows form application which opens up an notepad for me and start typing some random characters into it. simultaneously it also performs some random clicks and moves the mouse cursor to give a feel that some one is on system and working even when i am not :)
I also use "SetThreadExecutionState" Pinvoke calls to keep system awake.I have also observed the User idle time and last interactivity time through "GetLastInputInfo" PInvoke system call while my mouse/keyboard are in automation process and it is also fine.
But this is not working for me. It works perfectly till 5 mins and then somehow it detects that user is not present on system.
any suggestions for the same.
Get a decompiler, crack-open the spying application and see how it is working inside. Only knowing the internal workings, you can create a "workable" any-spying program. But I would not bother with emulation of the activity, but rather spoof the way it reports to the server.
However, depending on where you live, it might be illegal to do these things and I would not recommend cheating your employer. And if spying gets on your nerves I'd also suggest to brush up your CV and start searching for a new job.

WIndows Mobile full screen problem

I have a windows mobile professional 6.1 application and I want it to be full screen in all pages so I put the code below into my every pages constructor;
this.WindowState = FormWindowState.Maximized;
this works OK but "sometimes" for example when I use
MessageBox.Show("alert");
or when I try to connect internet within application and there is a problem and Windows shows me some messages popping up from the top of the screen..in this cases I lose my full screen and the top menu bar of windows becomes visible again..
any ideas?
You can use SHFullScreen to hide the start icon and other system areas of the screen. There is an undocumented function named AllKeys which will allow you to block some of the hardware keys (notes, recorder, green + red phone keys) from running. It will require a lot of work because there are many ways to run programs and the taskbar has a habit of reappearing after a program is run. Simply calling SHFullScreen once is not enough. You'll have to handle WM_ACTIVATE messages and call SHFullScreen again and force your program to the top again. It's a struggle against the operating system to have a true kiosk application on Windows Mobile.
Getting an app to "kiosk mode" in Windows Mobile is challenging becasue the platform simply isn't designed for it. This page has a lot of links to resources of getting it working. Using your favorite search engine to look for "compact framework kiosk mode" is likely to bring up more as well.

Categories