Windows 7 scheduled task "runs" but doesn't DO anything - vbscript

I have a vbscript file that must run under 32bit on a 64 bit Windows 7 machine so that it can connect to a 32 bit Access database. From a run box I can enter:
C:\Windows\SysWow64\WSCRIPT.EXE P:\Applicants\Applicants.wsf
and it runs great. When I try to run this as a scheduled task, it runs in under a second (it shouldn't be that fast) and claims it finished successfully. This is the 'action' I am running it under currently:
Start a Program
C:\Windows\SysWow64\WSCRIPT.EXE
Arguments: //Nologo //B P:\Applicants\Applicants.wsf >> P:\Applicants\logfile.txt
I have also tried running it under CScript instead of WScript and the result is exactly the same.
Before I added "//Nologo //B" (a tip I found here) it would start running and never stop.
The optional "Start In" box is empty. If I put any value in it at all (tried P:\Applicants) the task fails to start with "Error Value: 2147942667." No solutions offered by searching this error code have worked so I leave this box empty.
The logfile never even gets created and none of the work the script performs is getting done.
The task runs under my network account and should have access to all needed drives and resources.
Suggestions? Without a logfile I don't even know where to begin troubleshooting this thing.
EDIT: New Info: If I set it to run only when I am logged in it works fine. It is only when set to run even if user is logged off that it doesn't work, even if I am logged in when it runs.
EDIT 2: Security context of 'run even if user is logged off' states that ""...select the radio button labeled Run whether user is logged on or not. If this radio button is selected, tasks will not run interactively. To make a task run interactively, select the Run only when user is logged on radio button."
So I guess it thinks my script is somehow interactive, but it isn't. There aren't any kind of prompts or dialog boxes or msgBox calls so I'm not sure why this would be an issue.

Got it! The problem was that I was referencing a mapped drive with P:\ both in the 'action' call and in the script itself. When I replaced all calls to the P drive with the full network path \server\share everything works fine. Of course mapped drives aren't available if I'm not logged in, makes perfect sense :p

You have two options.
1.Create a batch file with the command to run, then schedule the batch file to run instead of the VBScript file.
2.Run the script file directly, instead of using WScript or CScript.
Sources: http://social.technet.microsoft.com/Forums/en-US/windowsserver2008r2general/thread/464a3bb3-3bcd-47a0-ab03-f0b8910f2ed1/

Related

Windows Batch File for Login Shortcut

I know you can use tsdiscon.exe and tscon.exe to connect to a user account via the command line.
I want to write a simple batch file to accomplish this, so I can have a shortcut on my desktop that will quickly and easily login to another user account on this system.
I share this computer with my in-laws, and they are not very computer literate. Currently there are many steps in switching to their account, and I want to make it more streamlined for them.
It's been awhile since I've written a batch file, but I am sure there is a way to run a simple IF/THEN statement, that would check to see if the user is logged in, then either log them in with the given credentials, or switch to that users profile.
I want to know the syntax to make this happen, so I can put the .bat file on the desktop for them to click on.
Is this possible?
Logging out to your account? Suppose impossible.
Suppose your user is usr1 and you save your batch file to, say, your desktop.
Then, by running this batch file, you run it as usr1.
If your batch file contains the log out statement, it therefore ends the user account, therefore terminating the batch file, thus not being able to run the batch file successfully.
However, switching to a different account could be possible.
Try this out, if it works.
Essentially, you're doing the following:
#echo off
taskkill /IM explorer.exe /F
runas /user:COMPUTERNAME\ACCOUNTNAME explorer.exe
(Replace COMPUTERNAME and ACCOUNTNAME with the current computer name and account name (i.e. C:\Users\ACCOUNTNAME) of your in-laws account)
If that's not what you wish, then, sorry, I can't help you.
The batch script I previously mentioned here
Just give your machine a simple name customise one line in script. Test from command prompt:
fus
If it works with win10 you should be able to create two shortcuts with commands:
fus.bat 1
and
fus.bat 2

Windows Task Scheduler & Administrator user

I have to run automatically a batch file once a week to update a file.
To do so I have created a task with Windows Task Scheduler on the company Server with the following options:
Security Options: user me, run only when user is logged in, Configure for Windows Server 2012
Trigger: every Monday at 11.00am
Action: start a program (the path to the bat file with quote)
This configuration works fine. However I wish the update to happen even if I am not here.
So I tried to change to Security Options to:
User: administrator (with batch job rights)
Run whether user is logged on or not
Run with Highest privileges
Trigger and action are unchanged.
I have also entered the admin password when saving the task.
On the Task History the action and task are completed, but the bat file is not run and there is no update happening on my file.
The Last Run Result display:
Incorrect function (0x80070001).
Looking at other posts I have tried different combination:
Run with Highest privileges: ticked or not
The path to the bat file with or without quote
Try to add the path without quote in Start in (optional)
None of these worked. Any idea?
The code is working fine when activated manually. I am not sure what you mean by the command that start the batch.
In the Scheduler it is on the Action tab. The action is start a program and the details is the path to the file ...run.bat
When launch manually I right click on the file and select run as administrator.
Thank you in advance for your help.
Sylvie
had the same problem with a RScript.exe with batch .R file. Runs perfect with main user, also in command line, but when setting the 'run with different user account' it fails.
What I did: added the ScriptUser (an anonymous user that will work forever when I have left the building) to the group Power Users. (Ok, I don't think you are allowed to set it to Administrator). But local\powerusers did it for me. The strange 'Incorrect function' without any details is solved now.
V
I have been having similar issues with a new scheduled task I was setting up. I could run the .exe no problem by itself by clicking on it, but when task scheduler would run it, the app would execute instantly and return a success, but did not actually execute. For us, the solution was to include the Start in folder on the Action tab where you specify the application location. Leaving this value blank will default to the root directory where the most things do not have permission to run.
Task Scheduler Action Settings:

VBS: Display message on logon screen

It is possible to set up Windows so that it displays verbose messages during startup or shutdown.
I'm writing a VBScript procedure which will be ran at startup and I would like to display a meaning message instead of the default "Running startup scripts".
How to achieve this in VBS?
You need to use Windows administrative tools which allow you to configure start up for specific users or users group to execute anything on start-up, shutdown even change their backgrounds. Network policy maybe useful for that as well if you are on domain controlled environment.
Also you can use MSCONFIG on a single system to add or define what ever you want to run at startup, for as long as it is valid windows program.
Once you configured what script to run use Windows console (run that under wscript.exe) to execute your VBS file with what ever you want to put there (with wscript you will get dialog with your text in it).
Usually it should look like
Wscript.Echo "Meaningful message goes here"
If you run that under cscript.exe you'll get output in your console window.

How to run something after Windows logon is fully done?

I have a system service running on my Windows machine that can impersonate the currently logged on user and launch applications on their behalf (including UI apps).
It works fine when the user is already logged on into their interactive session, their Desktop is created, and so on.
The startup of the service is Automatic, so it is started automatically after each reboot. If it attempts to run some program (that needs UI access) immediately after the service is started, that program may fail - possibly because the autologon process is still in progress, the Desktop is not created yet, etc.
The question is: if the service starts "early", how can it wait for the interactive session to be fully initialized (apart from waiting some arbitrary time, which is not optimal)?
Or, can the service be started "late"? Is there a registry key, or a folder, or something else, that I can use to delay the service startup to the moment when the Shell is ready and it is safe to launch UI applications?
The easiest two ways to "execute some code when a user logs on" is to write a .bat file, and either:
1) Put the .bat file in the startup folder
<= Note: Windows 7/Vista has a new location for "Startup folder"
... or ...
2) Create a new Task that calls the .bat file at login
I option "2)" gives you finer control. It also allows the .bat file to "Run as Administrator" if needed.
If you'd like to make the .bat file pause briefly (e.g. to make sure things are completely initialized", you can add "ping -w" to your .bat file.
EXAMPLE:
#rem Waits 5 seconds before continuing
ping 1.1.1.1 -n 1 -w 5000 > nul

