Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

vb.net - Sendkeys On Disconnected RDP Session

I have a VB application which is scheduled. It focuses on some cmd windows and performs sendkey actions. This works fine when I have the RDP session open, it's only when I disconnect (not logoff) that the issue occurs. (This task is running on a virtualised server).

When I open the RDP session again after the task has ran, the application has thrown an error regarding the login permissions. I presume this is because the user is locked and therefore can't perform the actions?

I need to find a way around this, any help is much appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Don't use SendKeys.

Instead, if you have a program running in a command prompt, make sure the VB.NET program is the one to open it (or them) with Process.Start, and set the RedirectStandardInput property of the ProcessStartInfo object you pass to True. Then pass commands into the process's StandardInput property as though writing to a file.

This will avoid any focus-change problems, any problems to do with locked screen sessions, most if not all potential problems with integrity levels, most if not all problems with timing, and probably some other stuff I'm not thinking of.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...