servicewindows-10commandcommand-prompt

How do I automatically have a command run from my Windows 10 command prompt when I log in?


I'm using Windows 10. When I first login, I launch a command window using

cmd

and then run a service using

myserv -a

I would like all this to happen automatically after I login. How do I configure this in Windows 10 when I am not an admin user?


Solution

    1. First, you need to create a batch file for your commands. Here are the steps to do it:

      • Right-click anywhere on your desktop, go to New > Text Document.
      • Open the new text document, and type in the following commands:
    @echo off
    cd "C:\Path\to\folder"
    cmd /c "myserv -a"
    

    IF ADMIN REQUIRED SKIP STEPS #2 and #3 see below for admin privileges

    1. To make this batch file run automatically when you log in, you have to place it in the Startup folder. Here are the steps to do that:

      • Press WIN+R to open the Run dialog box.
      • Type shell:startup and hit Enter to open the Startup folder.
      • Simply drag-and-drop (or copy and paste) your batch file into this folder.
    2. Now, every time you log in to your Windows 10, the batch file will run automatically, which, in turn, will run cmd and then your service.

    Since the service you're trying to run requires elevated privileges, it may be best to request that an admin user set up the automatic task, or grant your user account the necessary permissions.

    Admin users can setup tasks with elevated privileges via the Task Scheduler:

    1. Open Task Scheduler (Start > Windows Administrative Tools > Task Scheduler).
    2. Select Create Basic Task.
    3. Input a Name and Description then click Next.
    4. Select When I log on then click Next.
    5. Choose Start a program then click Next.
    6. Click Browse to find and select your batch file. Then click Next and Finish.
    7. Right-click the task you just created, select Properties.
    8. In the General tab, check Run with highest privileges.
    9. Click OK