Author |
Message |
Alfredo Morres #1 / 9
|
 Delete temp file
Hello... Another question for your power minds : ) In my script, i create a temp file using the function: strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" set fs = objFileSystem.CreateTextFile(strTempName, True) . . fs.close objWshShell.Run strTempName, 0, False
objFileSystem.DeleteFile "C:\TEMP\~*.*", True The problem is that no temp-files generated in this manner are deleted, while other ~*.* files are deleted !?!? Don't think that the file, when i try to delete it, is in use, because this is a logon script, so files generated on previous logon are absolutely not in use. Tell my why, guys!!! -Enjoy- Legolas
|
Mon, 01 Oct 2001 03:00:00 GMT |
|
 |
Tom Laveda #2 / 9
|
 Delete temp file
Quote:
> Hello... > Another question for your power minds : ) > In my script, i create a temp file using the function: > strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" > set fs = objFileSystem.CreateTextFile(strTempName, True) > . > . > fs.close > objWshShell.Run strTempName, 0, False
> objFileSystem.DeleteFile "C:\TEMP\~*.*", True > The problem is that no temp-files generated in this manner are deleted, > while other ~*.* files are deleted !?!? > Don't think that the file, when i try to delete it, is in use, because > this is a logon script, so files generated on previous logon are > absolutely not in use. > Tell my why, guys!!! > -Enjoy- > Legolas
A guess - Have you checked the temp file's attributes? I believe the 'force' argument in the .DeleteFile forces the deletion of 'read-only', but maybe temp files are also marked as 'system' and therefore cannot be deleted via the *.* filespec. I'm not at an appropriate machine to check right now. You might also try using the explicit strTempName. It's possible that 'forcing' doesn't apply to wildcard filespecs (though I don't see that stated in the documentation). Tom Lavedas ----------- http://www.pressroom.com/~tglbatch/
|
Mon, 01 Oct 2001 03:00:00 GMT |
|
 |
Tom Laveda #3 / 9
|
 Delete temp file
Quote:
> Hello... > Another question for your power minds : ) > In my script, i create a temp file using the function: > strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" > set fs = objFileSystem.CreateTextFile(strTempName, True) > . > . > fs.close > objWshShell.Run strTempName, 0, False
> objFileSystem.DeleteFile "C:\TEMP\~*.*", True > The problem is that no temp-files generated in this manner are deleted, > while other ~*.* files are deleted !?!? > Don't think that the file, when i try to delete it, is in use, because > this is a logon script, so files generated on previous logon are > absolutely not in use. > Tell my why, guys!!! > -Enjoy- > Legolas
I was way off-base in my previous post. I checked on my Win 98 equiped machine. The problem is the .bat extension you are adding. The TempName already has a .tmp extension, so your tempfile has a name like ~???????.tmp.bat, which is not matched by the ~*.* filespec. Instead change your strTempName line to extract the BaseName from the TempName to remove the extension, i.e. strTempName = objFileSystem.GetBaseName(objFileSystem.GetTempName) strTempName = "C:\TEMP\~" & strTempName & ".BAT" Then your ~*.* filespec will match in the .DeleteFile. Tom Lavedas ----------- http://www.pressroom.com/~tglbatch/
|
Mon, 01 Oct 2001 03:00:00 GMT |
|
 |
John Graha #4 / 9
|
 Delete temp file
Would be easier to use: Dim strTempFile Const TemporaryFolder = 2 'VBScript constant strTempFile = fso.GetSpecialFolder(TemporaryFolder) & "\" & fso.GetTempName ' * * * Your code here fso.DeleteFile strTempFile Quote:
>Hello... >Another question for your power minds : ) >In my script, i create a temp file using the function: > strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" > set fs = objFileSystem.CreateTextFile(strTempName, True) > . > . > fs.close >objWshShell.Run strTempName, 0, False
> objFileSystem.DeleteFile "C:\TEMP\~*.*", True >The problem is that no temp-files generated in this manner are deleted, >while other ~*.* files are deleted !?!? >Don't think that the file, when i try to delete it, is in use, because >this is a logon script, so files generated on previous logon are >absolutely not in use. >Tell my why, guys!!! >-Enjoy- >Legolas
|
Sun, 07 Oct 2001 03:00:00 GMT |
|
 |
