Powershell script to keep computer awake remotely - powershell

My colleagues and I work in a global business environment that requires us to do software rollouts after staff leaves (to reduce productivity impact) and what is frequently happening is that due to our power settings that I have no power to change, machines are going to sleep about 15 minutes after they leave the office and I still need to access them. They don't receive or install the SCCM package I send because they are asleep. Wake on LAN is not an option because of the hardware variety we have
What would be the easiest way in Powershell to batch keep several machines (possibly 200+) awake? And not bring down our network while doing it? I'm looking to create a script and I would prefer not to have to push it to the machine but rather do it remotely.
UPDATE:
So far one of my co-worker's solution was to run a wait command in CMD remotely for a specified time inside but I don't know if that would keep it awake? What constitutes "activity" as far as power management is concerned?

I hate to say it, but I'm not sure you can given how tightly your hands are bound and your druthers.
One semi-remote solution would be to push out a scheduled task to your client computers. You can specify the Wake the computer to run this task option on the Conditions tab. The Action could run a script silently from a network share, display a message, etc. What it actually does isn't likely very important, though the script could be coded to do something you find useful in your org.
Set the other settings creatively and securely enough and off the top of my head I can't think of any glaring security issues.

Here is 3 easy steps on how to create batch file app clicker to keep your windows 10 awake for as long as you want.
1 - Install Java JDK download link: https://www.oracle.com/ca-en/java/technologies/javase-downloads.html
2- copy paste the following code in a notepad and save it as CLICKER.JAVA in your drive like C:\CLICKER.JAVA
import java.awt.*;
import java.awt.event.InputEvent;
public class clicker {
public static void main(String[] args) throws Exception{
Robot robot = new Robot();
while(true){
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(60000);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
}}}
3- Open another notepad and copy past the following commands and save this file as batch file into your Desktop such as AWAKE.BAT
#echo off
mode con: cols=50 lines=10
#echo Started. Press CTRL+C few times to quit.
#echo off
set root=C:\Program Files\Java\jdk-16.0.1\bin
cd %root%
java "c:\start.java"

Related

Windows Services - How can I find the darktable instance in windows services

I accidentally screwed up my darktable configuration, so I reloaded it from scratch. To avoid losing all my recorded changes I have done to my pictures, I wrote a powershell backup script for the darktable database. I want to launch this script from the windows task scheduler when ever I launch darktable. I have found the event id which indicates in the security log of a new process has occurred which I should be able to use to automatically launch my backup script from task scheduler. I want to add code to the script to check the services to see if darktable is actually running and only perform the backup if it is. Anyone know how I can identify this?

Autohotkey on a remote desktop does not work when I disconnect my local desktop

Im am using Autohotkey to rerun Pytest every ten minutes on a Virtual machine offered my Microsoft Azure.
My .ahk script is simple.
loop
{
Send !{F10}
Sleep, 600000
}
The script works perfectly while Im connected to the remote desktop. But if I exit the full screen or disconnect from it., it does not work. The Autohotkey keeps on running but for some reason just does not register Send !{F10}.It only starts registering it when I connect back on it. Please help.
Autohotkey not functioning properly on minimized virtual machines is an issue that's been around for a while, with
(regarding Virtual Machines):
RemoteAdmin server process launches a program on request of remote
user (you). So R.A. is a parent process for AHK. Once you minimize
your RA session client it signals the RA-server that. RA-server thinks
now that since the client is minimized it does not need anything and
to consume CPU power it halts any activity of itself and its child
processes.
-wOxxOm
And in the documentation of other AHK functions, such as WinActivate
Known issue: If the script is running on a computer or server being
accessed via remote desktop, WinActivate may hang if the remote
desktop client is minimized. One workaround is to use commands which
don't require window activation, such as ControlSend and ControlClick.
Another possible workaround is to apply the following registry setting
on the local/client computer:
; Change HKCU to HKLM to affect all users on this system.
RegWrite REG_DWORD, HKCU, Software\Microsoft\Terminal Server Client
, RemoteDesktop_SuppressWhenMinimized, 2
^^The above registry change may potentially solve your issue as well^^
The forum thread provides a couple of different workarounds for this issue, but if you are just trying to put the VM out of the way while you do other stuff on your computer, the least gimmicky solution that I can think of would be to move the Virtual Machine window on the host computer to a Virtual Desktop by either using the Win+Tab shortcut or by using this guide. By moving the window to a virtual desktop, the Virtual Machine will moved out of the way in a manner where it would not be minimized, allowing it to continue running the AHK script. Additionally, you can quickly navigate between Virtual Desktops with the Ctrl+Win+← and Ctrl+Win+→ shortcuts.

How do I get Robotframework (in Eclipse) to respond to terminal prompt

