Run CMD File on Startup for one time RRS feed

  • Question

  • Hello all,

    I want to run cmd file in startup. its about joining active directory automatically and after that restart the server for completing domain join operation. but in script I put del command for deleting script after restart. because it restarts continuesly.

    the related script is like below :

    PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
    PowerShell C:\Users\administrator\Desktop\domainjoin.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
    move C:\Users\administrator\Desktop\domainjoin.ps1 c:\domainjoin
    del /f C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\domainjoin.cmd
    shutdown /r

    do you have some suggestion for this kind of operation?

    thank you.

    Friday, March 16, 2018 7:27 AM

All replies

  • Hi Amir.

    I think the simplest solution could be modifying the script to make it first check for the presence of a specific file (or for a value saved into a specific file): if this condition evaluates to true, then the script halts its execution and exits immediately without continuing; otherwise, the script will proceed its execution and do its job.


    Luigi Bruno

    Friday, March 16, 2018 12:59 PM