George S. Elli #5 / 9
|
 Delete temp file
I know that some temp files are created 'today' and may be open. You might leave any files created 'today' alone and delete all of the rest... Quote:
>Hello... >Another question for your power minds : ) >In my script, i create a temp file using the function: > strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" > set fs = objFileSystem.CreateTextFile(strTempName, True) > . > . > fs.close >objWshShell.Run strTempName, 0, False
> objFileSystem.DeleteFile "C:\TEMP\~*.*", True >The problem is that no temp-files generated in this manner are deleted, >while other ~*.* files are deleted !?!? >Don't think that the file, when i try to delete it, is in use, because >this is a logon script, so files generated on previous logon are >absolutely not in use. >Tell my why, guys!!! >-Enjoy- >Legolas
|
Mon, 08 Oct 2001 03:00:00 GMT |
|
 |
Tom Laveda #6 / 9
|
 Delete temp file
Quote:
> Would be easier to use: > Dim strTempFile > Const TemporaryFolder = 2 'VBscript constant > strTempFile = fso.GetSpecialFolder(TemporaryFolder) & "\" & fso.GetTempName > ' * * * Your code here > fso.DeleteFile strTempFile
Except for the fact that the originator's need is for a Batch file and system temp files have .TMP extensions, this is indeed the way to go. It is a simple matter to append .BAT to the name (with or without stripping off the .Bat extension. However, personal correspondence with Mr. Morresi suggests his real problem is that the system is not releasing his procedure, so it is not giving him access to the batch file to delete it. Which leads me to an AH HA! I hadn't though of this before! I'm guessing that the batch procedure's DOS session has not closed. This happens when text is sent to the console during the procedure's execution. The system does not automatically close such session so that the user can see the text before closing the window (though control is passed back to the calling script). Of course in this case, the text is of no consequence, but the system doesn't know that. Therefore, I must assume the offending batch proceedure is still associated with a running procedure AND CANNOT BE DELETED. If I'm right, the solution may be as simple as adding a CLS as the very last executable line of the batch procedure. [cc: Alfredo Morresi] Tom Lavedas ----------- http://www.pressroom.com/~tglbatch/ Quote:
> >Hello... > >Another question for your power minds : ) > >In my script, i create a temp file using the function: > > strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" > > set fs = objFileSystem.CreateTextFile(strTempName, True) > > . > > . > > fs.close > >objWshShell.Run strTempName, 0, False
> > objFileSystem.DeleteFile "C:\TEMP\~*.*", True > >The problem is that no temp-files generated in this manner are deleted, > >while other ~*.* files are deleted !?!? > >Don't think that the file, when i try to delete it, is in use, because > >this is a logon script, so files generated on previous logon are > >absolutely not in use. > >Tell my why, guys!!! > >-Enjoy- > >Legolas
|
Mon, 08 Oct 2001 03:00:00 GMT |
|
 |
Alfredo Morres #7 / 9
|
 Delete temp file
Thanks to all for the precious help, but now i discover that the problem is in another place!!! In my first message I wrote that not only the file that the logon use is impossible to delete, but also all other files generated on the same manner (files that were created by other previous logons) After a lot of researches, i finally find the problem: when the logon trys to delete the temp files, it uses the wildcard "~*.*". For some strange reasons, the first file delete is alway the file that the logon are using. This immediately stops the objFileSystem.DeleteFile("~*.*", True) method ad no other files are deleted. Now, understood the problem, it's easy find the solution. -Enjoy- Legolas Quote:
> Hello... > Another question for your power minds : ) > In my script, i create a temp file using the function: > strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" > set fs = objFileSystem.CreateTextFile(strTempName, True) > . > . > fs.close > objWshShell.Run strTempName, 0, False
> objFileSystem.DeleteFile "C:\TEMP\~*.*", True > The problem is that no temp-files generated in this manner are deleted, > while other ~*.* files are deleted !?!? > Don't think that the file, when i try to delete it, is in use, because > this is a logon script, so files generated on previous logon are > absolutely not in use. > Tell my why, guys!!! > -Enjoy- > Legolas
|
Mon, 08 Oct 2001 03:00:00 GMT |
|
 |
