Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

login vbscript textfile edit

$
0
0
Im trying to create a vbs file that runs when a user logs in to our domain pc. What I have now is it adds the current pc ip to a new line of this text file(top line). The reason I want this is because for certain reasons I need the ip of the last pc this user logged into. the script works fine now and every log in adds a new line with the ip and a timestamp. the problem I have is I only need the current Ip and the 2nd line with the last pc(most current)they logged in to. Im trying to find out how to only have those 2 lines and replace them with the latest and not keep adding lines.

line 1: current ip
line 2: last pc

So if they log in to a 3rd pc it would replace line 2 with line 1 and create a new line 1. I hope this isn't too confusing. Here's what i have now from other examples I've found from around the web.




' check if file exists and if not creates with ip and if so adds ip

Dim oFSO, oTxtFile

Set oFSO = CreateObject("Scripting.FileSystemObject") 

If oFSO.FileExists("F:\myips.txt")  Then

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("F:\myips.txt", ForReading)

strContents = objFile.ReadAll
objFile.Close

strFirstLine = strIPAddress
strNewContents = strFirstLine &  " " & Now & vbCrLf & strContents

Set objFile = objFSO.OpenTextFile("F:\myips.txt", ForWriting)
objFile.WriteLine strNewContents


objFile.Close


Else 
Set oTxtFile = oFSO.CreateTextFile("F:\myips.txt") 
Set oTxtFile = Nothing
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.OpenTextFile("F:\myips.txt", 2, True) 
fl.Write(strIPAddress &  " " & Now & vbCrLf)

fl.Close : Set fl = Nothing
Set fso = Nothing

End If
Set oFSO = Nothing

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>