sccm 2012 task sequence not running a exe or hta - sccm

I am trying to run a EXE or HTA file from command line, all it is, is a popup message that informs the end users of what is about to be deployed. I am run it from command line locally and it works great, but when I set it up as a task sequence it will not run.

Have you examined the log file smsts.log?
Run the HTA using a Run Command Line step.
Here is an example: %SYSTEMROOT%\system32\mshta.exe %ScriptRoot%\MyCustomHTA.hta
You could refer to the sample from here.
HTA in SCCM Task Sequence

Related

bat/cmd file do not work via task win scheduler

I have job in task scheduler on windows local server admin account that runs bat/cmd file that execute python script as different user (with accesses to locations and database) to make calculations, prepare file and then execute dbo procedure.
And it is sad :(
Job have action 'start a program' (I tried running it with both .cmd and .bat):
C:\PythonScripts\<run_data_prepare>.bat
And if bat/cmd file only contains an easy procedure, then it work properly:
python C:\PythonScripts\<python_script>.py
But if file contains code below it will only execute properly if I open it manually. If I open it via task scheduler, then it will start task and action and complete it (from scheduler point of view) but even the first command is not executed.
C:\Windows\System32\runas.exe /user:<domain>\<ServiceUser> /savecreds "python C:\PythonScripts\<python_script>.py"

Execute WIndows bat file in Jenkins

I am using Jenkins 2.46.1
I have a build pipeline plugin installed and I want to execute a Windows batch file in it. The batch file should execute in a new command window and not on jenkins console output. I give the below Jenkins pipeline groovy script:
node {
stage 'Init'
bat '''
call C:\\myprj\\mybat.bat stop
EXIT /B 0
'''
stage 'Deploy'
bat '''call C:\\myprj\\mybat.bat'''
}
In the init stage, I want to kill the process if it is already open and in stage deploy it should open a new command window and run my batch file.
The problem is that the above does not work. The build is succesful but no command window opens up. Pls suggest
Technically, to do what you're asking you should be able to run
bat 'start cmd.exe /c C:\\myprj\\mybat.bat'
This will launch a new command windows (cmd.exe) and run the batch file given. Depending how your Jenkins slave is running you may not see anything. (eg if it's running as a windows service or different user, you won't see anything)
Alternative solution if the agent is running in a service and you would like to get output:
bat(readFile("mybat.bat"))
Note: The bat file will need to be in your workspace.
Additional Note: You are no longer running the bat file from its original location. Instead it is being run from a temp location created by the underlying durable task system. This means things like %~dp0 in your script are not going to return the paths you might expect.

VBS script does not work properly from Task Scheduler in Windows 10

I have a windows server designed to perform mail merges for postal letters.
A outside server generates xls data sheets and SFTPS them to my windows server, along with a JSON file with further instructions:
The Letter to merge with (docx file)
An E-mail address to send a PDF of the merged letters.
The script works like this:
1. Constantly(every 60 seconds) monitor directory for JSON files. ->
2. If there is a JSON file, parse it. ->
3. Find XLS file related to that JSON file ->
4. Run VBA/ EXCEL macro to mail merge XLS and the letter into a PDF ->
5. Email PDF to appropriate contact ->
6. Move XLS file to Processed Folder
7. Move JSON file to PRocessed Folder
If I run it manually from the command line it works just fine. However, If I run it from Task Scheduler, either with "RUN" or automatically when the machine restarts or when a given user logs in the script fails. Steps 1, 2, and 3 work. The VBA code/ Macro fails to work.
I'm hoping this can be resolved through configuration of Task Scheduler. Here is my current setup:
Script runs from a bat file, the message script keeps a CMD window open that explains what the script is doing:
cscript C:\automerge\message.vbs
cscript C:\automerge\automerge.vbs >> C:\automerge\logs.log
Task Scheduler Settings:
Run only when user is logged on
Run with Highest Privileges
Configure for Windows 10 (tried using 7 and 8 too)
Trigger:
Trigger at logon - Enabled
Action:
Start a program
Details:
"C:\AutoMerge\JSON Watch.bat"
Conditions:
Start the task only if computer is on AC power
Stop if computer switches to battery power
Settings:
Allow Task to run on demand
If the running task does not end when requested, force it to stop
Can anyone give me advice on how to change the scheduled task or batch file to get this to work?
Try executing like this instead of calling the batch file directly.
32-bit
Action: "%SYSTEMROOT%\system32\cmd.exe /c C:\AutoMerge\JSON Watch.bat"
or 64-bit
Action: "%SYSTEMROOT%\SysWOW64\cmd.exe /c C:\AutoMerge\JSON Watch.bat"
If it is 64-bit... update your cscript to execute %SYSTEMROOT%\SysWOW64\cscript.exe
Turns out Noodles was right it was something in the code.
I created a file system object and used it to get a File.Name. Then I passed this File.Name(without the path) to a function that parses the JSON in the file. This worked just fine when I manually ran it.
JSONExists(File.Name)
In order to run properly from Task Scheduler I had to make sure it passed the entire file name including the path.
FPath = "C:\Automerge\"
JSONExists(FPath & File.Name)
I'm not exactly sure why I need the whole path with Task Scheduler and not when I run manually, but at least now I have a good rule of thumb.

Task Scheduler fails to run batch file despite reporting task completed

I have a simple batch file which calls a powershell script.
I've looked at the following 3 previous questions on the subject as well:
Run a batch file from Task Scheduler is not working with a java command
Windows Task Scheduler doesn't start batch file task
Task Scheduler not executing batch (bat) file with MSTest commands
It seems like I've tried every single combination of running the task and it still doesn't execute my powershell script.
batch file contents:
powershell.exe "E:\SIS\fileCopy.ps1"
If I run the command in the batch file manually, it runs just fine. Here are things I've tried to do to get it working:
I've change the Security options to run as System with "Run with highest priveleges" checked
I've tried every other combination of "Run only when user is logged on", "Run whether user is logged on or not" and "Run with highest priveleges"
I've tried adding the "Start in (optional" setting to the folder where the files are located.
I'm at my wits end and can't believe Microsoft hasn't figured out a way to make this easier.
You need to have task scheduler execute Powershell.exe and have the arguments be the path to your .ps1 file.
To validate your script is running properly, you should set the Security options to 'Run only when user is logged on'. It will then pop the powershell dialog when it runs. I often also use start-transcript to view the results of scheduled poweshell scripts.
After you validate the script is running correctly, you can set the security options however best fits your situation.
Use the execution policy flag to flag that instance to unrestrisicted because your powershell settings may be blocking script execution.
powershell -executionpolicy unrestricted -Command "E:\SIS\fileCopy.ps1"
I found that Task Scheduler can't run a batch file if it lives in a folder that is being synced by OneDrive. I had to move the batch file to another folder to get Task Scheduler to be able to run it.

Batch file is not running through Windows 7 Task Scheduler

I have a batch file that executes a php script which fetches files(pdfs) from the backend and saves locally. I have tried executing the batch file through command prompt and it works perfectly.
But when I setup a Windows Task Scheduler to run this batch, it is not working. The command prompt window pop ups and displays alot of unreadable characters and hangs there.
I have also chosen the option for the bat to run with highest privileges but no difference.
Any idea what's wrong?
My mistake. Managed to solve it. The path to php was not set properly.
Now it is fine.

Resources