Batch file not running on Azure VM Commissioning until user logs in

Question: Does anyone know why the batch file does not start when the machine starts up until the user connects via Remote Desktop? Also, is there a way to execute the batch file when the machine starts up without requiring any user interaction?

Background: I have a virtual machine hosted in Microsoft Azure. I opened a remote desktop session, created a simple batch file that starts the game server (like gameserver.exe), created a shortcut for that batch file, and added a shortcut to AppData / Windows / Start Menu / Programs / Startup.

Now when I restart VM from Azure Management Console. I can't see the game server start up, no matter how long I wait.

But when I retire to the VM, as soon as the remote desktop session is connected, I see that the batch file is open and running, thus starting my game server.

I can create a shortcut to gameserver.exe and place it in the startup folder and it works as I expected as soon as the VM restarts. However, I need to do a couple of different things to set up the server before starting it up, so I wanted to use a batch file to do this.

+3


source to share


3 answers


The only way I can get something to get started on the server would be using Group Policy to configure the computer to automatically start something on boot. The next step will be the AutoRun (RunOnce) key in the registry, which does something when the user logs in. The next step would be PsExec , which can direct remote computers and run an executable or script of your choice.



Alternatively, you can configure a virtual machine to autologize a user and then lock the virtual machine. Thus, RunOnce from the registry will be launched or even remove application shortcuts to the startup folder. Learn more about automatic registration and blocking here .

+1


source


You can also try using Windows Task Scheduler. You just need to create a task with administrator rights that runs to run the \ exe \ batch program at startup.

Here is an example XML that you can import and modify accordingly.



<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2015-07-22T12:21:20.7566893</Date>
    <Author>SRIKANTH-PC\vishwanath</Author>
    <Description>sample task desc</Description>
  </RegistrationInfo>
  <Triggers>
    <BootTrigger>
      <Enabled>true</Enabled>
    </BootTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>SRIKANTH-PC\vishwanath</UserId>
      <LogonType>S4U</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>F:\Projects\zipalign.exe</Command>
      <WorkingDirectory>F:\Projects\</WorkingDirectory>
    </Exec>
  </Actions>
</Task>
      

Run code


+1


source


Use a task scheduler. You want the circled option.Task Scheduler

0


source







All Articles