CopyFile API fails with AT command

I have a program that copies a file from Network Drive W: to Local Hard Drive E: using the CopyFile API Function. From the command line, the program works flawlessly. But, schedule the program to run with the AT command, and CopyFile fails with Error #5, “Access is Denied.”

I entered in this AT command from the command-line while logged in as Administrator:

at 11:01 /interactive “e:dataatdbu.bat”

The BAT file calls my EXE with the From/To parameters to feed to the CopyFile API function.

The “everyone” group has “Full Control” access to the file being copied and the directory it lives in. The destination directory is on a FAT drive.

By the way, the program works fine if I’m copying the file from one local hard drive to another, from the command-line or from AT.

You have run into one of those basic, but unobvious, security features of NT. AT jobs will NOT run under the security context of the user requesting it (even if you are an administrator). They will run under the security context of whatever you have the Schedule service running under, which is normally the System account. This account has 100% control over the local machine and drives, and 0% control over network drives. The best choice may be to set the Schedule service to run under the account of an account that does have rights to copy the network files.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: