beapit
asked on
Launchapp.vbs to run on battery power
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.
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)
Err.Clear
'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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No problem.
I 'think' you might set it with Action.StopIfGoingOnBatter ies = False
I'm not 100% on that, and unless somebody can confirm in the meantime, I'll get back to you. Otherwise, give it a try!
Lee
I 'think' you might set it with Action.StopIfGoingOnBatter
I'm not 100% on that, and unless somebody can confirm in the meantime, I'll get back to you. Otherwise, give it a try!
Lee
ASKER
I tried writing it several different ways and even used an example from http://rwandering.net/2008/02/28/unprivileged-tasks-in-windows-6-with-vbs/ and nothing worked.
Then I tried just putting it in like this and it worked! Thanks for your help. Working code is attached.
taskDefinition.Settings.Di sallowStar tIfOnBatte ries = false
taskDefinition.Settings.St opIfGoingO nBatteries = false
Then I tried just putting it in like this and it worked! Thanks for your help. Working code is attached.
taskDefinition.Settings.Di
taskDefinition.Settings.St
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 User0"
'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)
Err.Clear
'Create the new task
Set taskDefinition = objTaskService.NewTask(0)
taskDefinition.Settings.DisallowStartIfOnBatteries = false
taskDefinition.Settings.StopIfGoingOnBatteries = false
'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
ASKER
He pointed me in the right direction but I had to dig to find what I actually needed to do.
Excellent, glad you found the final solution!
Lee
Lee
ASKER
E.g.
objTaskService.StopIfGoing
objTaskService.DisallowSta
Sorry, I'm not very knowledgeable with VBScript.
Thanks
Kevin