Task Scheduler

information   Information
This Tutorial will show you how to create a Scheduled Logon Task.



Note   Note
You should, ideally, perform this Tutorial from within an account with administrative privileges.



Section ONE

Open Task Scheduler.

Click Create Task...

This will open the following dialogue panel, with the General tab selected. Give the task a suitable Name and Description. Also, change the other settings (if different) to match those shown below.

Capture.png

Click the Triggers tab and then click New...

Enter the settings as shown below. If you wish, you can set a start date (as shown below), but if you don't want (or need) to, just uncheck the Activate: option. Click OK.

Note   Note
You can set a start date and/or end date for the task if you so choose. Just check the appropriate option(s) shown below (Activate: for the start date and/or Expires: for the end date). I suggest that you set the time(s) to 00:00:00 (midnight), and that you check the option(s) Synchronize across time zones.



Capture1.PNGCapture2.PNG

Click the Actions tab and then click New...

Enter the settings as shown below (note that you can change the message to whatever you want it to display) and click OK.

Capture3.PNGCapture4.PNG

Note   Note
This only provides for a simple text message to be displayed for each user, with each user having the same message. If that is all you require, skip over the next section, but for more flexibility, see below.



Section TWO

Instead of choosing Display a message for the Action:, select Start a program instead, as shown below.

Capture5.PNG Capture6.PNG

Note   Note
The following blocks of code are what actually carry out the action when the task is triggered. In all cases, replace the data in BLUE with the actual UserName(s) and the data in <GREEN> with the routine to be executed. For the third block of code, you can choose to use the same routine or a different routine. With the last block of code, a different routine should be used for each user.


With this script, the routine is executed only if the current user IS the user referenced to by MyStr.
Code:
Dim StrUser, MyStr
Set wshNetwork = CreateObject("WScript.Network")
Set wshShell = CreateObject("WScript.Shell")
StrUser = wshNetwork.Username
MyStr = "[COLOR=#0000ff]account[/COLOR]"
If StrComp(StrUser, MyStr, 1) = 0 Then
wshShell.Run ("[COLOR=#008000]<Routine, including path>[/COLOR]")
End If

In this script, the routine is executed if the current user IS NOT the user referenced to by MyStr.
Code:
Dim StrUser, MyStr
Set wshNetwork = CreateObject("WScript.Network")
Set wshShell = CreateObject("WScript.Shell")
StrUser = wshNetwork.Username
MyStr = "[COLOR=#0000ff]account[/COLOR]"
If StrComp(StrUser, MyStr, 1) <> 0 Then
wshShell.Run ("[COLOR=#008000]<Routine, including path>[/COLOR]")
End If

With this script, a routine is executed if the current user IS one of the users referenced to by MyStr1 or MyStr2. Note that the routine can be different for each user, and that you may need to adapt the code to fit in with the accounts on your system. For this example, account1 will execute Routine1, account2 will execute Routine2, and account3 will not execute either routine.
Code:
Dim StrUser, MyStr1, MyStr2, MyStr3
Set wshNetwork = CreateObject("WScript.Network")
Set wshShell = CreateObject("WScript.Shell")
StrUser = wshNetwork.Username
MyStr1 = "[COLOR=#0000ff]account1[/COLOR]"
MyStr2 = "[COLOR=#0000ff]account2[/COLOR]"
MyStr3 = "[COLOR=#0000ff]account3[/COLOR]"
If StrComp(StrUser, MyStr1, 1) = 0 Then
wshShell.Run ("[COLOR=#008000]<Routine1, including path>[/COLOR]")
ElseIf StrComp(StrUser, MyStr2, 1) = 0 Then
wshShell.Run ("[COLOR=#008000]<Routine2, including path>[/COLOR]")
End If

With this script, Routine1 is executed if the current user IS the user referenced to by MyStr. All other users execute Routine2.
Code:
Dim StrUser, MyStr
Set wshNetwork = CreateObject("WScript.Network")
Set wshShell = CreateObject("WScript.Shell")
StrUser = wshNetwork.Username
MyStr = "[COLOR=#0000ff]account[/COLOR]"
If StrComp(StrUser, MyStr, 1) = 0 Then
wshShell.Run ("[COLOR=#008000]<Routine1, including path>[/COLOR]")
Else
wshShell.Run ("[COLOR=#008000]<Routine2, including path>[/COLOR]")
End If

