0

I want to launch a Windows spot instance on AWS with a specific AMI and launch the instance and run PowerShell command. The problem i am facing issue is that, when the instance is launched, it shows "Running" on the EC2 dashboard but the Windows was not logged in as I have already given the username and password of a local user in User Data. When I login into the server, the script starts running. But I want that spot instance should run the Powershell script on the Desktop after initialization. PS: I have tried multiple methods suggested by ChatGPT too. Thanks. :)

2 Answers 2

0

You can create a scheduled task and run it as that user, with a trigger of System Startup. The Trigger can also specify a delay, or a delay can be in the script.

Edit: If it needs to access the Desktop, use Sysinternals Autologon:

https://learn.microsoft.com/en-us/sysinternals/downloads/autologon

0

For a desktop after every reboot, you will have to setup autologon for that machine. This can be done in the registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"AutoAdminLogon"="1"
"DefaultUserName"="USERNAME"
"DefaultPassword"="PASSWORD"
"DefaultDomainName"="DOMAIN(IF ANY)"

The obvious security problem is the plain text password, but there is no way around this in local sessions. If you don't have any other local users, just make sure "remote registry" service is disabled.

Then create a scheduled task, exactly as @greg-askew wrote.

I would, instead of autologon, recommend to set up the script as a service using NSSM and the username of choice (not SYSTEM). This will, obviously, not work when a real user session desktop is needed. But thats (much) less often the case than I have been asked for autologn desktops - so maybe you should give this a try.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .