Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

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

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
bbaldwin
Asked:
bbaldwin
  • 8
  • 4
  • 2
1 Solution
 
dottheiCommented:
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
 
bbaldwinAuthor Commented:
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
 
shanesuebsahakarnCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
dottheiCommented:
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
 
bbaldwinAuthor Commented:
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
 
bbaldwinAuthor Commented:
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
 
bbaldwinAuthor Commented:
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
 
bbaldwinAuthor Commented:
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
 
bbaldwinAuthor Commented:
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
 
dottheiCommented:
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
 
dottheiCommented:
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
 
shanesuebsahakarnCommented:
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
 
bbaldwinAuthor Commented:
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
 
bbaldwinAuthor Commented:
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

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 8
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now