Score:0

Spot instance windows auto login in User Data using Boto3

us flag

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. :)

Score:0
cn flag

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

Score:0
cn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.