VBS Stop option forced to kill on 1 sec :(

I was writing a vbs script to monitor a process and restart it if it died.
however as i was new to vbs i made a mistake in identifying the running process and had a infinate loop of starting a new version and hence crashed my pc....
i have fixed the code to work properly now but in the script properties>script tab the "stop script after specified number of seconds" has been set to 1 and if i disable this option and kick apply.. its still set :( this has only started being like this after i opened a billion cmd consoles and crashed my pc.... is this some sort of security feature.. how do i disable it.
Had exactly the same problem on W7 Ultimate.
The following article was helpful:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/wsh_setindivprops.mspx?mfr=true
"To set global properties for all scripts that are run with the Windows-based script host
1. Click Start, and then click Run.
In the Open box, enter wscript, and then click OK. The Windows Script Host Settings dialog box appears.
Select the Stop script after specified number of seconds check box.
In the seconds box, enter the time limit you want to place on all scripts.
"
Just delete the [scriptname].wsh file in the same directory as the script. Possibly that's been made read-only or similar?
That's the file that contains the settings. You can find more details in this MSDN article: Setting and Customizing Script Properties (.wsh)
Edit: Some new suggestions that might help:
Try going to this key in the registry: HKLM\Software\Microsoft\Windows Script Host\Settings and checking if there is a setting in there that might be the reason. Might be worth going to the same path but under Current User as well (so HKCU\Software\Microsoft\Windows Script Host\Settings).
Otherwise there is an option in the Group Policy Editor called Maximum wait time for Group Policy scripts. I don't think this would affect you but might be worth making sure.
Finally, if neither of the above suggestions help maybe either of the following might at least alleviate the problem:
There is a property called WScript.Timeout which you can set at the beginning of your scripts (like WScript.Timeout = 60) that might help.
There is also a command line parameter \T to wscript that can be used to setting the timeout as described here.

Resources