Running WinBatch.exe from NT AT Scheduler
Keywords: NT AT Scheduler
The AT command schedules commands and programs to run
on a computer at a specified time and date. There are several things to keep
in mind when using the AT command to launch a script.
The "AT" command, that allows scheduled program-run. Be careful, it uses a system account (not
administrator !!!)
Winbatch scripts running under the AT command have several problems.
- The AT command problem is that WinBatch is running then as a service and with a
DIFFERENT userid (some low-level default) unless you add special command line
options to run it as someone else. So, for example, if you're having problems
creating a directory via the NT AT command, that means that apparently the default
user does not have permissions to create directories.
- Getting userid during netlogon problems: Sometimes you can check environment
variables with the Environment function, but I think it does not
work since you are not completely logged in yet.
Although
the environment variables %USERNAME% and %USERDOMAIN% variables are
present as soon as the dosbox opens for a logon script.
- They are run without any reasonable default environment variables, temp directories, security
clearances, etc., etc., so you cannot make any assumptions about paths and stuff.
- They are run sort of as a "guest" user where the process running has no network privileges higher than
guest. It can't really log into network servers etc etc unless its uses the guest account or something
like that. So
it is real difficult to access stuff on network servers...
By default, the AT scheduler runs under the security context of the NT
System
account which doesn't have network access. There are two ways to get
around
your problem.
- Using the Control Panel Services applet, change the service account
that the
scheduler uses to an account that has access to the UNC you are trying
to
access. Make sure you enter the right password.
- Define the UNC on the target system as a "Null Session Share" and
then
reboot the target system. When it comes up again, it will accept
connection
requests to that share point from the System account on other machines.
I don't
recall the exact path to the registry key but you can use regedit to
search for
"nullsessionshares". When adding your share to the MULTISZ field be
carefull
not to delete what is already there.
The NT AT command can run when no-one is logged on within certain contraints:
- Hard code everything.
- No network connections allowed.
- You cannot send keystrokes to anything UNLESS the AT command is set to be interactive
AND there is a logged in user AND the
workstation is not locked ... only then *maybe* you can send keystrokes..
Note that you can also make a primitive scheduler with the TimeWait function.
Getting the NT AT command to work with WinBatch may be tricky. The command requires that the
user who is logged into the NT system has the appropriate permissions to be able to
run the scheduled job.
When run via the AT command, WinBatch runs more or less as a service and cannot
send keystrokes to anything (unless you adhere to the restrictions above).
You might look into the WinBatch TimeWait function to avoid the AT command altogether.
HINTS:
- Use the /interactive parameter, which allows the job to interact with the
desktop of the user who is logged on at the time the job runs.
Below is an example of how to use the /interactive parameter in the command line:
at \\server 23:59 /interactive "C:\MYDIR\MYWINBATCH.EXE"
- Make sure you specify only the server name (not the server name plus sharename).
- The quotes around the path to the app you want to run works only in NT3.5X.
In NT 4.0 and above, you have to remove the quotes otherwise the command is not executed.
There's a new registry value coming with 6a (or maybe 2000) to toggle this behaviour - see MS
Knowledge Base.
When the command in quotes requires a path as an argument, use the absolute path
(the entire pathname beginning with the drive letter).
- If your compiled WinBatch EXE is on a remote computer, specify the server and sharename UNC,
rather than a remote drive letter. You can use quotation marks around the command,
whether you are using "at" in the command line or in a batch file.
If the command includes switches used by both the command and "at",
you *must* enclose the WinBatch command in quotation marks. So, since we're using the
"/interactive" parameter, then you must enclose the WinBatch command script in quotes.
- If you are launching
an uncompiled .WBT, you must precede the .WBT filename with the path and filename of
the WINBATCH.EXE interpreter program.
Connecting to Network Drives
When the AT command is used across network drives, the scheduler does not recognize your
normal login mappings. So, even though you may be mapped to W:, the AT command will not recognize
this mapping. You must use UNC names as suggested below. "UNC" refers to the
"Universal Naming Convention" path, which is the standard way to access a networked
drive without having to map it to a drive letter. You also have the option to re-map the drive with the
NetAddDrive command, as described in the Win32 Network Extender Help file in your
WinBatch directory.
From the NT documentation regarding the AT command:
Scheduled jobs that access the network should not use redirected drives made by the user.
The Schedule service may not be able to access these drives and they may not be present if
a different user is logged on at the time the scheduled job runs. Instead, scheduled jobs
should use UNC paths.
For example, use the next command line:
at \\server\share 23:59 /interactive "\\server\sharename\MYDIR\MYWINBATCH.EXE"
**not:**
at x: 23:59 /interactive "X:\MYDIR\MYWINBATCH.EXE"
Additional Tech Notes:
IF the AT command is set to be interactive AND there is a logged in user AND the
workstation is not locked then *maybe* you can send keystrokes.
If you're using the NT AT command with the RAS connection, you might be able to bypass
this way of doing things altogether by using our WinSock extender. Take a look at
the WinSock DUNConnect function to dial for you, along with the TimeWait (or you
could TimeDelay(3600) to wait an hour) as alternatives to the AT and RAS phone stuff.
The NT AT scheduler runs tasks in the background. If you want to run them in
the foreground, a Winbatch user reported that a product called LaunchPad in conjunction
with Winbatch has worked well
for them on NT4.
Tip on MSIE5 and the AT Scheduler:
FYI for all you winbatch users that launch
your programs from the AT scheduler.
If you install MSIE 5 it'll replace your
scheduler with the TASK SCHEDULER. If you
look in START/SETTINGS/CONTROL PANEL/SERVICES
you'll notice the SCHEDULER is now the TASK SCHEDULER.
You'll also notice you can no longer specify a username/password to the account, through this interface.
Solution: click on MY COMPUTER, double-click
on SCHEDULED TASKS. Then you can reset all
your AT programs with the correct params.
Article ID: W13655
Filename: The NT AT command .txt
File Created: 2000:07:06:15:17:36
Last Updated: 2000:07:06:15:17:36