اذهب الي المحتوي
أوفيسنا

الردود الموصى بها

قام بنشر

بعم يمكن ذلك

استخدم هذا الكود 

Private Const TIMEOUT = 99
Public Sub Restart()
    Dim scriptpath As String
    scriptpath = Application.CurrentProject.FullName & ".dbrestart.bat"
    
    If Dir(scriptpath, vbNormal) <> "" Then
        If DateAdd("s", TIMEOUT * 1, FileDateTime(scriptpath)) < Date Then
            Kill scriptpath
        Else
            Application.Quit acQuitSaveAll
            Exit Sub
        End If
    End If
    
    Dim s As String
    s = s & "SETLOCAL ENABLEDELAYEDEXPANSION" & vbCrLf
    s = s & "SET /a counter=0" & vbCrLf
    s = s & ":CHECKLOCKFILE" & vbCrLf
    s = s & "ping 0.0.0.255 -n 1 -w 100 > nul" & vbCrLf
    s = s & "SET /a counter+=1" & vbCrLf
    s = s & "IF ""!counter!""==""" & TIMEOUT & """ GOTO CLEANUP" & vbCrLf
    s = s & "IF EXIST ""%~f1.%3"" GOTO CHECKLOCKFILE" & vbCrLf
    s = s & "start "" "" ""%~f1.%2""" & vbCrLf
    s = s & ":CLEANUP" & vbCrLf
    s = s & "del %0"
    
    Dim intFile As Integer
    intFile = FreeFile()
    Open scriptpath For Output As #intFile
    Print #intFile, s
    Close #intFile
    
    Dim dbname As String, ext As String, lockext As String
    Dim idx As Integer
    For idx = Len(CurrentProject.FullName) To 1 Step -1
        If Mid(CurrentProject.FullName, idx, 1) = "." Then Exit For
    Next idx
    dbname = Left(CurrentProject.FullName, idx - 1)
    ext = Mid(CurrentProject.FullName, idx + 1)
    
    If Left(ext, 2) = "ac" Then
        lockext = "laccdb"
    Else
        lockext = "ldb"
    End If
    
    s = """" & scriptpath & """ """ & dbname & """ " & ext & " " & lockext
    Shell s, vbHide
    
   Application.Quit acQuitSaveAll
End Sub

ثم استدعيه بهذا الكود

Private Sub btRestart_Click()
    Utilities.Restart
End Sub

 

  • Like 2
  • Thanks 1
قام بنشر
الان, Barna said:

بعم يمكن ذلك

استخدم هذا الكود 


Private Const TIMEOUT = 99
Public Sub Restart()
    Dim scriptpath As String
    scriptpath = Application.CurrentProject.FullName & ".dbrestart.bat"
    
    If Dir(scriptpath, vbNormal) <> "" Then
        If DateAdd("s", TIMEOUT * 1, FileDateTime(scriptpath)) < Date Then
            Kill scriptpath
        Else
            Application.Quit acQuitSaveAll
            Exit Sub
        End If
    End If
    
    Dim s As String
    s = s & "SETLOCAL ENABLEDELAYEDEXPANSION" & vbCrLf
    s = s & "SET /a counter=0" & vbCrLf
    s = s & ":CHECKLOCKFILE" & vbCrLf
    s = s & "ping 0.0.0.255 -n 1 -w 100 > nul" & vbCrLf
    s = s & "SET /a counter+=1" & vbCrLf
    s = s & "IF ""!counter!""==""" & TIMEOUT & """ GOTO CLEANUP" & vbCrLf
    s = s & "IF EXIST ""%~f1.%3"" GOTO CHECKLOCKFILE" & vbCrLf
    s = s & "start "" "" ""%~f1.%2""" & vbCrLf
    s = s & ":CLEANUP" & vbCrLf
    s = s & "del %0"
    
    Dim intFile As Integer
    intFile = FreeFile()
    Open scriptpath For Output As #intFile
    Print #intFile, s
    Close #intFile
    
    Dim dbname As String, ext As String, lockext As String
    Dim idx As Integer
    For idx = Len(CurrentProject.FullName) To 1 Step -1
        If Mid(CurrentProject.FullName, idx, 1) = "." Then Exit For
    Next idx
    dbname = Left(CurrentProject.FullName, idx - 1)
    ext = Mid(CurrentProject.FullName, idx + 1)
    
    If Left(ext, 2) = "ac" Then
        lockext = "laccdb"
    Else
        lockext = "ldb"
    End If
    
    s = """" & scriptpath & """ """ & dbname & """ " & ext & " " & lockext
    Shell s, vbHide
    
   Application.Quit acQuitSaveAll
End Sub

ثم استدعيه بهذا الكود


Private Sub btRestart_Click()
    Utilities.Restart
End Sub

 

شكراً اخي على المرور

هل اضعه في وحدة نمطية

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information