远程抓取win7 的用户登录时间
2014-01-03 11:42
232 查看
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: HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server
Then change the following value:
Name : AllowRemoteRPC
Type : REG_DWORD
Value : 1
Reboot. Now it should work.
无法将“query”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后重试。
出现这个错误是这个方法的需要在IIS中运行,不能再本地调试,而且应用程序池的账号需要在被抓去机器的管理员组中(最好)
相关文章推荐
- [转]win7 多用户远程登录
- Win7多用户同时远程登录
- 开启win7多用户登录远程桌面3389
- 开启Win7多用户登录远程桌面
- win7 多用户远程登录
- 如何设置win7多用户远程控制登录
- windows Win7如何设置多用户同时远程登录
- win7 多用户远程登录
- win7凭据管理、win7多用户远程登录、主机头设置、nuget.org无法访问
- Win7系统查看最后登录时间的方法 win7电脑记录用户登录时间的查看
- win7实现多用户同时远程登录到PC端
- win7 多用户远程登录
- 远程桌面用户交互式登录
- SQL2005怎样远程连接以及使用sa用户登录
- win7新建标准用户不能登录,总注销,有办法吗?
- 记录远程用户登录日志
- 防止远程密码拦截破译,ssh验证和普通用户登录
- centos7 创建普通用户,添加sudo权限,禁止root远程登录和公钥登录脚本
- win7、8 cmd开启3389,并添加用户至远程桌面组
- win7 搭建ftp 设置用户权限 远程访问设置