【发布时间】:2017-11-01 11:50:00
【问题描述】:
我正在创建一个 VB Windows 表单,它检索在 AD 中注册的计算机列表,然后检查每台计算机是否存在应用程序(查找 .exe)。我在连接 .exe 的路径时遇到问题我收到错误“从字符串到长的对话无效”
我该如何解决这个问题?
Private Sub CheckButton_Click(sender As Object, e As EventArgs) Handles CheckButton.Click
Dim PCsource As String = "C:\FilePath\adComputers.txt"
Dim FilepathX64 As String = "\C$\Program Files (x86)\FilePath\Some.exe"
Dim FilepathX86 As String = "\C$\Program Files\FilePath\Some.exe"
Dim Check As String
Dim Install As System.IO.StreamWriter
Dim Installed As System.IO.StreamWriter
If System.IO.File.Exists(PCsource) = True Then
Dim Computer As New System.IO.StreamReader(PCsource)
Do While Computer.Peek() <> -1
Check = Computer.ReadLine()
If System.IO.File.Exists("\\" & Check & FilepathX64 Or "\\" & Check & FilepathX86) = True Then
Installed = My.Computer.FileSystem.OpenTextFileWriter("C:\FilePath\Installed.txt", True)
Installed.WriteLine("Sophos is installed on " & Check, True)
Installed.Close()
Else
Install = My.Computer.FileSystem.OpenTextFileWriter("C:\FilePath\Install.txt", True)
Install.WriteLine(Check, True)
Install.Close()
End If
Loop
Else
FailSound.Play()
MessageBox.Show("The Domain Computer List is missing")
Exit Sub
End If
End Sub
【问题讨论】:
-
请添加错误消息的确切文本,其中还应包括有关哪条线路失败的信息。
-
你真的不应该像在编译程序中那样硬编码值。你有什么理由不能使用像 PowerShell 这样非常适合这类事情的脚本语言?
-
您绝对应该探索 powershell 选项。它正是为这样的东西而制作的。
-
一个字符串和一个长在一个酒吧...
-
错误:从字符串“\\COMPUTERNAME\C$\Program Fil”到类型“Long”的转换无效
标签: vb.net file active-directory