Solved

Scheduling tasks

Posted on 2004-08-04
8
833 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now