write to shared textfile 
Author Message
 write to shared textfile

Is it possible to append text to an textfile that is already opened?
I want to write in a texfile in my logon script, there is a problem if two
or more users logon at the same time!!!
Is there a solution in VBS. In VB there is a option to Open a textfile
shared, is there something like this in VBS???

Alex



Sat, 01 May 2004 15:36:18 GMT  
 write to shared textfile


Quote:
> Is it possible to append text to an textfile that is already opened?

No, but you can write a loop into the script that will wait for the file to
be closed. Below is a small test script that I wrote to dimonstrate how two
different script could share the same log file.

The only problem that I can see in implementing this type of solution in a
logon script is the number of people trying log on at the same time. It
should work well up to 10 or so. But if dozens of people are logging on at
exactly the same time it could cause very long delays (LoopCount) in the
script's execution or a failure to log the event message. If this is the
case, you should have each person log to a separate file, then have a
separate script that concatenates the results.

In the script below, Line 014 determines how many times the script tries to
open the log file before giving up. Line 019 determines how many
milliseconds the script waits between attempts.

[--- Begin: Dual Script Log Demo.vbs ---]

001. Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
002. sLogFile = "C:\LOGS\DualScript.LOG"
003.
004.
005. 'do some script stuff
006. 'generate an event that needs logged
007. Call LogEvent("This is an event I want logged!")
008.
009. WSCript.Quit(0)
010.
011.
012. Sub LogEvent(sEventMsg)
013.   Dim nLoopCount, oLogFile
014.   For nLoopCount = 1 To 100
015.     On Error Resume Next
016.       Err.Clear
017.       Set oLogFile = oFS.OpenTextFile(sLogFile, 8, True, 0)
018.       If Err.Number <> 0 Then
019.         WScript.Sleep 100
020.       Else
021.         oLogFile.WriteLine sEventMsg
022.         oLogFile.Close
023.         Exit Sub
024.      End If
025.   Next
026.
027.   MsgBox "Error: Could not open log file!"
028.   WScript.Quit(1)
029.
030. End Sub

[--- End: Dual Script Log Demo.vbs ---]



Sun, 02 May 2004 00:22:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. write CODE into Textfile

2. writing form output to a textfile

3. Writing textfile in VBscript

4. ASP: Writing to a textfile, and then redirecting to it

5. Writing a text file to a shared location

6. WSH - sharing directories ( net share)

7. enumerating shares and share permissions with vbscript

8. share permissions and enumerating shares

9. List shares and share permissions?

10. Creating a share with share permissions

11. How to write a " into a textfile ???

12. how do you format text when you write to a textfile?

 

 
Powered by phpBB® Forum Software