Solved

Scheduling tasks

Posted on 2004-08-04
8
834 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 69

Expert Comment

by:Éric Moreau
ID: 11717816
See the task scheduler wrapper at http://www.mvps.org/emorcillo/dotnet/shell/index.shtml
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 11717822
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 59
MS Access - Capture pressed key onclick 4 28
Visual Studio 2005 text editor 10 35
Excel Automation VBA 19 25
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now