Scheduling task using AT not working

I'm trying to schedule a task using AT.  The command is as follows:

at 16:00 cmd /c \"reg query "HKCU\SOFTWARE\Microsoft\Internet Explorer\T
ypedURLs" >> log.txt\"

If I just type the reg query command on the command line, it pipes the output fine to the log.txt file.  But as soon as I put it in an AT command, all I get in the log.txt file is:
"The system was unable to find the specified registry key."

I next tried creating a batch file with the reg query command in it and used the at command as follows:

at 16:00 cmd /c c:\temp\log.bat

That once again gave the same output in the log.txt file.  If I run the log.bat from the command line, it gives me the output I'm looking for in log.txt.

I tried adding some pause commands to the log.bat file when the AT utility ran it to see what was happening and nothing appeared wrong.  So I'm not sure what is wrong.

Any ideas?  Oh, and I don't want to use scheduled tasks either.  Prefer to use AT.

Who is Participating?
AvonWyssConnect With a Mentor Commented:
By default, jobs created by AT run in the system context. THe system context, however, will have virtually no registry keys in the HKEY_CURRENT_USER branch. So, what you can do, it to open Control Panel, go to the Sheduled Tasks, and modify that task you have created using AT to use the user you want to run.

Note that you will probably not be able to export that registry key from *any* currently logged in user, but only for the user you defined in the task properties. If that's fine with you, go for it.
I think it is a permission issue
with scheduled tasks you can specify the username and password;en-us;Q300160
you can try incorperating the runas command in the bat file
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

try using  
cmd.exe /k for interactive batch files.

I hope this helps !
have you tried the "interactive" switch?

it lets the task run in the context of the logged on user.

at 16:00 cmd.exe /interactive /c \"reg query "HKCU\SOFTWARE\Microsoft\Internet Explorer\T
ypedURLs" >> log.txt\"
SigTau66Author Commented:
Steven:  I had already looked at those MS articles and still couldn't figure it out.  Thanks for taking your time to submit an answer.

SysExpert & Franka:  Already did the /k command and it still didn't work along with the interactive switch.  And I'm trying to make this as hidden as possible so the person doesn't know they're having their browser history watched.

The correct and accepted answer was by AvonWyss.  The 3-4 hours I spent researching this problem, I don't know how many times I read about the AT command running in the system context and never thought that it wouldn't have permission to read that registry key.  I submitted the same scheduled command as yesterday, but this time I went to that task in Scheduled Tasks and had it runas the administrator on the machine and it worked perfectly.  

I appreciate all the help from everybody.

now you don't need the /interactive switch?
Shane, thank you for accepting my answer. However, from your comment, I am not sure whether you may still be missing a part of your "quest" with the system context. That is, the problem is not a permission issue at all.

The registry is mainly divided in two parts, the machine specific part and the user specific part. The user specific part is stored and managed completely individually for each user on the system. This is the HKCU key.

Now, any application or service has to run in a user context (which will then also provide an individual user key in the registry). The "system" context is therefore only sort of a special user, and what you were doing is to read its registry (which did not work out since the system context never ran Internet Explorer).

This said, it should be clear that the exported registry part will be out of the registry of the user you have assigned to the AT command, and not from the currently logged on user.
SigTau66Author Commented:

Yeah, I found that out running the command with the runas portion of the scheduled task.  After you gave me the answer, I realized I wasn't going to be able to pull that key out for the user I wanted on that PC.  So it looks like I won't be able to get that person's partial history of their Internet usage.  But, you answered my question in the aspect of why it wasn't working.  Which was all I was looking for at this point. :)

I'll continue on with my search for getting someone's Internet history without them knowing it.  Thanks anyway.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.