• 远程抓取win7 的用户登录时间


      protected void Page_Load(object sender, EventArgs e)
            {
                InvokeSystemPS("query user /server:192.168.1.222");
                //test();
            }
    
            public static void InvokeSystemPS(string cmd)
            {
                List<string> ps = new List<string>();
                ps.Add("Set-ExecutionPolicy RemoteSigned");
                ps.Add("Set-ExecutionPolicy -ExecutionPolicy Unrestricted");
                ps.Add("& " + cmd);
                Runspace runspace = RunspaceFactory.CreateRunspace();
                runspace.Open();
                Pipeline pipeline = runspace.CreatePipeline();
                foreach (var scr in ps)
                {
                    pipeline.Commands.AddScript(scr);
                }
                Collection<PSObject> psObjects= pipeline.Invoke();//Execute the ps script
                PSObject[] abc = psObjects.ToArray();
                string [] ss=abc[1].BaseObject.ToString().Split(' ');
                runspace.Close();
            }
      public string GetFreeTime(string IPAddress)
            {
                string cmd = "query user /server:" + IPAddress;
                List<string> ps = new List<string>();
                ps.Add("Set-ExecutionPolicy RemoteSigned");
                ps.Add("Set-ExecutionPolicy -ExecutionPolicy Unrestricted");
                ps.Add("& " + cmd);
                Runspace runspace = RunspaceFactory.CreateRunspace();
                runspace.Open();
                Pipeline pipeline = runspace.CreatePipeline();
                foreach (var scr in ps)
                {
                    pipeline.Commands.AddScript(scr);
                }
                Collection<PSObject> psObjects = pipeline.Invoke();//Execute the ps script
                runspace.Close();
    
                string[] arr = psObjects[1].BaseObject.ToString().Split(' ');
    
                StringBuilder str = new StringBuilder();
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] != "")
                    {
                        str.Append(arr[i] + ",");
                    }
                }
                string[] tmp = str.ToString().Split(',');
    
                return tmp[4];
    
            }

     在win7 中会报错,需要做如下修改

    Solution

    On the machine that you cannot message to:

    Use regedit to navigate to: HKLMSYSTEMCurrentControlSetControlTerminal Server

    Then change the following value:

    Name : AllowRemoteRPC

    Type : REG_DWORD

    Value : 1

    Reboot. Now it should work.

    无法将“query”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后重试。

    出现这个错误是这个方法的需要在IIS中运行,不能再本地调试,而且应用程序池的账号需要在被抓去机器的管理员组中(最好)

  • 相关阅读:
    不要自称为程序员(转)
    JSON数据格式
    netstat
    win7,ubuntu双系统——重装win7后如何恢复ubuntu引导
    js中setInterval与setTimeout用法
    使用CSS中margin和padding的基础和注意事项
    HTTP协议与HTML表单(再谈GET与POST的区别)
    (转)JAVA AJAX教程第四章—AJAX和MVC的简单结合
    (转)JAVA AJAX教程第三章—AJAX详细讲解
    制作SD卡启动自己编译的uboot.bin
  • 原文地址:https://www.cnblogs.com/ahghy/p/3503403.html
Copyright © 2020-2023  润新知