1
Dim oShell : Set oShell = CreateObject("WScript.Shell")
dim filesys
oShell.Run "taskkill /F /IM mysqld.exe", , True
Dim WShell
Set fso = CreateObject("Scripting.FileSystemObject")
file = ("C:\xampp\mysql\bin\mysqld.exe")
fso.DeleteFile file
Set WShell = Nothing 

Im getting permission denied running the script with user privileges, what i want is that the script wont display that error even if i get permission denied.

datarocker
  • 27
  • 2
  • 2
    [What does the “On Error Resume Next” statement do?](https://stackoverflow.com/questions/2202869/what-does-the-on-error-resume-next-statement-do) – Flakes Dec 30 '19 at 10:21

2 Answers2

0

Refer to On Error - statement of language VBScript

If you don't use an On Error Resume Next statement, then any runtime error that occurs is fatal; i.e. an error message is displayed and the execution stops.

On Error Resume Next causes execution to continue with the statement immediately following the statement that caused the runtime error, or with the statement immediately following the most recent call out of the procedure containing the On Error Resume Next statement.

This allows execution to continue despite a runtime error. You can then build the error-handling routine inline within the procedure.

An On Error Resume Next statement becomes inactive if another procedure is called, so you should execute an On Error Resume Next statement in each called routine if you want inline error handling within that routine.

On Error Resume Next
Dim fso,oShell,file
Set fso = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
oShell.Run "Taskkill /F /IM mysqld.exe",0,True
file = "C:\xampp\mysql\bin\mysqld.exe"
If fso.FileExists(file) Then
    fso.DeleteFile file
End If
Set oShell = Nothing 
Set fso = Nothing
Hackoo
  • 18,337
  • 3
  • 40
  • 70
0

You can add something more in error handling:

Dim oShell
Set oShell = CreateObject("WScript.Shell")
Dim filesys
oShell.Run "taskkill /F /IM mysqld.exe", , True
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = ("C:\xampp\mysql\bin\mysqld.exe")
On Error Resume Next
fso.DeleteFile file
On Error Goto 0
Set fso = Nothing 

You can disable error handling any time using On Error Goto 0 statement. And there is an Err object. Err.Raise ErrorCode raises an error using an errorcode. Err.Number gives the error code and Err.Description gives the error details.

Wasif
  • 14,755
  • 3
  • 14
  • 34