小编All*_*ino的帖子

尝试在 Powershell v1 中嵌入 C# 代码

这是我第一次发帖提问。我是 csharp 和 powershell 的新手。如果我的英语一点都不好,请多多包涵。我一直在尝试将我的 csharp 代码转换为 powershell,但没有成功。我试图研究有关 powershell 的文档并尝试每一个,不幸的是,对我来说没有任何作用。我的 csharp 代码在 Visual Studio 2010 中工作,但我无法在 Powershell 中嵌入和工作。下面的代码简单地捕获任务管理器的 PID 并将其写入带有时间和日期戳的记事本。任何帮助将不胜感激。

我的 csharp 代码是:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GET_TASK
{
    class Program
    {
        static void Main(string[] args)
        {

            var processList = Process.GetProcessesByName("taskmgr");                

            foreach (var process in processList)
            {

                string myPath = "C:/powershell/GET_TASK"; //change data path as needed

                FileStream logfile;
                //log program process
                logfile = new FileStream(myPath + "/logfile.txt", FileMode.Append, FileAccess.Write); 

                TextWriter oldLog …
Run Code Online (Sandbox Code Playgroud)

.net c# powershell

5
推荐指数
1
解决办法
1541
查看次数

标签 统计

.net ×1

c# ×1

powershell ×1