[英]Exception - System cannot find the file specified
I see numerous similar questions to this, but I remain stuck. 我看到许多与此类似的问题,但我仍然坚持。 I can run nltest.exe from a cmd prompt but not programmatically.
我可以从cmd提示符下运行nltest.exe,但不能以编程方式运行。
Here is the code that fails with exception "An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll" 这是失败的代码,带有异常“ 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()
So, I modified to use cmd /c as follows: 因此,我修改为使用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()
Using cmd /c, the code runs but only creates an empty file c:\\temp\\where.txt. 使用cmd / c,代码将运行,但仅创建一个空文件c:\\ temp \\ where.txt。
If I run the command manually from the Start menu (Windows 10), this runs fine and the file contains the site location. 如果我从“开始”菜单(Windows 10)手动运行命令,则此命令运行良好,并且该文件包含站点位置。
Am I making a basic error in either/both of these attempts? 我在这两种尝试中都犯了基本错误吗?
In order to use the active directory function dsgetsite, I gave up on commandline function nltest and translated the c# (using converter.telerik.com ) found at http://adcoding.com/using-dsgetsitename-in-c-sample-how-to-get-the-name-of-the-site-where-a-computer-resides/ based on netapi32.dll. 为了使用活动目录功能dsgetsite,我放弃了命令行功能nltest并翻译了http://adcoding.com/using-dsgetsitename-in-c-sample-how中找到的c#(使用converter.telerik.com ) 获取基于netapi32.dll 的计算机所在/站点的名称。
I added this line to my IMPORTS section of my vb.net code module 我将此行添加到我的vb.net代码模块的IMPORTS部分
Imports System.Runtime.InteropServices
I then added to the main Module 然后我添加到主模块
<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
And when I want to find the site name of a workstation from that workstation, I call the function GetLocation(). 当我想从该工作站查找工作站的站点名称时,我调用函数GetLocation()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.