希望你的淵博知識的基礎可以幫助在這裏,文件搜索在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