Task Scheduler not executing batch (bat) file with MSTest commands - batch-file

I have several batch files which set a log file path and start visual studio 2010 ordertests. When I execute a batch file from windows explorer it runs perfectly. The problem is that when I use the Windows Task Scheduler to run a batch file my orderedtest is not executed.
Sample Code:
:::
::: This batch kicks off the searchinlineset test set node.
:::
SetLogPath.vbs "\\spm08r2dw\ATPData\Webportal Test Results\"
%comspec% /c "call "%VS100COMNTOOLS%vsvars32.bat" & mstest /testcontainer:"%SmartUITestInstallPath%AUTs\Tests\DemoSuite\SearchInlineSet\SearchInlineSet.orderedtest"" /nologo /usestderr
OS: Windows 7/2008 r2
Task Scheduler Configuration Images:
General:
(source: vsoh.com)
Settings:
(source: vsoh.com)
Conditions:
(source: vsoh.com)
Edit Action:
(source: vsoh.com)
Edit Trigger:
(source: vsoh.com)

Navigate to the General Tab of the Scheduled Task and select "run with highest privleges". Change the user account to SYSTEM and use a command that allows authentication parameters to be passed in the code such as the PowerShell cmdlet Start-BitsTransfer.
Also, fill in the correct start in path or arguments as necessary under the edit actions tab. I use a .bat file to kick it off, so I fill in the start in box.

Workaround:
Navigate to the General Tab of the Scheduled Task and select "Run only when user is logged on". Now the scheduler will execute the .ordertest scheduled task. This of course requires the user to be logged on but atleast the .bat will execute on schedule.

Setting the permissions explicitly for the folder and the file to full control and giving the start in folder parameter as the path for the directory where the batch file fixed the issue for me.
Check out this link
http://social.technet.microsoft.com/Forums/en-US/winservermanager/thread/d47d116e-10b9-44f0-9a30-7406c86c2fbe/

Related

start a batch file on startup as administrator on win 10

I want to disable auto-updating on Windows 10.
I found out that disabling the service "WINDOWS UPDATE" will do this.
It did for some time, but when ever i restart my system it enables itself again and again. So I created batch file that disables it.
#echo off
NET stop "Windows Update"
I put it in startup folder but it worked only if it is executed as administrator. I tried to set properties of the shortcut to "RUN AS ADMINISTRATOR" but it stopped executing on startup.
Then I read about Task scheduler and added this task there but still its not working there even it just shows "The Directory Name is Invalid. (0x8007010B)

Runas command to read user details from a txt file

having an issue where a batch script of mine is changing time server REG Keys but requires admin privildges to do so, even if local user is admin.
My way around this i have found is using this line of code:
runas /noprofile /user:administrator\administrator "%UserProfile%\Desktop\Time Server.bat"
But this asks me for the admin password everytime, and i cant be doing this for 150+ users.
Can i get this command to read user details from a .txt file or .ini file?
Thank you in advanced.
OliV555
AFAIK this is not possible out of security reasons. I've spent a lot of time on this but at the end, I had to use a workaround:
Create a new task with the windows scheduler. In the interface select the admin user you want to run your script with and enter the password. Check the option to run the task with highest privileges. Let your task execute the batch file with all the code you want to run as admin. Don't enter any trigger to start your task automatically.
Now here's the trick:
To run your command with admin privileges simply execute
SCHTASKS /Run /TN <taskname>
If your local user is admin this will work straight on. Otherwise, you'll have to grant the user rights to start tasks.
EDIT: The scheduler will execute your batch file with system32 as working directory. So if you are using any relative paths in your script don't forget to adjust them or replace them with absolute paths.

Using Task Scheduler to run a batch file that contains the start /w command

I have a Windows XP virtual machine that I am using to run a legacy app. I am using a limited user account.
I have created a batch file that I'd like to:
Start the legacy app
Wait for the program in step 1 to close
Shut down the computer
So this is the code I am using (in this example, I am attempting to open notepad):
#ECHO OFF
start /w notepad
%windir%\system32\shutdown.exe -f -s -t 1
Because the legacy app needs to be run under an account with administrator privileges, I then manually created a scheduled task in Task Scheduler to run the batch file. The scheduled task is set to run using an account named Admin that has administrator privileges.
I am having a bit of an issue. When the scheduled task runs, nothing appears on the screen. However, I did notice that both cmd.exe and notepad.exe appear in Task Manager as processes running as the user Admin.
What am I doing wrong? How can I accomplish what I'd like to do? Thanks!
Sorry all, it was an issue with me not having Task Scheduler set up properly. I found this post which suggests to use the AT command to run the task interactively. This allows the Cmd window to be displayed when a batch file is run as a Scheduled Task.

