每次Windows启动时安排任务的vbs代码是什么?
我想知道如何编写vbs代码来安排Windows任务在每次Windows启动时启动.exe程序。
我在网上找到了以下代码:
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
但它只告诉我如何在每个特定的日期和时间安排任务。
我想到创建一个Windows服务。然而,以下是为什么我必须寻找替代方案的故事。
我使用 RunAsService 为我的 java 程序创建了一个 Windows 服务,并用 贾内尔。当我第一次安装并启动该服务时,该服务运行良好。然而,重新启动我的 Windows XP 后,弹出一个对话框窗口,说我的 janel 生成的 .exe 文件已崩溃,而我的 RunAsService 服务继续运行。当我终止服务并手动重新启动它时,该服务工作正常。然而,每次我重新启动 Windows 时,同样的崩溃都会一遍又一遍地发生。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将应用程序的快捷方式放在启动文件夹中不是更容易吗?
Would it not be easier just to put a shortcut to your application in the Startup folder???