每次Windows启动时安排任务的vbs代码是什么?

发布于 2024-09-01 23:50:10 字数 923 浏览 6 评论 0原文

我想知道如何编写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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷清清 2024-09-08 23:50:10

将应用程序的快捷方式放在启动文件夹中不是更容易吗?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文