Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How do I keep rdp DISPLAY (gcp VM, windows server) ALWAYS ON?

Hi.

I have a python code which makes every minute a screenshot of my VM desktop. After I minimize window with RDP or disconnect the session script stops running.

Other scripts on VM are still running while I am disconnected, so the session is alive. The issue is probably that DISPLAY is not active.

How I make the display always on?

Thanks a lot

0 2 831
2 REPLIES 2

@CrFor 

Can you help with python library you using for this task?

This is the script:

 

import cv2
import numpy as np
import pyautogui
import sys
import time
from datetime import datetime
from csv import reader

def nestedSort(dict):
if type(dict) is str:
return dict

sorted_dict = sorted(dict, key=int)

ret = []
for key in sorted_dict:
ret.append(nestedSort(dict[key]))

return ret

def findRecursive(number, dict, img_rgb, img_gray, invert):
template = cv2.imread('font/' + str(number) + '.png', 0)
if invert:
template = (255-template)

w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)

loc = np.where(res >= 0.9)

for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, (pt[0] - 1, pt[1] - 1), (pt[0] + w, pt[1] + h), (0, 0, 255), 0)
index = pt[1]
if dict.get(index) is None:
dict[index] = {}

c = img_gray[pt[1] + h - 1, pt[0] - 2]
l = img_gray[pt[1] + h - 1, pt[0] - 3]
t = img_gray[pt[1] + h - 2, pt[0] - 2]

diff1 = abs(int(c) - int(t))
diff2 = abs(int(c) - int(l))

# print('----')
# print(pt[1])
# print(c)
th = 10
if ((c > 220 and invert) or (c < 20 and not invert)) and diff1 > th and diff2 > th:
#cv2.rectangle(img_rgb, (pt[0] - 2, pt[1] + h - 1), (pt[0] - 2, pt[1] + h-6), (0, 0, 255), 0)
dict[index][pt[0]] = "." + str(number)
else:
dict[index][pt[0]] = str(number)


def readExtraValues():
with open('data.csv', 'r') as read_obj:
csv_reader = reader(read_obj)
header = next(csv_reader)
if header != None:
for row in csv_reader:
return ";" + ";".join(row)

def find(image):
w = 100
image_crop = image[0:image.shape[0], image.shape[1]-w:image.shape[1]]
image_gray = cv2.cvtColor(image_crop, cv2.COLOR_BGR2GRAY)

dict = {}
for i in range(0, 10):
findRecursive(i, dict, image_crop, image_gray, False)
findRecursive(i, dict, image_crop, image_gray, True)

sort_dict = nestedSort(dict)

now = datetime.now()
current_time = now.strftime("%H:%M:%S")

f = open("values.log", "a")

val = current_time
for d in sort_dict:
s = ''.join(d)
val = val + ';' + s

val = val + readExtraValues()
f.write(val)
f.write('\n')
print(val)

f.close()
#cv2.imwrite('result.jpg', image_crop)

while True:
try:
image = np.array(pyautogui.screenshot())
cv2.imwrite('sh.jpg', image)
find(image)
except:
print('Screenshot failed')
time.sleep(6)

Top Labels in this Space
Top Solution Authors