views:

81

answers:

1

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.

+1  A: 

Would it not be easier just to put a shortcut to your application in the Startup folder???

David Relihan
well.. the thing is that I have to automate it. Does every windows machine have startup folder, including the server versions?
Winston Chen
Yep - Assuming by your reply that your in a networked environment i.e. if this is a solution for a business then you should use Windows GPO so that when every user logs on it would add it to Startup. http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/ That's a fairly standard way of doing it
David Relihan
Thanks. This means I am able to write a batch/script to put the shortcut into the startup folder as well when I encounter a machine that's outside of my domain. By the way, why did you pass me an iPhone link?
Winston Chen
My bad!!! Multi-tasking!!! This is what I meant!!! http://en.wikipedia.org/wiki/Group_Policy
David Relihan