1

I've some processes I want to automate using an Azure VM. I want to automatically start it up, run something, then shut it down and deprovision it until the next scheduled startup.

I can start something on boot by using Task Scheduler and setting something to run on startup, before login. This works fine with a console app I've written which just does stuff and writes to a database without trying to open a window. It doesn't work with a batch file, which is how I originally wanted to go- use a batch file to run a PowerShell script which runs my app and then uses the return code to decide whether to shut down and deprovision. The obvious difference is the console window, so I suspect there's no UI at this point and cmd is choking waiting for it.

This poses a problem with the next task- periodically use screen scraping software to do operations on a remote website, pull records down and store them in the local DB. There's no API for the remote service. Without a UI, I can't launch Firefox in marionette mode and do the record updates.

I've tried adding registry entries as described in here and setting a task to start after login, but the task never gets run and although I can't be sure it looks like the UI comes up after the remote desktop session connects.

I've seen a solution that uses Powershell on a local laptop to script the startup of the VM and the establishment of a remote desktop connection, but if I was going to commit to leaving the laptop on to do this, the laptop may as well be doing everything, which I don't want- that's the whole point of trying to put it in Azure.

So, has anyone done something similar and knows how to get an Azure VM to come fully up into a logged in desktop without any interaction from outside?

  • Did you figure out a solution? – MInner Oct 14 '18 at 22:11
  • Nope. Most of the tasks didn't need a UI so they were fine as startup programs. The periodic web scraping task that did need a UI I just got into the habit of kicking off manually on a weekly basis on a physical machine. – Craig Graham Feb 13 '19 at 14:19
1

If you are using ARM template deployment you can use the following OSProfile for a windows machine to configure AutoLogon:

"osProfile": {
        "computerName": "[parameters('vmName')]",
        "adminUsername": "[parameters('adminUsername')]",
        "adminPassword": "[parameters('adminPassword')]",
        "WindowsConfiguration": {
            "additionalUnattendContent": [
              {
                "passName": "oobesystem",
                "componentName": "Microsoft-Windows-Shell-Setup",
                "settingName": "AutoLogon",
                "content": "[concat('<AutoLogon><Password><Value>', parameters('adminPassword'), '</Value><PlainText>true</PlainText></Password><Enabled>true</Enabled><Username>', parameters('adminUsername'), '</Username></AutoLogon>')]"
              }
            ]
        }
      }
| improve this answer | |
0

So, has anyone done something similar and knows how to get an Azure VM to come fully up into a logged in desktop without any interaction from outside?

You could use the following cmdlets to login your VM without any interaction.

echo "Connecting to 23.98.218.139"
$Server="23.98.218.139"
$User="user"
$Password="********"
cmdkey /generic:TERMSRV/$Server /user:$User /pass:$Password
mstsc /v:$Server

Save the script as a Power Shell script and execute it depends on your need. More information please refer to this link.

Notes: When you first login your VM, you should trust your PC.

| improve this answer | |
  • Thanks, but am I right in thinking this is a procedure to automate the establishment of a remote desktop connection from my laptop? That's not what I want- I want the VM to log in to a desktop on its own, with nothing connected to it- as a machine would if unattended and set to auto login. – Craig Graham Jun 29 '17 at 7:47
  • @CraigGraham Yes, the script could log into your VM desktop from your local PC. What do you mean log into a desktop on its own? – Shui shengbao Jun 29 '17 at 7:50
  • Hi, do you use a Windows VM? – Shui shengbao Jun 29 '17 at 7:52
  • 1
    Yeah it's a Windows VM. I must not have explained things well enough in my initial post. I have a process that needs a UI for programs to run, but doesn't need a person to be there. This process needs to be run on a schedule, unattended, without any reliance on a local PC. With a physical server, I could set it to auto login on power up, run my program and shut down until the next scheduled power up. I'm trying to replicate this behaviour with an Azure Windows VM. – Craig Graham Jun 29 '17 at 13:42
  • If my understanding is right, what you need is when your VM start, you want to start your program. Do you need Programs Run at Windows Startup? The program will automation run when your VM starts, please refer to this link. – Shui shengbao Jun 30 '17 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.