Solved

Scheduling tasks

Posted on 2004-08-04
8
835 Views
Last Modified: 2012-05-05
Does anyone know how I can make a VB program that will create a scheduled task in windows xp?

I was originally going to just use windows' schtasks command, but I can't figure out how to use that to schedule a command with a switch '/s' at the end.
0
Comment
Question by:Crash2100
  • 4
  • 3
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 11716545
What command are you using now?  Can you post the command line?
Should be able to use schtasks from a shell...
0
 
LVL 18

Author Comment

by:Crash2100
ID: 11717654
I've tried several different ways to do this.  Currently I'm trying this with a batch file created by the program, so that I can have a record of what the command executes.  What I really don't understand is why the first batch file I created manually, works just fine, then the one created by my VB program doesn't work.  From what I can tell, they have identical code:

This batch file works:

SCHTASKS /Create /SC Once /ST 22:34:00 /TN MBABackup /s JEFF /ru Jeff /TR "E:\DOCUME~1\Jeff\Desktop\DRSTOL~1\NEWMBA~1\MBABAC~1.EXE /s" /rp

And this one doesn't:

SCHTASKS /Create /SC Once /ST 22:34:00 /TN MBABackup /s JEFF /ru Jeff /TR "E:\DOCUME~1\Jeff\Desktop\DRSTOL~1\NEWMBA~1\MBABAC~1.EXE /s" /rp

And here's the code from my VB program that compiles the line for the batch file:

strPath = "SCHTASKS /Create /SC " & "Once" & " /ST 22:34:00" & " /TN " & "MBABackup"
        strPath = strPath & " /s " & Environ("computername") & " /ru " & Environ("username")
        strPath = strPath & " /TR " & Chr(34) & GetShortPath(App.Path & "\" & App.EXEName & ".exe") & "/s" & Chr(34) & " /rp " & txtPassword
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 11717816
See the task scheduler wrapper at http://www.mvps.org/emorcillo/dotnet/shell/index.shtml
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 11717822
0
 
LVL 18

Author Comment

by:Crash2100
ID: 11718903
At first I couldn't get that VB6 code to work.  I had to re-create the VB project group, then it all worked perfictly.  Let me mess with the code in it and see if I can get it working in my program the way I want.  This looks very promising.
0
 
LVL 18

Author Comment

by:Crash2100
ID: 11722557
Using that code, is there a way I can edit the properties of the task from within my VB Program?  So I can change things like the day it runs on from my program.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 11722617
Sure. It will be something like this:

    With m_oSchedule(lstTasks.ListIndex + 1)
        .Triggers.Item(1).MonthlyDOW_DaysOfTheWeek = Saturday
        .Save
    End With
0
 
LVL 18

Author Comment

by:Crash2100
ID: 11741059
It all worked great.  Thanks!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question