Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#获取当前登录用户及时登录.net表单应用程序_C#_.net - Fatal编程技术网

C#获取当前登录用户及时登录.net表单应用程序

C#获取当前登录用户及时登录.net表单应用程序,c#,.net,C#,.net,我需要获取当前用户的Windows登录时间 我正在使用Windows.NET窗体。我发现什么都不管用。我最终得到的时间是最后一次登录时间,而不是最新登录时间,这毫无意义。在我看来,微软破坏了这个功能,但我知道什么呢 我已经尝试了所有的方法,但仍然不是正确的时间。我开始了一个新的线程,以不复活一个死线程,但我这样做可能是错误的。如果是这样的话,很抱歉。我还不能发表评论,所以我不得不提出这个问题作为答案 您是否尝试过以此处建议的方式更明智地运行该工具 在这里,您可以捕获输出并解析它 pri

我需要获取当前用户的Windows登录时间

我正在使用Windows.NET窗体。我发现什么都不管用。我最终得到的时间是最后一次登录时间,而不是最新登录时间,这毫无意义。在我看来,微软破坏了这个功能,但我知道什么呢


我已经尝试了所有的方法,但仍然不是正确的时间。我开始了一个新的线程,以不复活一个死线程,但我这样做可能是错误的。如果是这样的话,很抱歉。

我还不能发表评论,所以我不得不提出这个问题作为答案

您是否尝试过以此处建议的方式更明智地运行该工具

在这里,您可以捕获输出并解析它

    private List<string> RunCommand(string exeName, string args, string folder)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo(exeName);

        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.CreateNoWindow = true;
        startInfo.UseShellExecute = false;
        startInfo.WorkingDirectory = folder;
        startInfo.RedirectStandardInput = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.Arguments = args;

        Process process = new Process();
        process.StartInfo = startInfo;
        process.Start();

        var results = new List<string>();
        while (!process.StandardOutput.EndOfStream)
        {
            results.Add(process.StandardOutput.ReadLine());
        }

        return results;
    }
private List RunCommand(字符串exeName、字符串args、字符串文件夹)
{
ProcessStartInfo-startInfo=新的ProcessStartInfo(exeName);
startInfo.WindowStyle=ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow=true;
startInfo.UseShellExecute=false;
startInfo.WorkingDirectory=文件夹;
startInfo.RedirectStandardInput=true;
startInfo.RedirectStandardOutput=true;
startInfo.Arguments=args;
流程=新流程();
process.StartInfo=StartInfo;
process.Start();
var results=新列表();
而(!process.StandardOutput.EndOfStream)
{
添加(process.StandardOutput.ReadLine());
}
返回结果;
}
上面是我使用的代码


抱歉格式化,因为我正在我的手机上做这件事

我还不能评论,所以我不得不提出这一点作为回答

您是否尝试过以此处建议的方式更明智地运行该工具

在这里,您可以捕获输出并解析它

    private List<string> RunCommand(string exeName, string args, string folder)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo(exeName);

        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.CreateNoWindow = true;
        startInfo.UseShellExecute = false;
        startInfo.WorkingDirectory = folder;
        startInfo.RedirectStandardInput = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.Arguments = args;

        Process process = new Process();
        process.StartInfo = startInfo;
        process.Start();

        var results = new List<string>();
        while (!process.StandardOutput.EndOfStream)
        {
            results.Add(process.StandardOutput.ReadLine());
        }

        return results;
    }
private List RunCommand(字符串exeName、字符串args、字符串文件夹)
{
ProcessStartInfo-startInfo=新的ProcessStartInfo(exeName);
startInfo.WindowStyle=ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow=true;
startInfo.UseShellExecute=false;
startInfo.WorkingDirectory=文件夹;
startInfo.RedirectStandardInput=true;
startInfo.RedirectStandardOutput=true;
startInfo.Arguments=args;
流程=新流程();
process.StartInfo=StartInfo;
process.Start();
var results=新列表();
而(!process.StandardOutput.EndOfStream)
{
添加(process.StandardOutput.ReadLine());
}
返回结果;
}
上面是我使用的代码

抱歉格式化,因为我正在手机上执行此操作

当前用户是

  System.Security.Principal.WindowsIdentity.GetCurrent()
但是没有存储登录时间,您的方法听起来很奇怪

如果有人在Windows启动5天后启动了您的应用程序,您想让该用户从Windows注销,因为他已在45分钟前登录?我希望我误解了这一点

您只需跟踪应用程序运行的时间。这是一个单用户应用程序,如果您愿意,可以随时关闭应用程序。

当前用户是

  System.Security.Principal.WindowsIdentity.GetCurrent()
但是没有存储登录时间,您的方法听起来很奇怪

如果有人在Windows启动5天后启动了您的应用程序,您想让该用户从Windows注销,因为他已在45分钟前登录?我希望我误解了这一点


您只需跟踪应用程序运行的时间。这是一个单用户应用程序,您可以随时关闭应用程序。

是的,您可以谈论windows登录,有人登录windows,5天后启动应用程序。您不会谈论web应用程序,首先启动应用程序,然后登录。首先登录,然后启动应用程序。您将登录Windows和登录单个应用程序混为一谈。您不能在登录到windows时启动任何操作,因为您的WinForms应用程序没有运行。@xCONFLiCTiONx您的问题中没有“服务”一词。Windows服务是正确的方法,服务在用户登录之前运行。但是服务从来都不是WinForms应用程序,它没有用户界面。据我所知,您想使用Microsoft Word这样的用户应用程序从Windows注销-这太令人困惑了。Windows登录始终是用户做的第一件事-启动应用程序总是比较晚,无休止的时间,可能是几天后。是的,您谈论的是Windows登录,有人登录Windows,5天后启动应用程序。您不会谈论web应用程序,首先启动应用程序,然后登录。首先登录,然后启动应用程序。您将登录Windows和登录单个应用程序混为一谈。您不能在登录到windows时启动任何操作,因为您的WinForms应用程序没有运行。@xCONFLiCTiONx您的问题中没有“服务”一词。Windows服务是正确的方法,服务在用户登录之前运行。但是服务从来都不是WinForms应用程序,它没有用户界面。据我所知,您想使用Microsoft Word这样的用户应用程序从Windows注销-这太令人困惑了。Windows登录始终是用户做的第一件事-启动应用程序总是比较晚,时间总是无限的晚,可能是几天之后。