C# - ScheduledTasks 类 - 如何指定 localhost?

标签 c# .net windows

在尝试提取计划任务列表时,我在定义本地计算机时遇到问题。

“localhost”似乎不起作用,我如何定义当前/本地计算机

private void testing_Click(object sender, EventArgs e)
{
    // Get a ScheduledTasks object for the computer named "DALLAS"
    ScheduledTasks st = new ScheduledTasks(@"localhost");

    // Get an array of all the task names
    string[] taskNames = st.GetTaskNames();

    // Open each task, write a descriptive string to the console
    foreach (string name in taskNames)
    {
        Task t = st.OpenTask(name);
        MessageBox.Show("  " + t.ToString());
        t.Close();
    }

    // Dispose the ScheduledTasks object to release COM resources.
    st.Dispose();  
}

最佳答案

根据文档,计算机名称需要是 UNC 名称:

ScheduledTasks Constructor (String)

因此,以下操作应该有效:

string machineName = (@"\\" + System.Environment.MachineName);

ScheduledTasks st = new ScheduledTasks(machineName);

关于C# - ScheduledTasks 类 - 如何指定 localhost?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6424979/

相关文章:

c# - Azure HTTP 函数无法发布

c# - Lync ContactList WPF 控制热键/快捷键从 WebBrowser 窃取按键

c# - 并发多线程读取访问 - 这会导致任何问题吗?

Windows 批处理文件无法定位文件

c# - 需要帮助来查找我正在尝试做的具体事情的名称

c# - InterpolationMode HighQualityBicubic 在调整大小后的图像边缘引入伪像

.net - 如何替换.net中最后一次出现的字符

.net - 如何知道 .fsx 脚本是由 .NETCore/.NET5 还是由遗留框架运行的?

c# - 动态关键字问题

php - 如何在 php 中打开 ssrs rdl 文件