?
Solved

USN*.TMP files created in Temp folder for each snapshot report generated

Posted on 2003-03-26
14
Medium Priority
?
292 Views
Last Modified: 2006-11-17
I am having a problem with an application that creates snapshot reports.  This application creates many reports hourly.  It is creating a bunch of TMP files in the users TEMP folder.  There seems to one file for each report generated. I went into the application and generated a snapshot report by hand and the tmp file was created but was then cleaned up properly by Access.

Does anyone have any idea how to make sure these files are cleaned up out of the temp folder?
0
Comment
Question by:bbaldwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 2
14 Comments
 
LVL 4

Expert Comment

by:dotthei
ID: 8212067
Maybe this is too low level, but does not require modifying any current code

Call a Batch file that purges "CommonTextString".tmp
from temp dir.

Make this call AFTER the snapshot is off and gone
You will likely want to change the vbNormalFocus to another option, ie Hidden

call Shell ( Environ$ ( "COMSPEC" ) & " /c  c:\test.bat", vbNormalFocus)

Environ$("COMSPEC") returns the path to Command.com on the machine and the "/c" argument makes sure that the Dos window is automatically closed when the batch file finishes executing.
0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8212104
dotthei,

This may be our answer, however, I was hoping to change some setting on the server.  Let me see if anyone else comes up with an idea that does not require us to code the deletion of these files.

This does sound like a reasonably simple idea though.

0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8212168
Well, I'm not sure why the tmp files aren't being cleaned up properly - it could be a permissions problem - which user account is listed as the owner of the files ?

If you go with dotthei's suggestion which seems the simplest workaround, you can use the Kill statement from within VBA instead of calling a batch file, eg:
Kill "C:\Temp\USN*.tmp"
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 4

Expert Comment

by:dotthei
ID: 8212328
I learn as much from my bad suggestions as I do from other's good ones - this way I know where my logic is (if applicable) faulty.

AND

I have learned to be hesitant to post a comment after Shane has commented, but since I am not within arm's reach...  :-)  

Assuming that only one machine AND only one log-in was used, there is a clue in the question...

"... I went into the application and generated a snapshot report by hand and the tmp file was created but was then cleaned up properly by Access..."

This might indicate that your procedure is re-hooking "WHATEVER IT IS" that generates the tmp file creation.

Can you re-order your procedure to allow sufficient time for the system to release the hook?
0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8212341
dotthei,

This may be our answer, however, I was hoping to change some setting on the server.  Let me see if anyone else comes up with an idea that does not require us to code the deletion of these files.

This does sound like a reasonably simple idea though.

0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8212365
We actually run this application once per hour and it creates about 500 reports each hour.  We could put the command to delete the files at the end of each hourly run.  Even if any of the files are still locked, the files from the previous hour should be unlocked.

Both of your suggestions are very valid.
0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8212618
dotthei,

This may be our answer, however, I was hoping to change some setting on the server.  Let me see if anyone else comes up with an idea that does not require us to code the deletion of these files.

This does sound like a reasonably simple idea though.

0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8212632
dotthei,

This may be our answer, however, I was hoping to change some setting on the server.  Let me see if anyone else comes up with an idea that does not require us to code the deletion of these files.

This does sound like a reasonably simple idea though.

0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8212666
The files are being created in the "Documents and Settings\[User Name]\Local Settings\Temp" folder. Do you know the Windows API call to determine what the name of the folder is to kill the files?
0
 
LVL 4

Expert Comment

by:dotthei
ID: 8212736
API: Get Login name
 Author(s)
Dev Ashish
 
 
(Q) How do I retrieve the UserName with which the user is logged into the network?

(A) Paste the following code in a new module and call the function fOSUserName.


'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If ( lngX > 0 ) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function
'******************** Code End **************************
 
0
 
LVL 4

Accepted Solution

by:
dotthei earned 750 total points
ID: 8212750
API: Return temporary, system, and installed directories
 Author(s)
Dev Ashish
 
 
(Q) How do I retrieve the Operating System's

    - installed path (directory name)?
    - Temp Directory?
    - System Directory?

(A) Paste the following code in a new module and use fReturnSysDir function to return the System directory (eg. C:\win95\System), fReturnWinDir to return the directory where the OS is installed (eg. C:\Winnt), or fReturnTempDir to return the Temp directory (eg. C:\Temp\)

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Const MAX_PATH As Integer = 255
Private Declare Function apiGetSystemDirectory& Lib "kernel32" _
        Alias "GetSystemDirectoryA" _
        (ByVal lpBuffer As String, ByVal nSize As Long)

Private Declare Function apiGetWindowsDirectory& Lib "kernel32" _
        Alias "GetWindowsDirectoryA" _
        (ByVal lpBuffer As String, ByVal nSize As Long)

Private Declare Function apiGetTempDir Lib "kernel32" _
        Alias "GetTempPathA" (ByVal nBufferLength As Long, _
        ByVal lpBuffer As String) As Long
Function fReturnTempDir()
'Returns Temp Folder Name
Dim strTempDir As String
Dim lngx As Long
    strTempDir = String$(MAX_PATH, 0)
    lngx = apiGetTempDir(MAX_PATH, strTempDir)
    If lngx <> 0 Then
        fReturnTempDir = Left$(strTempDir, lngx)
    Else
        fReturnTempDir = ""
    End If
End Function
Function fReturnSysDir()
'Returns System Folder Name (C:\WinNT\System32)
Dim strSysDirName As String
Dim lngx As Long
    strSysDirName = String$(MAX_PATH, 0)
    lngx = apiGetSystemDirectory(strSysDirName, MAX_PATH)
    If lngx <> 0 Then
        fReturnSysDir = Left$(strSysDirName, lngx)
    Else
        fReturnSysDir = ""
    End If
End Function
Function fReturnWinDir()
'Returns OS Folder (C:\Win95)
Dim strWinDirName As String
Dim lngx As Long
    strWinDirName = String$(MAX_PATH, 0)
    lngx = apiGetWindowsDirectory(strWinDirName, MAX_PATH)
    If lngx <> 0 Then
        fReturnWinDir = Left$(strWinDirName, lngx)
    Else
        fReturnWinDir = ""
    End If
End Function
'******************** Code End**************************
 
 
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8213085
Who, li'l old me ? Don't worry, I try to only post bad-tempered messages once every so often - you caught me after a late night and a flame war last time :-)

BTW, on WinNT/2K/XP, you can use:
environ("username")
to return the current username in VBA, but not on 98/ME.
0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8213099
We know how to get the UserName. We were just looking for how to get the temp folder location. We will try dotthei's solution for the temp folder to see if it works. We are running this on a Terminal Server so it is a multi-user environment.

Thanks!
0
 
LVL 2

Author Comment

by:bbaldwin
ID: 8220673
We decided to use the kill command but to find the folder we used a different command that is a one line command.

Set objFolder = objFSO.GetSpecialFolder(2)

Anyway, thanks for the help!!

Bob
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question