Note   Note
If you want to display a simple message, or messages, simply replace wshShell.Run ("<Routine, including path>") with MsgBox "<Message>", vbSystemModal (change <Message> to whatever you want to display).


All of the above blocks of code are vbscript files, and should be created using Notepad, saving with a .vbs extension. For the purposes of this Tutorial, the file is saved in the root of the C:\ drive as logonscript.vbs, although you can change the name and location if you wish. Just make sure that the name and location are updated above to reflect any changes.

Since we don't need to change any further settings, click on OK to finish creating the task and close the Task Scheduler.

Section THREE

Triggering a task at logon Logon tasks can be set for any user or a specific user or user group. If the user whose logon has triggered the task is not the user in whose security context the task is running, the task will be noninteractive - in other words, essentially invisible. (The user can note the presence of the task - and terminate it - by running Windows Task Manager, going to the Processes tab, clicking Show Processes From All Users, and answering the UAC prompt.)

To overcome this limitation, follow the steps below.

Open Task Scheduler, click Task Scheduler Library to bring up the list of tasks, highlight the one you've just created and click Properties to bring up the following dialogue.

Capture7.PNG

We need to change the information under When running this task, use the following user account:, so click on Change User or Group...

Capture8.PNG

Click Object Types... and change the settings so that only Groups is selected, as shown below. (Note that this is optional, it only narrows down the list you have to look through in the next step. If you wish to omit this step, click on Advanced instead and move on to the next step.)

Capture9.PNG

Click OK.

Capture10.PNG

Click Advanced... and then click Find Now. This will bring up a list of items that match the search criteria. Scroll through and highlight Users as shown below.

Capture11.PNG

Click OK.

Capture12.PNG

Click OK. If the next dialogue comes up as shown below, you have been successful. If not, review the above steps to ensure that you haven't missed anything.

Capture13.PNG

Click OK to save the task, and close the Task Scheduler. Regardless of the user logging on, this task will execute and s/he will see the results of it on their screen in their account.

warning   Warning
You need to ensure that all users can freely execute the vbscript files created in the implementation of this Tutorial. Failure to do so will result in the code not being able to be executed in one or more accounts. No error message will be given, and, in tasks where a sequential set of actions is to be performed, only those actions preceding will be executed.

 

Attachments

  • Task_Scheduler.png
    Task_Scheduler.png
    23 KB · Views: 318
Last edited by a moderator:
Great tutorial, Guy! I'll be tipping the scales. :)
 

My Computer

System One

  • OS
    Windows 7 Ultimate x64/Windows 8 Consumer Preview x64/Ubuntu 11.04
    System Manufacturer/Model
    Custom Build
    CPU
    Intel Pentium Dual Core E6700 3.2GHz
    Motherboard
    ASUS P5G41T-M LX
    Memory
    Strontium 8192MB DDR3 1333Mhz
    Graphics Card(s)
    msi GeForce N560GTX-M2D1GD5 1GB
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    CHIMEI CMV 221D 22"
    Screen Resolution
    1680x1050
    Hard Drives
    Seagate 3.5'' 2TB HDD/WD Elements External 1TB HDD
    PSU
    SHAW Viper-1500w Gaming PSU
    Case
    Black eMaxx ATX Mini Tower Case
    Keyboard
    Microsoft Wireless Keyboard 1000
    Mouse
    Microsoft Wireless Optical Mouse 2000
    Internet Speed
    100GB @ 4.76Mbps
Thanks, Dwarf!!!! You tried to help me, but I;m too much of a doofus to follow you after this point:

"Section TWO

Instead of choosing Display a message for the Action:, select Start a program instead, as shown below."

Your sample program was sumpn about "logon....." What is that, and how would I go about selecting my target task from a long list of items that are unfamiliar and udecipherable to me? I want to schedule a Norton scan in the wee hours, but I dont see that option listed in my elementary English. And I fear getting into the register like poison!
 

My Computer

System One

  • OS
    windows 8.1
    Computer type
    Laptop
    System Manufacturer/Model
    hp envy
    Browser
    IE, FIREFOX
    Antivirus
    norton
Back
Top