Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 800A0046 upon CreateTextFile method

Status
Not open for further replies.

dannydanny

IS-IT--Management
Oct 9, 2002
109
DK
Hi,

I sent out a script to everyone in my office to collect information about links stored on their computers then write the information to a textfile on the server. I created the script below and ran it and it seemed to work perfectly. But no sooner than I had distributed the scirpt, users started calling me asking why an error popped up. I investigated and this was the error code: "800A0046. Can not write to file."

However the script continues and works as intended. So I am wondering, why did the error occur and what does it mean???

***********************************
Set fs = CreateObject("Scripting.FileSystemObject")

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer)
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings
compname = objComputer.Name
Next

>>>>>>>>ERROR CREATED BY NEXT STATEMENT<<<<
set tempfile = fs.CreateTextFile(&quot;\\Servername\public\GeneralFolder\&quot;+compname+&quot;Links.txt&quot;)

Set objWMIService = GetObject(&quot;winmgmts:\\&quot; & compname & &quot;\root\cimv2&quot;)
Set colItems = objWMIService.ExecQuery(&quot;Select * from Win32_ShortcutFile&quot;,,48)
For Each objItem in colItems
tempfile.writeline (&quot;Name: &quot; & objItem.Name)
tempfile.writeline(&quot;Target: &quot; & objItem.Target)
tempfile.writeline(&quot;&quot;)
Next

msgbox(&quot;Finished. Thank you for your co-operation&quot;)
tempfile.close
WScript.quit
*****************************************

Permissions on the folder that the text file is written to are Everyone. We are using W2k Pro, but the server is WinNT4.0.

Could the error be caused by permissions? or the fact that everyone executed the script at about the same time, so access to the folder was denied?!?!

The funny thing is, apart from the error popping up, the script works as intended!?!?

Any info much appreciated! It was quite embarassing to send out a buggy script to everyone....
Danny
 
LOL

I solved my own problem.....its turns out that users were executing the program twice in quick succession. So while the first execution was creating the text file and writing to it, the second one could not obtain a handle to the same file for writing, hence the error. So while the 2nd execution stopped, the 1st one continued and comleted its task as expected!

So, you may be wondering why so many of my users executed the script twice in a row....I actually sent two scripts around the office. The first one I asked users to execute does its job in about 2 seconds, while the 2nd script (the one above which caused the error messages) normally takes about 10 minutes to complete. I guess that because the &quot;Finished&quot; pop up box did not come up straight away, users clicked on the program icon again. Hence the double execution.

Anyway, I`ve fixed the &quot;bug&quot; now.
I feel like giving myself a star!!! :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top