Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Launchapp.vbs to run on battery power

Avatar of beapit
beapit asked on
ProgrammingVB ScriptWindows 7
6 Comments1 Solution1768 ViewsLast Modified:
I'm using the lauchapp.vbs script to run a login script in the user context for Windows 7 machines. I ran into a problem with it when a laptop is on battery power. I've discovered that the scheduled task that the launchapp.vbs script creates has the check boxes checked for "Start the task only if the computer is on AC Power" and the sub category "Stop if the computer switches to battery power" under the Conditions tab of the task.

Just hoping someone knows how to create a scheduled task without those two options checked. I've attached the relevant part of the script.
Sub LaunchApp

  Dim objTaskService
  Dim strTaskName, rootFolder, taskDefinition, triggers, trigger, Action

  'Create the TaskService object
  Set objTaskService = CreateObject("Schedule.Service")
  Call objTaskService.Connect()
  strTaskName = "Launch App As Interactive User"

  'Get a folder to create a task definition in
  Set rootFolder = objTaskService.GetFolder("\")

  'Delete the task if already present
  On Error Resume Next
  Call rootFolder.DeleteTask(strTaskName, 0)

  'Create the new task
  Set taskDefinition = objTaskService.NewTask(0)

  'Create a registration trigger
  Set triggers = taskDefinition.Triggers
  Set trigger = triggers.Create(TriggerTypeRegistration)

  'Create the action for the task to execute
  Set Action = taskDefinition.Actions.Create(ActionTypeExecutable)
  Action.Path = strKIX
  Action.Arguments = strScriptName
  Action.WorkingDirectory = strWorkingDirectory

  'Register (create) the task
  call rootFolder.RegisterTaskDefinition(strTaskName, taskDefinition, FlagTaskCreate,,, LogonTypeInteractive)

  Set objTaskService = nothing

End Sub
Avatar of Lee Osborne
Lee OsborneFlag of United Kingdom of Great Britain and Northern Ireland imageSenior Infrastructure Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers