C# WMI Win32_ScheduledJob 属性

发布于 2024-12-28 23:34:56 字数 1117 浏览 0 评论 0 原文

ConnectionOptions connOptions = new ConnectionOptions(); 
connOptions.Username = _username; 
connOptions.Password = _password; 
connOptions.Impersonation = ImpersonationLevel.Impersonate; 
connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(_server, connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_ScheduledJob");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);

ManagementBaseObject inParams = processClass.GetMethodParameters("Create"); 
inParams["Name"] = "TESTER"; 
inParams["Owner"] = "Tester";
inParams["Command"] = command;
inParams["StartTime"] = "********171000.000000-300"; 

我正在尝试连接到远程系统来创建计划任务。我可以创建计划任务,但它是使用用户 SYSTEM 创建的。我希望它在我的用户下创建。我尝试使用“所有者”和“名称”等属性,例如:

inParams["Owner"] = ;
inParams["Name"] = ;

但它们抛出 ManagementException,“未找到”。有谁知道我该怎么做,或者我在这里做的事情可能有什么问题......

谢谢

ConnectionOptions connOptions = new ConnectionOptions(); 
connOptions.Username = _username; 
connOptions.Password = _password; 
connOptions.Impersonation = ImpersonationLevel.Impersonate; 
connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(_server, connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_ScheduledJob");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);

ManagementBaseObject inParams = processClass.GetMethodParameters("Create"); 
inParams["Name"] = "TESTER"; 
inParams["Owner"] = "Tester";
inParams["Command"] = command;
inParams["StartTime"] = "********171000.000000-300"; 

I'm tyring to connect to a remote system to create a scheduled task. I can create the scheduled tasks, but its being created with user - SYSTEM. I want it to be created under my user. I tried using the properties like 'Owner' and 'Name' eg:

inParams["Owner"] = ;
inParams["Name"] = ;

But they throw a ManagementException, "Not Found". Does anyone know how I can do this, or what might be wrong that I'm doing here...

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

佼人 2025-01-04 23:34:56

使用 < 创建计划作业code>Win32_ScheduledJob WMI类相当于使用AT命令创建作业。 AT 服务通常在本地\系统帐户或网络服务帐户下运行。因此,当您使用此类时,您的职位将使用这些帐户之一创建,有关此主题的更多信息,您可以查看 备注部分/en-us/library/windows/desktop/aa394399%28v=vs.85%29.aspx" rel="nofollow">MSDN 文档

Creating a scheduled job with the Win32_ScheduledJob WMI class is equivalent to create job using the AT command. The AT service normally run under the Local\System account or the NetworkService Account. so when you uses this class your jobs are created using one of these accounts for more info about this topic you can check the remarks part of the MSDN documentation.

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