Task Scheduler status still shows as Running after a BAT completes its task

I'm attempting to create a batch file that I can use with Task Manager in Windows 7 to copy users' local Google Earth file to a network location where it can be backed-up. It appears that the BAT is running just fine, but the task does not complete or stop once it's done & continues to show a status of "running".
Thanks in advanced for the suggestions!
COPY/Y "C:\Users\lena.domain\AppData\LocalLow\Google\GoogleEarth\myplaces.kml" "\\server\u-users\Lena\system backup\Google Earth" cmd.exe /C
Running your single line in a command prompt window results in error message: syntax error
Reason 1: There is no space between command COPY and option /Y.
Reason 2: There is cmd.exe /C appended at end of the line.
Use in your batch file the line:
COPY /Y "C:\Users\lena.domain\AppData\LocalLow\Google\GoogleEarth\myplaces.kml" "\\server\u-users\Lena\system backup\Google Earth"
And additionally make sure that this job is executed from task scheduler with credentials (account) which has the permission to write something on server. The local SYSTEM account often used for scheduled tasks has surely no permissions to access files on the server at all. It looks like the best account to use for this scheduled task is the user account of lena.domain. See also Configure a Scheduled Task Item (At least Windows 7)

Batch runs manually but not in scheduled task

I don't generally write batches, but I currently have a batch that uses forfiles to copy my FLVs from one folder to another. When I run the batch manually it works every time, but from a scheduled task, it throws a (0x1) error.
forfiles -p "C:\Program Files\Adobe\Flash Media Server 4.5\applications\name\streams" -m *.flv -s -d -1 -c "cmd /c copy #file ^0x22C:\Program^ Files\Adobe\Flash^ Media^ Server^ 4.5\applications\name\output\"
Not sure what syntax the scheduled task doesn't like.
Update
Under my scheduled task, Actions I have the following:
Program/script: name.bat
Start in (optional): \\servername\file\to\batch
Hi might be this is helpful,
I also face the same issue.
Just set the startin path like:
Here start in path is the path of batch file:
like you have enter in program script:
"E:\program related files\demo.bat"
then in startin just pass:
E:\program related files & done!
When my Start in (optional): path was a UNC path, it wouldn't work. So I moved my batch on the server and everything worked correctly.
UNC in Windows Batch Files
forfiles with UNC path
On Server 2008 R2 when running the batch file under domain user credentials, with confirmed "log on as a batch job" security in the Local Security Policy>Local Settings>User Rights Assignment,
even then my batch (copying a log file to a network share) would not run as scheduled task, until I selected in tab General the option "Run with highest privileges" (default NOT checked!)
The option Run whether user is logged on or not was also selected, with radio-button, but I guess this is quite standard, when selecting to run the task using a domain user account.
For the tab Actions : specifying the entire batch file name including its path, directly in "Program/script:" works fine (with Server 2008 R2)
Using double quotes inside the batch file causes no problems.
See the screen shot bellow.
You need to change the user to system
Most common reason for such problems is permissions: scheduled tasks does NOT always run with your user credentials. If you want scheduled task to run as you you will have to set it up as you or alternative user.
Besides that I hope that your line of code is a content of your batch file, you are not trying to run this command directly. Or are you?
P.S. What are these ^0x22 and ^ doing in your code?
I know this is an old question, but just wanted to share some info.
The (0x01) error code can also refer to resources that are not found. Therefore:
all files/folders referd from within the batch file should be accessible to the user which account is being used to run that scheduled task;
pay attention when using network locations in combination with "Run whether user is logged on or not" option;
the above-mentioned option can be tricky to use because some resources may be available only after log on.
For .bat files to run inside your scheduled task, you need to specify your .bat file path inside the start option - despite the fact that your .bat file is at the same directory as your .exe. Also, I flagged it to run with highest privilege. After I have done those two things, the task suddenly takes off without any problem!

Resources