vbscript fails when run as scheduled task and user is logged off

Can a scheduled task in vbs have a desktop from which windows apps can get "sendkey" input?
Is there an alternative language, rather than vbs, that will work?

When logged on, these scripts run correctly, even when scheduled.  But when the user logs off the scheduled tasks fail (i.e. the edit to the file notefile.txt is not done) because the "sendkey" and the "appactivate" commands fail.

from the administrator desktop, run "note.bat" which uses cscript to call "note.vbs".  It creates logfile.txt and notefile.txt.
When executed, note.vbs attempts to edit notefile.txt.  It works correctly when interactive, fails when scheduled.  Logfile
shows that the return value of appactivate is false when scheduled.    

note:  there have been a number of similar questions recently but the answers have not been clear.  
If it can't be done I would like to hear why!

------------------------------- note.bat  

cd "c:\documents and settings\administrator\desktop"
echo time and date will be written above by vbs script > notefile.txt
cscript note.vbs notefile.txt > logfile.txt

----------------------------- note.vbs

set shell = wscript.createobject("wscript.shell")
shell.currentdirectory =  "c:\documents and settings\administrator\desktop"
mytime = time & " " & date & vbcrlf
wscript.echo "vbs script start " & mytime & vbcrlf
wscript.sleep 1000
return = shell.run ("notepad.exe notefile.txt")
wscript.echo "return = " & return
wscript.sleep 1000
return = shell.appactivate ("notepad")
wscript.echo "return = " & return
shell.sendkeys mytime
wscript.sleep 1000
shell.sendkeys "%f"
wscript.sleep 1000
shell.sendkeys "s"
wscript.sleep 1000
shell.sendkeys "%f"
wscript.sleep 1000
shell.sendkeys "x"
wscript.sleep 1000
mytime = time & " " & date & vbcrlf
wscript.echo "vbs script end   " & mytime & vbcrlf

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

no ... script language will help... if the user account is not INTERACTIVELY logged on...
as sendkeys and appactivate work on current INTERACTIVELY logged on user's program windows...

They will also not work if you just lock the workstation with the right user ...

it is a SAFETY mechanism... to make sure... only ONE user can login INTERACTIVELY on a machine simultaneously...

If u can provide a ... original.. script.. then I might be able to help you in modifying it such a way that...
it doesn't require... INTERACTIVE... sendkeys and appactivate functions...

other great simulation language is "Auto-IT".... http://www.hiddensoft.com/autoit3/


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David LeeCommented:
Sorry to be dense, but I don't understand what you're doing with the script.  That aside, why mess around with Notepad and SendKeys?  Use the FileSystemObject to create a text file and write directly to it.  That will work whether a user is logged in or not.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.CreateTextFile("c:\documents and settings\administrator\desktop\notefile.txt")
objTS.WriteLine "Write whatever you want"
I guess it is just a DUMMY code....

RROLOFFAuthor Commented:

Yes, this is a dummy code.  It duplicates the problem I am having with two applications by using a "notepad" dummy code that anyone can run.

My conclusion is that certain vbs commands, e.g. sendkeys and appactivate, don't run without a user being logged on and having a active display.    I wanted a script that would dial up my ISP (at&t worldnet) at 4am and then download antivirus updates.  My search led me to MSH and VBscript, and I progressed to getting a script that worked interactive, worked when scheduled if I was logged on, but failed when scheduled and logged off.    Microsoft has not clearly documented the fact that some VBscript commands don't work if not logged on.  Shame on Bill.

I came up with a solution that doesnt' use VBscript.  In Network Connections I make a copy of my dial up connection and give it a 10 minute timeout.  Then I make a shortcut to it and I can schedule a DOS script to run it and dial up at 4am (without using sendkeys to press buttons on the standard at&t gui).  My antivirus software has it's own download scheduler that will try to download signature updates, I set it to run at 4:05 am.  I've solved this problem because my antivirus program has it's own internal scheduler.  I would like to do the same thing with my stock charting program;  it doesn't have a built-in scheduler for downloads.

It's sort of fun to script a VB activity, put 1 sec delays between button presses, and watch it run.  I would like to better understand why MS can't enable sendkeys and appactivate for a scheduled task.  MS should document this better.

Thanks for your comments!!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.

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.