希望你的渊博知识的基础可以帮助在这里,文件搜索在PC名VB6
即时通讯寻求建立一个搜索和开放代码,
我要搜索的计算机名(有位实现)并使用该名称搜索文件夹中的文本文件。该文件将包含一行数据,我想用它来配置我的系统注销的页面,如果文件不存在,我想打开一个名为default的文件并使用其中的数据行。 即。即时通讯卡上的位是能够检查文件夹的扩展名将相同但名称可以从PC更改为PC的文件。 原因是我需要验证和测试编程,如果我更改代码内的注销页面数据,每次需要对其进行更改时都需要对其进行测试。通过这种方式更新每个带有合适的注销数据的pc命名的文本文件列表,这些都是需要更改的。
有足够的资源为VB.NEt努力寻找VB6的东西。
PS。在这非常绿色。
感谢 审查附带的代码,如果任何人有足够的时间,
再次感谢
Type Point_Type
x As Long
y As Long
End Type
'Allows user to set logout duration
'Logout Duration = timer interval x 19
'Change timer interval or max LogoutCheckCounter to change duration
Dim LogoutCheckCounter As Integer
Declare Function GetCursorPos Lib "user32.dll" (lpPoint As Point_Type) As
Long
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Sub InacLogOut()
On Error GoTo Err_
Dim CheckUser As String
Dim coord As Point_Type
Dim retval As Long
Dim xPos As Long
Dim yPos As Long
Dim line As Integer
Dim page As integer
Dim LogoutTime As String
Dim LogoutPage As String
Dim MyComputerName As String
Static xOldPos As Long
'get current cursor position
retval = GetCursorPos(coord)
xPos = coord.x
yPos = coord.y
'code executes every 30 seconds
'If mouse is not moved the old position nwill equal t r log in default user
If xOldPos = xPos Then
'get the current user
CheckUser = System.LoginUserName
If CheckUser = "NOBODY" Then
'User is already logged out, exit sub without action
Exit Sub
Else
'get logout time
line = FreeFile
If Dir("C:\LogoutTime.txt") <>"" Then
Open "C:\LogoutTime.txt" For Input As line
Line Input #line, LogoutTime
MsgBox (LogoutTime)
Close File
Else
LogoutTime = 10
End if
' get logout page
MyComputerName = fOSMachineName
Dim FiletoOpen as string
FiletoOpen = "C:\" & MyComputerName & ".txt"
If Dir(FiletoOpen) <>"" Then
Open "FiletoOpen" For Input As page
Line Input #page, LogoutPage
MsgBox (LogoutPage)
Close File
Else
LogoutPage = MainPage
End if
'code executes every 30 seconds, LogoutCheckCounter used to set the
logout interval
If LogoutCheckCounter > LogoutTime Then
' code to kill report tool if open
Shell "taskkill.exe /f /t /im ReportGenerator.exe"
msgbox (Kill task)
User.ReplaceCentralFrame LogoutPage
System.FixLogin "NOBODY", ""
Else
LogoutCheckCounter = LogoutCheckCounter + 1
End If
End If
Else
'mouse has been moved, reset LogoutCheckCounter
LogoutCheckCounter = 0
End If
'xOldPos will initially be zero the first time the code runs
xOldPos = xPos
Err_:
End Sub
'-----------------------------------------------
Function fOSMachineName() As String
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function
'---------------------------------------------------`
你也要打个咖啡吗?你在问一些不可能的事情。 –
没有什么是不可能的;只是很难。我有读取PC名称的代码并操作包含以PC命名的文本文件的文件夹。我只需要一种方法来加入找到的文件名(PC名称)和已知的扩展名。例如,在PC-001001上,我使用PC名称在C:\ LogoutCode \中有一个文件。 PC001001.txt我只需要一种方法来加入字符串的路径......“C:\ LogoutCode \”&&“PC001001.txt”,并感谢您的快速响应 –
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/concatenation-operators – Marc