如何运行“查询会话”使用vb.net? [英] How can I run "query session" using vb.net?

查看:59
本文介绍了如何运行“查询会话”使用vb.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从cmd.exe中执行查询会话获得结果,并使用VB.NET将它们存储在字符串变量中。我已经搜索了两天,但是我无法运行命令,一旦运行命令,我将尝试保存结果。

I would like to get the results from executing "query session" in the cmd.exe and Store them in a string variable using VB.NET. I have been searching for two days now and I cannot get to run the command, I will try to save the result once I get the command running.

似乎VisualStudio执行cmd.exe,但不执行C:\Windows\System32中的那个。

It seems that VisualStudio executes cmd.exe but not the one in C:\Windows\System32.

        Dim process As System.Diagnostics.Process = New System.Diagnostics.Process
    process.StartInfo.FileName = "C:\Windows\system32\cmd.exe"
    process.StartInfo.Arguments = "/K query session"
    process.StartInfo.UseShellExecute = True
    process.StartInfo.CreateNoWindow = True
    process.StartInfo.RedirectStandardOutput = False
    process.Start()
    process.WaitForExit()

返回错误:'query'不被识别为内部或外部命令,
可操作程序或批处理文件。

It returns error: 'query' is not recognized as an internal or external command, operable program or batch file.

推荐答案

这似乎是权限问题。您需要将命令的用户名和密码传递给命令

It seems to be a permission problem. You need to pass a user name and a password of an administrator user to your command

.....
process.StartInfo.UserName = "yourAdminUser"
process.StartInfo.Password = GetPassword()
.....


Public Function GetPassword() as String
     Dim ss = new SecureString()
     ss.AppendChar("p")
     ss.AppendChar("a")
     ss.AppendChar("s")
     ss.AppendChar("s")
     return ss
End Function

NB SecureString类需要一个引用 System.Security.dll 和命名空间 System.Security

N.B. SecureString class requires a reference to System.Security.dll and an import of the namespace System.Security

这篇关于如何运行“查询会话”使用vb.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