ClickOnce app doesn't execute from Task Scheduler - batch-file

I have a ClickOnce application that we start on Log on and recurring. After I install the application the tasks work fine, but if I reboot the machine the scripts run but they fail to start my application. I added logging to the BAT file and I know it is executed, but calling the rundll32 line produces no result and generates no errors.
If I manually run the script, from explorer, it works and task scheduler executions start working as well. Also, if I manually run the clickonce shortcut the scripts start executing from the Task Scheduler. Is there someway to verify that dfshim is loaded, or load it before executing it? What am I missing? I tried clearing the cache and that seemed to fix it on one machine, but it seems like a coincidence because it did not fix it on another machine.
VBS Script Called first(Called By Task Scheduler):
Set WshShell = WScript.CreateObject("WScript.Shell")
obj = WshShell.Run("C:\Users\brnapolitano\AppData\Roaming\FirstAmerican\TaskScheduler\AppReferenceInvoke.bat", 0)
set WshShell = Nothing
BAT Script Called Second(Called by VBS above):
rundll32.exe dfshim.dll,ShOpenVerbShortcut
C:\Users\brnapolitano\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\FastLocalService\FastLocalService.appref-ms
I would like to make this a script fix, but if that's not possible, I will try adding it to the startup and see if that resolves my issue.

I found the answer(linked below). I am still in the process of testing, but it seems to work. dfsvc needs to be run, if not active, before running the command to start the shortcut.
ClickOnce app not starting from the scheduler

It's not clear from your post what is happening after reboot. After the reboot are you trying to run the scheduled task after logon or before logon? If the latter, your vbs and bat files are most likely running under a different security context than what you think it is. That could also be the case after logon depending on the settings in your scheduled task.
See Task Scheduler is not supporting option "Run with highest Privilege" and "Run weather user is logged on or not"

Related

Why is my .vbs running as intended when I execute in Windows but errors out when I try to schedule it as a scheduled task? [duplicate]

