so I'm trying to automate interactions with an application that requires a window to be opened on the (windows) host.
Right now, I cant seem to find a way to do this. Even with Psexec ran interactively, it still fails to open any window. Lets use this an example, I want to open notepad.exe on the hosts desktop session
- name: Run notepad.exe on the hosts logged in desktop sesion
win_psexec:
command: notepad.exe
interactive: yes
username: logged_in_user
password: logged_in_pass
Right now in this example, it goes straight to “notepad exited with code 0”
Is there an established way to do this in ansible? I feel this must be a common problem people run into, or maybe I'm just thinking about this wrong. Any help would be appreciated!
Related
Having some issues figuring out automation for RDP on win10. Would appreciate any tips you guys got.
What I am trying to accomplish:
Use an AutoIt script to:
Open a remote desktop connection
Check 'Don't ask me again for connections to this computer', click
connect
Allow for remote desktop to load
Disconnect
Attempted to run the remote desktop connection with mstsc.exe, but got the error
The shortcut name is
My code so far
Have also tried Run("C:\Users\Public\Desktop\RDP Consoles\administrator#windows-1") to no avail.
Anyone know why I am getting this error? Or of a better way to perform this task?
Run() actually starts a cmd process, so you have to obey the rules of cmd too.
cmd expects filenames with spaces (and some other "poison chars") to be quoted (and it has to be double-qoutes). In your example, you run mstsc with two parameters: C:\Users\Public\Desktop\RDP and Consoles\administrator#windows-1. To make it one parameter, quote it. Best practice: also quote any paths or filenames (to again avoid problems with spaces):
$x=Run('"C:\Windows\system32\mstsc.exe" "C:\Users\Public\Desktop\RDP Consoles\administrator#windows-1.rdp"', '')
Nope. On my Win 7 Ultimate and my Windows Server 2019 it sure works this way:
Run("C:\Windows\system32\mstsc.exe")
WinWaitActive("Remote Desktop Connection","")
Send("Put your Remote Desktop IP here")
Send("{ENTER}")
WinWaitActive("Windows Security","")
Send("Put your Remote Desktop user name here")
Send("{TAB}")
ClipPut("Put your Remote Desktop password here")
Send("^v")
Send("{ENTER}")
I am trying to have a PowerShell script run after a machine restart. I want the script to run on restart, not login. Additionally, I want the script to run in a window. I found many questions that are almost identical to mine but don't include having the script running in a window. I've tried including -noexit. I have tried to use task scheduler and while it says that my script is running, no window appears. What do I need to do to make it run in a window?
I do not want to change global keys making all scripts run in a window and I do not want to write anything in my script that prompts the user to close the window.
I have VS2015 set up so that it always runs as administrator (a la something like this https://superuser.com/a/468056/48346).
Now I want to create an AHK script to launch Visual Studio and run a few UI / Keyboard commands to get it ready for me - I want this script to run at login but that's a later problem.
The Null solution is obviously to turn UAC off, but I don't want to do that.
So far I'm stuck on the way the UAC prompt always grabs the whole screen and I can't use AHK to click the "yes" button or send any keyboard commands to press enter or something like that. I guess this is the whole point of the UAC prompt, not to allow anything to do it for me.
Is there no way to open VS without the UAC prompt showing? I'd need to open a specific solution file, so if it's possible from the command line, the solution file would need to be included in the command so that it opens.
So far I've tried the AHK command RunAs, but I couldn't get that to work - my personal user is a domain user that's a member of the admin group on my local machine. I tried creating a specific runner account with admin privileges and use the RunAs command with that, but that didn't work. I get an access is denied when I run this AHK code:
RunAs, runner, password, LocalComputer-Name
Run, %comspec% /k "start c:\Users\myacc\Documents\path\solution.sln"
The runner account is in the Administrators group on my local machine, which has full access to the folder where the solution file is stored including the file itself - so I don't understand why access is denied.
Is this not possible?
Ps. I'd ask this question on the AHK forum, but registering there seems to not send any confirmation email at all (no, it's not in my spam folder), so I can't post it there.
The answer is to schedule a task that runs with the highest privileges to run the script at logon. The problem I was really having was to construct and debug the script - running a task each time was cumbersome. So to debug the script, just right-click the script and select "Run as administrator". Then the UAC prompt will pop up before the script starts running but not during the script. Then when the script is ready, just schedule a task to run at logon and check the "Run with highest privileges" option for the task. Then you can try the task by right-clicking the newly created task and selecting run, then you will see it run without the UAC prompt.
My final version of the script just opens the solution file using Run, no RunAs required - the scheduled task is set to run as my user, with the highest privileges.
Run, %comspec% /c "start c:\Users\myacc\path\solution.sln"
I know you can use tsdiscon.exe and tscon.exe to connect to a user account via the command line.
I want to write a simple batch file to accomplish this, so I can have a shortcut on my desktop that will quickly and easily login to another user account on this system.
I share this computer with my in-laws, and they are not very computer literate. Currently there are many steps in switching to their account, and I want to make it more streamlined for them.
It's been awhile since I've written a batch file, but I am sure there is a way to run a simple IF/THEN statement, that would check to see if the user is logged in, then either log them in with the given credentials, or switch to that users profile.
I want to know the syntax to make this happen, so I can put the .bat file on the desktop for them to click on.
Is this possible?
Logging out to your account? Suppose impossible.
Suppose your user is usr1 and you save your batch file to, say, your desktop.
Then, by running this batch file, you run it as usr1.
If your batch file contains the log out statement, it therefore ends the user account, therefore terminating the batch file, thus not being able to run the batch file successfully.
However, switching to a different account could be possible.
Try this out, if it works.
Essentially, you're doing the following:
#echo off
taskkill /IM explorer.exe /F
runas /user:COMPUTERNAME\ACCOUNTNAME explorer.exe
(Replace COMPUTERNAME and ACCOUNTNAME with the current computer name and account name (i.e. C:\Users\ACCOUNTNAME) of your in-laws account)
If that's not what you wish, then, sorry, I can't help you.
The batch script I previously mentioned here
Just give your machine a simple name customise one line in script. Test from command prompt:
fus
If it works with win10 you should be able to create two shortcuts with commands:
fus.bat 1
and
fus.bat 2
I have a system service running on my Windows machine that can impersonate the currently logged on user and launch applications on their behalf (including UI apps).
It works fine when the user is already logged on into their interactive session, their Desktop is created, and so on.
The startup of the service is Automatic, so it is started automatically after each reboot. If it attempts to run some program (that needs UI access) immediately after the service is started, that program may fail - possibly because the autologon process is still in progress, the Desktop is not created yet, etc.
The question is: if the service starts "early", how can it wait for the interactive session to be fully initialized (apart from waiting some arbitrary time, which is not optimal)?
Or, can the service be started "late"? Is there a registry key, or a folder, or something else, that I can use to delay the service startup to the moment when the Shell is ready and it is safe to launch UI applications?
The easiest two ways to "execute some code when a user logs on" is to write a .bat file, and either:
1) Put the .bat file in the startup folder
<= Note: Windows 7/Vista has a new location for "Startup folder"
... or ...
2) Create a new Task that calls the .bat file at login
I option "2)" gives you finer control. It also allows the .bat file to "Run as Administrator" if needed.
If you'd like to make the .bat file pause briefly (e.g. to make sure things are completely initialized", you can add "ping -w" to your .bat file.
EXAMPLE:
#rem Waits 5 seconds before continuing
ping 1.1.1.1 -n 1 -w 5000 > nul