What's the vbs code to schedule a task every time Windows starts up?
Posted
by Wing C. Chen
on Stack Overflow
See other posts from Stack Overflow
or by Wing C. Chen
Published on 2010-05-17T08:47:56Z
Indexed on
2010/05/17
8:50 UTC
Read the original article
Hit count: 267
I would like to know how to write up the vbs code to schedule a windows task to start a .exe program every time the Windows starts up.
I found the following code online:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
("Notepad.exe", "********123000.000000-420", _
True , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated
But it only tells me how to schedule the task every on some specific days and hours.
I thought of creating a windows service. However the following is the story why I must look for an alternative to it.
I created a windows service with RunAsService for my java program wrapped with Janel. The Service worked fine when I first installed and started it. However, after restarting my windows xp, a dialog window poped out saying that my janel generated .exe file has crashed, with my RunAsService service kept on going. The service worked fine when I terminated the service and restarted it again manually. Nevertheless, the same crash happens over and over again every time I restart my Windows.
© Stack Overflow or respective owner