I'm currently running Robotframework in Eclipse on Windows 10 OS. I'm using an external python library that allows students and teachers to use this extracted library to connect to our hardware devices. I'm automating the extractions from the main site package made by our developers. If more than one device is plugged into the USB ports on the PC, then the code does the following:
x = input("Select one device:")
selected = int(x)
This causes a terminal prompt so the user has to type in a 0, or 1 for example, then hit the ENTER key. User response will allow the code to further process a connect to the selected device. Note, this prompt is not a GUI. So when I run Robotframework, it will execute the steps up to the point where it's prompting.
It seems like this should be pretty easy, but I can't seem to figure it out. Since you're inside a piece of code that's waiting for input, how do you make RobotFramework do something with it?
Edit: It occurs to me that maybe there's a way to execute a delayed Robotframework step that starts an external python command after a specified time, to throw a '0' and a RETURN key response. I had a python file made from an import of pynput.py library which appears to work from the command line execution (prints a 0, or a 1, and a return line feed). There's gotta be an easier way I'd think, but I don't know what it is.
Edit: Can I run a keyword from a listener that watches for the command prompt and the keyword runs another python file to feed the prompt? If I get this to work, then all I have to do is leave the devices on the USB port (or hub for that matter), and select the devices I want to do further testing on. Our devices are supported Blooth tooth as well but I need to run both USB and BLE tests to verify our Python extractions the teachers and students can use.
Edit: The other option is to use a software programmable hub and select the USB with a specific device on it, but I'm trying to avoid that.
OK, I solved it using Robotframework background process. I wrote a small python file that gets executed from the process. It has a 5 second timer (more than I need) and then Robotframework runs the next Test Case step. The Python file then does some keyboard presses, selecting the port and an ENTER key which goes out to the console (feeding the input prompt). It connects the sensor.
So in my Robotframework Test Case I do the following:
*** Test Case ***
smoke_test
Start process . Python . usbportselect
open usb
The Python program called from the process looks like this:
import time
import pynput
from pynput.keyboard import Key, Controller
keyboard = Controller()
def choose_usb(portvalue)
keyboard.press(portvalue)
keyboard.release(portvalue)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(5)
choose_usb('0')
Note: I'm pretty sure this won't fix all the problems with using processes, but it's at least a start and a way to feed input to a prompt resulted from a future Test Case step

Reliable access to locked remote computer

What I have: I have Windows 7 on my home PC.
What I'm trying to do: I'm trying to keep TeamViewer running at home so I can always get to my home computer. The other day it got completely messed up and would not let me connect but everything else on the PC was just fine.
Items I've looked at:
I looked at this thread and it does not seem to apply to what I need:
Is it possible to start Teamviewer, to accept connections, from commandline?
... but it does not appear to be what I'm looking for.
I have looked at this:
https://serverfault.com/questions/48600/how-can-i-automatically-restart-a-windows-service-if-it-crashes
... and to test the script at the above URL, I stopped a service on my computer and pointed the above vbs script to that service and the vbs script will not restart that service, so that's not working.
What's happening:
From time to time on my home computer, TeamViewer hangs or gets messed up in some way and I cannot connect to my home computer. The last time this happened, the TeamViewer UI was still running but there was a little red dot next to the tray icon and the id numbers and password were blank in the UI so I had to right click and kill it and restart the computer and all was OK.
What I'd like to do:
Is there a way I can run some kind of script or something that will completely kill all TeamViewer processes and services and restart it completely? I'd like to schedule this type of activity once an hour so I can be assured of pretty much always being able to get into my home computer or else just wait an hour and it should be back up and available?
I have 20 years in IT with networking background, databases, GUI development, website development, hardware and software installation but no experience in brain surgery. I've given it a good try but am now asking for some help.
Thanks.
I think that task scheduler, taskkill and batch script is your friend here.
create a batch file to stop any current team viewer process and then restart it.
crate a batch file something like:
taskkill /IM TeamViewer.exe
start "" "C:\Program Files (x86)\TeamViewer\TeamViewer.exe"
(substitute the path to TeamViewer.exe on your own machine).
Then create an hourly scheduled task to run the script using the highest privileges (using Windows Task Scheduler).
Lookup taskkill for more info on killing tasks from the command line.
Just to add that you'll have to have the PC in a associated in your teamviewer account in a group (e.g. My Computers) and use the same account to connect - otherwise the password change on restart will prevent you connecting (you won't know the new password).

Run batch file on remote pc *visibly* to logged on user

I've got a batch file dmx2vlc which will play a random video file through VLC-Player when called.
It works well locally but I need this to happen on another machine on the network (will be adhoc) and the result (VLC-Player playing the video) must be visible on the remote screen.
I've tried SSH, Powershell and PsExec, but both seem to run the batch file and the player in the session of the command line, even when applying a patch to allow multiple logins.
So IF I get to run the batch file it is never visible on screen.
Using Teamviewer and the like is no option as I need to be able to call all this programmatically from my dmx program.
I'm not bound to being able to call the batch directly, it would be sufficient for me if I could somehow trigger it to run.
Sadly latency is a problem here as we are talking about a lighting (thus dmx) environment.
Any hints would be greatly appreciated!
You can use PSexec if the remote system is XP with the interactive parameter if you state the session to interact with, 0 would probably be the console (person physically in front of the machine).
This has issues with Windows Vista and newer as it pops up a prompt to ask the user to change their display mode first.
From memory, you could create a scheduled task on the remote system pretty easily though and as long as it's interactive the user should see it.
Good luck.
Try using web interface. It is rather easy: VLC is running http server, and accessing particular URL from remote machine will give full control over VLC. Documentation can be found here