I'm trying to run a .vbs file as a scheduled task through Windows Task Scheduler. Under the 'General' tab, when I select "Run only when user is logged on", the script executes as expected.
However, when I select "Run whether user is logged on or not", and enter the appropriate credentials, the task runs at the scheduled time, but the script does not actually run. I've already tried running the script under wscript.exe as well as cscript.exe, but no luck with either.
EDIT: Even if I am logged in when the task begins, the script will still not run under the "logged in or out" setting.
Additional info: The purpose of this scheduled task is to run before I arrive at work. I've already configured my BIOS to startup at a predetermined time (06:00), and set the Task Scheduler to run at 06:27. I've successfully tested the BIOS startup, as well as the script itself (including using the Task Scheduler to run it). Therefore, the only weak link I can find is the option to "Run whether the user is logged on or not".
I'm running Windows 7 Enterprise.
Any help would be appreciated!
This is because normally it would run the script using the shell handler, which by default is wscript.exe. When there's no desktop environment (because no-one is logged-in) it would fail and abort script execution (or rather, not run the script in the first place).
To fix this, instead of running the .vbs file directly, change it to run cscript.exe (the command-line script runtime program) with the script's filename passed as the first argument. Also be sure to ensure you don't have any InputBox or MessageBox calls (instead use WScript.Echo to return messages to the user: wscript displays message-boxes, but cscript will write it to the console.

Task scheduler says task is running, but it's not

I am trying to create a scheduled task to run a batch file. I know that my batch file runs fine, because I have no problem running it manually. However, when the task calls it, it says that it's running, but it's not. The reason I know that it's not running is because it calls a python script, and the python script sends an email saying that the process has started. And I'm not receiving that email.The python process doesn't take too long (maybe 5 minutes at most), and the task keeps saying that it's "Running" after an hour.
I have the current settings with "Run whether user is logged on or not" (doesn't seem to work at all if I have it as "Run only when user us logged on", because the status never changes from "Ready" even if I tell it to run). I also have the setting with "Run with highest privileges", and just the name of the batch file under "Program/script" and the path to the batch file under "Start in". I also want to note, that I have the user account as "DOMAIN\Administrator".
However, I've tried other ways of calling it. I've tried putting the entire path with the batch file under "Program/script" (G:\GOM3_Update\FeatureServices\copies\test.bat), or putting the path to the python program, and then putting the path to the python script as an argument, but that doesn't seem to work either.
I'm not sure if this issue is caused by some major security settings with windows 10, or something minor in the task scheduler settings.
Here are my current settings:
Full path of the Start in is: "G:\GOM3_Update\FeatureServices\copies\"
The batch file:
"C:\Users\Administrator.DOMAIN\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\python.exe" "G:\GOM3_Update\FeatureServices\copies\database.py"
I would include a full path to batch file here:
From my personal experience it is usually the environment problem, aka things like current working directory etc..
Also, make sure to click the refresh button in the right pane of Task Scheduler because it is known for not updating the status of task unless you manually refresh. You may see it change from 'running' to 'ready' sooner if you do that.
The reason why I feel like your screen is not refreshing is because normally Task Scheduler does not allow any scheduled task to execute for longer that 1 hour and you said yours was still saying 'running' after an hour.
What does the exit code and messages say under tasks history?
Exit code 0 means no errors captured by Task Scheduler.
Another idea is to log the start of batch script (inside batch) to a log file before you do anything. And do the same for python file. This will help you narrow down the problem.
I struggled with this one also a lot, changing the User Account
AND Group. User Account alone was not enough for me.
This helped for me:
And then clicking on the Locations...you'll have to choose "WINSTADM"

EXE is not Executing from Schedule Task

My EXE is executing perfectly fine when I am executing it by double click on it, but it is not executing when I am trying to run it via Schedule Task.
I am running schedule task on a local machine as administrator. I have already set the following settings into the "Security Options" of the Schedule Task.
Run only when user is logged in (I am logged in when schedule task is running)
Run with highest privileges check box is checked
In my case, it didn't worked because of the start in location of the program.
Set the [Start in] (optional) properties of the scheduled task with the path where the exe file is exist.
The default [Start in] value is C:/Windows/System32
Depending on which Windows OS you're running this on, your EXE may have in fact started and is running in the background, with the user interface completely hidden. Depending on the EXE you are trying to run, it may be sitting there, hidden, waiting for user input that it will never get. If your EXE doesn't require any user input (something that just runs and then closes when it completes), then you might just check to see if the job is actually done.
A trick I have used to verify this is to create a small batch program like this:
#echo off
echo myEXE Scheduled Task Started %DATE% %TIME% >>c:\myEXE.log
myEXE.exe
echo myEXE Scheduled Task Completed %DATE% %TIME% >>c:\myEXE.log
Have your scheduled task call this batch script instead of myEXE directly. This will generate a text file (myEXE.log) that you can check to verify when the scheduled task kicked off, and then when (and whether) the EXE finished.
Just for kicks (and to test what I'm talking about) you can add these lines at the end of the batch script.
pause
echo Batch Script Finished %DATE% %TIME% >>c:\myEXE.log
If you never see the cmd window waiting for you to Press any key to continue... then you'll also never see the last line in your log file (myEXE.log)
Windows Task Scheduler is a strange beast of a program. It's not really a CRON like task scheduler and it's not a Quartz based program, other than relying on internal clock system.datetime, which has been known to have "issues" of its own.
Nevertheless, it can sometimes trip over itself (unproven, but from personal observations), when it comes to permissions of a task and who created it vs what account is used to run it.
I found the following steps gives me a "clean" task schedule every time, and the task runs every time:
Always run Task Scheduler as Administrator. If you don't have admin rights to do this, then you should even be here!
Don't create a Basic Task. Go straight to Create Task, and under your own admin account (doesn't have to be God Admin!).
When filling in the task wizard, don't provide a trigger UNTIL you've tested the task first. Also, make sure you've allowed the task to run whether you're logged in or not! That catches me sometimes.
Don't worry about Settings, for now. Accept the default
Save/OK
Close Task Scheduler
Restart it again, and again as Admin
Run the task you've created.
If all goes well, it ran! Do a CMD run of the EXE using #Wes's suggestion to be sure.
Now, place a Trigger of your choice
Change the Account to your proper task admin account, or a generic account with admin rights specifically created to run tasks. We call ours admin.tasks
Save everything and you should be ok from here.

Windows service recovery - run a program wont work

How do i do this?
i've tried all i can think of.
Browsing for my .exe file i want to run.
run a bat file
writing forcedos.exe in program textbox and path to my bat file in command line parameters textbox
Why cant it just work with an normal exe?
and i know it should run a program because it can restart the service correctly.
EDIT
Application: test.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Exception
This is my latest try to make it work.
the script has the code
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("iexplore")
Set objShell = Nothing
Now the script opens internet explorer if i run the cmd command
wscript.exe "C:\asfh.vbs"
The "run a program" recovery option for when a service crashes runs the specified executable in the same way as the service, i.e., it runs in session 0 (and so is affected by session 0 isolation, see also related questions) and it runs with the same security context as the service.
This means that it can't interact directly with the user (you can display a GUI, but nobody will see it) but it also restricts what the executable or script can do. For example, some shell API functions will not work properly unless the user account has been interactively logged in at some point. In the example script you posted, the script itself is probably running, but is unable to launch Internet Explorer because IE is only designed to run in an interactive session.
Provided you restrict yourself to basic functionality, it should all work as expected. (There is no master list that I know of describing what functionality is safe to use in a service context, but it is usually easy to guess. You can resort to trial and error if necessary!)
Also note that as far as I know forcedos.exe is no longer present in modern versions of Windows. If you want to run a batch file, you can specify cmd.exe as the application and /c myscript.bat as the command line parameters.

Jenkins task to switch on monitor if it's switched off

I use Jenkins to run our builds. What I want to do is to wakeup the monitor before build starts. This is what I have done so far.
Use nircmdc.exe (http://www.nirsoft.net/utils/nircmd.html) and prepare a batch file to turn on monitor. I have tested the script through command prompt and it works fine.
Then I add a build step in Jenkins to execute windows batch file before running the ANT script. Then I remote start the build (via URL). Console shows that the batch file is being executed. But the monitors doesn't wake up.
Then I included a target in ANT to execute the same batch file and tested running the ANT via CMD. This wakes up the monitor and continue with the build steps.
But, if I run this ant script from Jenkins, everything works fine except waking up the monitor.
Is this something to do with privileges ?
Has someone done something similar?
Don't think I've ever heard of a requirement to wake up the monitor, so probably no one has done anything like this.
However, your problem is probably due to Jenkins process running in a separate session from your machine's console. Have a look at my answer here: Open Excel on Jenkins CI, it explains how to get around the session issue.

Resources