Link to home
Create AccountLog in
Avatar of Mel Brooks
Mel Brooks

asked on

Task scheduler not working unless logged in

I'm trying to get Task Scheduler to work unattended.  I have a vbs script that creates a CuteFtp object and uploads a file using sftp through cuteftp.  In task scheduler, if I click the option "Run only when user is logged in", then it runs while I'm logged in and it will run on demand if I select to run it.  If I choose "Run whether user is logged on or not", then if I try to run on demand, the status changes to "Running", but nothing happens. If I let it go to the triggered time, the same thing happens.  I just can't figure this one out.  I run similar scripts from a  different server and they have been running for years without fail from the Task Scheduler.  As a test, I changed the Action to open Excel.  Result is the same. Only works if I choose the "Run only when user is logged in" option

Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Try to configure the 'Run As' setting in the task by entering credentials for the account you are logged on with. It is the setting where you can change the user or group.

Avatar of Mel Brooks
Mel Brooks

ASKER

I'm not sure what you mean by "run As".   I don't see that option in Task Scheduler.  Already tried running the task as System.

My account is an Admin account, but running it under that still doesn't work.

The option is under the 'General' tab of the task settings, under 'security options'.

I put Run As between quotes as that term is generally used to describe you are running a program or task as a different user.


User generated image


Can you post the script?

below is a sample of the script I'm trying to run.  As mentioned previously, I did try running the script as System and running it as an AD Admin account.


' Create TEConnection object

Set MySite = CreateObject("CuteFTPPro.TEConnection")


' Initialize remote server host name, protocol, port, etc.

MySite.Host = "ftp.data.fakesite.com"

MySite.Protocol = "SFTP"

MySite.Port = 22

MySite.Retries = 30

MySite.Delay = 30

MySite.MaxConnections = 4

MySite.TransferType = "AUTO"

MySite.DataChannel = "DEFAULT"

MySite.AutoRename = "OFF"


MySite.Login = "username"

MySite.Password = "user password"

MySite.SocksInfo = ""

MySite.ProxyInfo = ""

' Connect to remote server

MySite.Connect

MySite.UploadAsync "\\Timas\Timas\NetManagerDD\Schedules\OnShift\3daypunchrecords.csv", "/upload/3daypunchrecords.csv"


MySite.Close "EXITNOPENDING"

wscript.quit

\\Timas


This might be causing a problem. The link is to a network share that may need access permissions.


Authentication needs to be done before the file transfer, so you may need to look up scripting with 'Net Use'


ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer

Ok.  I've made a little progress.  The user account was a Domain User and there was a GP setting denying access to batch scripts.  We created a local Admin account and then found that account didn't have access to the server share and so we created the same credentialed account on the other server.  Now, the new local user can run the script successfully when task scheduler is set to: Run only when user is logged in" .  If task scheduler is set to: "Run whether user is logged on or not" , then runs the script up to this line:   MySite.Connect 

So, I'm not sure why it won't continue.  


I think I may have this working. It was a matter of configuring the CuteFtp DCOM object to run using a designated account.  I'll know for sure as a monitor today to be sure task scheduler is running the script completely

Good to hear there's progress. 


>> The user account was a Domain User and there was a GP setting denying access to batch scripts

For this we would typically add the right 'allow logon as a batch job'.

It seems to finally be working.  The problem here wasn't just a single issue.  There was a permissions issue on the share of the file that needed to be uploaded, there were GP security configurations limiting users access to running scripts from task scheduler and the main problem was needing to configure DCOM settings for CuteFtp transfer engine.  I would have never gotten to that line and been able to pinpoint that issue if I hadn't added logging to the vb script as Gerwin recommended.  Thanks to everyone here.