例外-系统找不到指定的文件

马特·D

我看到许多与此类似的问题,但我仍然坚持。我可以从cmd提示符下运行nltest.exe,但不能以编程方式运行。

这是失败的代码,带有异常“ System.dll中发生类型'System.ComponentModel.Win32Exception'的未处理的异常”

Dim pz As New Process()
pz.StartInfo.FileName = "nltest.exe"
pz.StartInfo.Arguments = " /dsgetsite > c:\temp\where.txt"
pz.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
pz.Start()

因此,我修改为使用cmd / c,如下所示:

    Dim pz As New Process()
    pz.StartInfo.FileName = "cmd"
    pz.StartInfo.Arguments = " /c nltest /dsgetsite > c:\temp\where.txt"
    '       pz.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
    pz.Start()
    pz.WaitForExit()

使用cmd / c,代码将运行,但仅创建一个空文件c:\ temp \ where.txt。
如果我从“开始”菜单(Windows 10)手动运行命令,则此命令运行良好,并且该文件包含站点位置。

我在这两种尝试中都犯了基本错误吗?

马特·D

为了使用活动目录功能dsgetsite,我放弃了命令行功能nltest并翻译了http://adcoding.com/using-dsgetsitename-in-c-sample-how中找到的c#(使用converter.telerik.com获取基于netapi32.dll的计算机所在/站点的名称。

我将此行添加到我的vb.net代码模块的IMPORTS部分

Imports System.Runtime.InteropServices

然后我添加到主模块

  <DllImport("netapi32.dll", CharSet:=CharSet.Auto)>
  Public Function DsGetSiteName(ByVal ComputerName As String, <Out> ByRef SiteName As IntPtr) As Integer
  End Function

  Public Function GetLocation()
       Dim pSiteInfo As IntPtr
       Dim sSiteName As String = ""
        If DsGetSiteName(String.Empty, pSiteInfo) = 0 Then
              sSiteName = Marshal.PtrToStringAuto(pSiteInfo)
        End If
       Return sSiteName 
  End Function

当我想从该工作站查找工作站的站点名称时,我调用函数GetLocation()。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章