Michael Harri #8 / 9
|
 Delete temp file
I've tried to duplicate this problem with a comparable standalone script (not a logon script), but can't. Here's the test script... 'start of script set fso = createobject("scripting.filesystemobject") s = fso.gettempname msgbox s s = "c:\_temp\~" & s & ".BAT" set ts = fso.createtextfile(s) ts.write "start /w notepad.exe" ts.close msgbox "created" set sh = createobject("wscript.shell") sh.run s,1,false fso.deletefile "c:\_temp\~*.*" msgbox "deleted" set ts = nothing set fso = nothing 'end of script The .bat file starts notepad and waits, so it is still "executing". Even then the fso.deletefile works. The only way I could make this fail was to comment out the ts.close which causes it to fail on the sh.run (file in use), not the fso.deletefile. My conclusion is that it must have something to do with the fact that the script runs during logon. -- Michael Harris
Quote: > Hello... > Another question for your power minds : ) > In my script, i create a temp file using the function: > strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" > set fs = objFileSystem.CreateTextFile(strTempName, True) > . > . > fs.close > objWshShell.Run strTempName, 0, False
> objFileSystem.DeleteFile "C:\TEMP\~*.*", True > The problem is that no temp-files generated in this manner are deleted, > while other ~*.* files are deleted !?!? > Don't think that the file, when i try to delete it, is in use, because > this is a logon script, so files generated on previous logon are > absolutely not in use. > Tell my why, guys!!! > -Enjoy- > Legolas
|
Mon, 08 Oct 2001 03:00:00 GMT |
|
 |
George S. Elli #9 / 9
|
 Delete temp file
Another thing that can be done is change a registry setting (of course, I am not saying *do this*, just an option): [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon] "RunLogonScriptSync"=dword:00000001 This key will cause Logon scripts to run first and then the desktop will load. Useful if you are loading custom desktop item or Start menus from a server.
Quote: >I've tried to duplicate this problem with a comparable standalone script >(not a logon script), but can't. Here's the test script... >'start of script >set fso = createobject("scripting.filesystemobject") >s = fso.gettempname >msgbox s >s = "c:\_temp\~" & s & ".BAT" >set ts = fso.createtextfile(s) >ts.write "start /w notepad.exe" >ts.close >msgbox "created" >set sh = createobject("wscript.shell") >sh.run s,1,false >fso.deletefile "c:\_temp\~*.*" >msgbox "deleted" >set ts = nothing >set fso = nothing >'end of script >The .bat file starts notepad and waits, so it is still "executing". Even >then the fso.deletefile works. The only way I could make this fail was to >comment out the ts.close which causes it to fail on the sh.run (file in >use), not the fso.deletefile. >My conclusion is that it must have something to do with the fact that the >script runs during logon. >-- >Michael Harris
>> Hello... >> Another question for your power minds : ) >> In my script, i create a temp file using the function: >> strTempName = "C:\TEMP\~" & objFileSystem.GetTempName & ".BAT" >> set fs = objFileSystem.CreateTextFile(strTempName, True) >> . >> . >> fs.close >> objWshShell.Run strTempName, 0, False
>> objFileSystem.DeleteFile "C:\TEMP\~*.*", True >> The problem is that no temp-files generated in this manner are deleted, >> while other ~*.* files are deleted !?!? >> Don't think that the file, when i try to delete it, is in use, because >> this is a logon script, so files generated on previous logon are >> absolutely not in use. >> Tell my why, guys!!! >> -Enjoy- >> Legolas
|
Tue, 09 Oct 2001 03:00:00 GMT |
|
|
|