公司的軟件是放置在公共盤上給用戶使用,每次升級時,都有用戶未關閉軟件,使得新程序不能順利的替換舊程序。
所以我想有沒有什麼辦法可以強制刪掉舊程序,或者將舊程序重命名。
這問題困擾了我好幾天了。注意:
1)是刪正在使用中的文件
2)不可以重啟公共機的

解决方案 »

  1.   

    试一试API函数:DeleteFile
    【操作系统】
    Win9X:Yes
    WinNT:Yes
    【说明】
      删除指定文件 
    【返回值】
      Long,非零表示成功,零表示失败。会设置GetLastError 
    【其它】
      与vb的kill语句相似,在windows 95下使用这个函数要小心——即使文件当前正由一个应用程序打开,该函数也会将其删除
    【参数表】
      lpFileName -----  String,欲删除文件的名字Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long'Example Name:Files
    'This program needs a Dialog box, named CDBox1
    '  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
    '   and select Microsoft Common Dialog control)
    Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
    End Type
    Private Type SHFILEOPSTRUCT
        hWnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAborted As Boolean
        hNameMaps As Long
        sProgress As String
    End Type
    Private Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
    End Type
    Private Const GENERIC_WRITE = &H40000000
    Private Const OPEN_EXISTING = 3
    Private Const FILE_SHARE_READ = &H1
    Private Const FILE_SHARE_WRITE = &H2
    Private Const FO_DELETE = &H3
    Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
    Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As Long) As Long
    Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
    Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
    Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
    Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
    Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim lngHandle As Long, SHDirOp As SHFILEOPSTRUCT, lngLong As Long
        Dim Ft1 As FILETIME, Ft2 As FILETIME, SysTime As SYSTEMTIME
        'Set the dialog's title
        CDBox.DialogTitle = "Choose a file ..."
        'Raise an error when the user pressed cancel
        CDBox.CancelError = True
        'Show the 'Open File'-dialog
        CDBox.ShowOpen
        'Create a new directory
        CreateDirectory "C:\KPD-Team", ByVal &H0
        'Copy the selected file to our new directory
        CopyFile CDBox.filename, "C:\KPD-Team\" + CDBox.FileTitle, 0
        'Rename the file
        MoveFile "C:\KPD-Team\" + CDBox.FileTitle, "C:\KPD-Team\test.kpd"
        'Open the file
        lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
        'Get the file's size
        MsgBox "The size of the selected file is" + Str$(GetFileSize(lngHandle, lngLong)) + " bytes."
        'Get the fil's time
        GetFileTime lngHandle, Ft1, Ft1, Ft2
        'Convert the file time to the local file time
        FileTimeToLocalFileTime Ft2, Ft1
        'Convert the file time to system file time
        FileTimeToSystemTime Ft1, SysTime
        MsgBox "The selected file was created on" + Str$(SysTime.wMonth) + "/" + LTrim(Str$(SysTime.wDay)) + "/" + LTrim(Str$(SysTime.wYear))
        'Close the file
        CloseHandle lngHandle
        'Delete the file
        DeleteFile "C:\KPD-Team\test.kpd"
        With SHDirOp
            .wFunc = FO_DELETE
            .pFrom = "C:\KPD-Team"
        End With
        'Delete the directory
        SHFileOperation SHDirOp
        End
    End Sub
      

  2.   

    2樓
    DeleteFile
    這函數試過,不管用
      

  3.   

    问题是我调试通过了啊Option Explicit
    Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
    Private Sub Command1_Click()
        Dim lngP As Long
        'D:\11.png处于打开状态
        lngP = DeleteFile("D:\11.png")
    End Sub
    你要删除的文件是什么文件?是不是本机文件?如果是处于网络中的,可能是权限的问题。
      

  4.   

    我要刪的是本機的EXE文件
    但是共享另給人正在使用中我試過,刪不了
      

  5.   


    兄弟,你說的是不是這篇文章
    [强烈推荐]ring0下文件解锁&强制删除工具 
    看介紹,使用時有時候會導致服務器藍屏,有這種情況我可不敢用的,如果藍屏了,老板罵人的口水就夠嗆死我。
      

  6.   

    你看这样行否?
    1、当你需要删除程序时,你向所有的客户机发送一个消息,客户机再接收到这个消息后关闭掉打开的文件,或者使用Taskkill命令杀掉打开文件的进程。
    2、在完成了1后你再删除文件。
      

  7.   

    楼主的这种情况,可以考虑使用terminal server。
      

  8.   

    需要借助另一个exe程序,结束本机客户端程序,从服务器下载新程序,覆盖或安装,再启动它 
      

  9.   

    不是有个unlock都开源了嘛
    看看人家怎么做的
      

  10.   

    你是不是用windows的图片传真查看器打开了图片,然后你就说你的图片是打开状态?有没有想过,windows只是将图片读入内存,然后就切断了联系。所以,我怀疑你所谓的图片打开了站不住脚。你正在播放一个电影的时候试试,如果这样也可以,那你就是对的!
      

  11.   

    就算你更新成功了,你也无法实时更新客户端内存里面旧的exe或dll的映象。