Try
Dim TargetProcess As Process() = Process.GetProcessesByName( "EndingBanner")
If TargetProcess.Length0 Then
My.Computer.FileSystem.DeleteFile( "C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez",FileIO.UIOption.OnlyErrorDialogs,FileIO.RecycleOp tion.DeletePermanently,FileIO.UICancelOption.DoNot hing)
My.Computer.FileSystem.DeleteFile( "C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez",FileIO.UIOption.OnlyErrorDialogs,FileIO.RecycleOp tion.DeletePermanently,FileIO.UICancelOption.DoNot hing)
End If
Catch ex As Exception
'Display error message here...
End Try
I tried this code, it was really nice, maybe i wasn't clear enough. But i want it to be able to detect the start of proccess "Ending banner", so as soon as proccess "ending banner" starts, it starts killing files.
so.. i need the codes for if proccess A.exe starts then my program deletes files A and File B. And then the program shuts down it self.
I'll had more details if needed.
[php]
Dim TargetProcess As Process() = Process.GetProcessesByName(txtprocess.Text) 'substitute txtprocess with whatever'
If TargetProcess.Length <> 0 Then
My.Computer.FileSystem.DeleteFile("C:\Example\Exam ple") 'change this to your file path that you want to delete'
End
End If
[/php]
Oh yeah for the Process.GetProcessesByName("example") don't include .exe.
i.e this will work
[php]
Dim TargetProcess As Process() = Process.GetProcessesByName("notepad")
[/php]
But this won't
[php]
Dim TargetProcess As Process() = Process.GetProcessesByName("notepad.exe")
[/php]
Hope that helps
thanks will take a look
Originally Posted by porhaxn
thanks will take a look
No problems, it should work.
Can we target the proccess by location of the file?
Edit:
Code:
Dim TargetProcess As Process() = Process.GetProcessesByName(notepad)
If TargetProcess.Length <> 0 Then
Kill("C:\Nexon\Combat Arms\Filename")
End
End If
would this work, i mean differenct between kill and delete files
Originally Posted by porhaxn
Can we target the proccess by location of the file?
Edit:
Code:
Dim TargetProcess As Process() = Process.GetProcessesByName(notepad)
If TargetProcess.Length <> 0 Then
Kill("C:\Nexon\Combat Arms\Filename")
End
End If
would this work, i mean differenct between kill and delete files
No, you can't. You can delete the file so that the process won't run again. But for killing (i.e; for 1 time) you need to use the process class.
Originally Posted by porhaxn
Can we target the proccess by location of the file?
Edit:
Code:
Dim TargetProcess As Process() = Process.GetProcessesByName(notepad)
If TargetProcess.Length <> 0 Then
Kill("C:\Nexon\Combat Arms\Filename")
End
End If
would this work, i mean differenct between kill and delete files
Quick question, are you trying to create an auto-clean feature for a CA cleaner by any chance?
What exactly are you trying to kill in the CA folder? If it's not CA itself I'm pretty sure you can go with the code you've got there... dunno
Oh yeah the first line of your code should be
[php]
Dim TargetProcess As Process() = Process.GetProcessesByName("notepad")
[/php]
That code you have there will kill("C:\Nexon\Combat Arms\Filename") whenever notepad opens.
Oh yeah with "kill" functions you should either add a try-catch block or an
[php]
On Error Resume Next
[/php]
Because after the first time you kill the files, it will return a "cannot find this file" error and close the whole program down.
Nope, not making a cleanner
Code:
Dim TargetProcess As Process() = Process.GetProcessesByName("EndingBanner")
If TargetProcess.Length <> 0 Then
Kill("C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez")
Kill("C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez")
this means if endingbanner.exe starts, these files will be deleted?
and please fix the On error resume next for me thanks
And how do we add exit the program itself after it deleting the files?
Originally Posted by porhaxn
Nope, not making a cleanner
Code:
Dim TargetProcess As Process() = Process.GetProcessesByName("EndingBanner")
If TargetProcess.Length <> 0 Then
Kill("C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez")
Kill("C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez")
this means if endingbanner.exe starts, these files will be deleted?
and please fix the On error resume next for me thanks
And how do we add exit the program itself after it deleting the files?
On Error Resume Next is not a good wrapper to handle errors. Use Try...Catch Block. Anyways, here's the code you need:
Try
Dim TargetProcess As Process() = Process.GetProcessesByName( "EndingBanner")
If TargetProcess.Length0 Then
My.Computer.FileSystem.DeleteFile( "C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez",FileIO.UIOption.OnlyErrorDialogs,FileIO.RecycleOp tion.DeletePermanently,FileIO.UICancelOption.DoNot hing)
My.Computer.FileSystem.DeleteFile( "C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez",FileIO.UIOption.OnlyErrorDialogs,FileIO.RecycleOp tion.DeletePermanently,FileIO.UICancelOption.DoNot hing)
End If
Catch ex As Exception
'Display error message here...
End Try
Hope this helps !!
Originally Posted by FLAMESABER
On Error Resume Next is not a good wrapper to handle errors. Use Try...Catch Block. Anyways, here's the code you need:
Try
Dim TargetProcess As Process() = Process.GetProcessesByName( "EndingBanner")
If TargetProcess.Length0 Then
My.Computer.FileSystem.DeleteFile( "C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez",FileIO.UIOption.OnlyErrorDialogs,FileIO.RecycleOp tion.DeletePermanently,FileIO.UICancelOption.DoNot hing)
My.Computer.FileSystem.DeleteFile( "C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez",FileIO.UIOption.OnlyErrorDialogs,FileIO.RecycleOp tion.DeletePermanently,FileIO.UICancelOption.DoNot hing)
End If
Catch ex As Exception
'Display error message here...
End Try
Hope this helps !!
K flame, i tried your code. It was really nice, maybe i wasn't clear enough. But i want it to be able to detect the start of proccess "Ending banner", so as soon as proccess "ending banner" starts, it starts killing files.
I think it's easier to just check when Engine.exe stops running O.o.
But for EndingBanner.exe....
I just aircoded this so It might not work 100%
add a timer, delay 100 and enabled = True
[php] Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim TargetProcess As Process() = Process.GetProcessesByName("EndingBanner")
If TargetProcess.Length <> 0 Then
Try
Kill("C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez")
Kill("C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez")
Application.Exit() 'ends your program'
Catch ex As Exception
'If you want it to display the error in a message box do MsgBox(ErrorToString)'
End Try
End If
End Sub
[/php]
you can make a separate kill function to minimize repeated code but it's optional
[php]
Private Sub KillFile (ByVal rez as String)
Kill("C:\Nexon\Combat Arms\" + rez + ".rez")
End Sub
[/php]
Then to use it:
[php]
KillFile("GUNS_T_PV_SMG") 'change this to whatever rez name (don't need to include ".rez" but make sure you use the double quotes '
[/php]
And yeah...I think that's what you want to do?
Thanks Deezy, and i would like to use the one which checks if engine.exe stops running, it would work out better. But it seems to be deleting files before engine.exe even starts -.-
Yes because it checks whether the process is running or not, and if not it will do all the crap you want. So any time that engine isn't running it will do the commands.
To when Engine is not running AFTER it has been opened I think the most straightforward way is to incorporate 2 timers. There's other ways but this one is pretty easy.
Okay so this timer checks whether Engine has started or not, if it has it starts the close timer running.
Don't forget to Enable this timer.
[php]
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim TargetProcess As Process() = Process.GetProcessesByName("Engine")
If TargetProcess.Length <> 0 Then
Timer1.Enabled = True
Else : Timer2.Enabled = False
End If
End Sub
[/php]
Now for the timer that checks whether Engine has stopped running.
[php]
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim TargetProcess As Process() = Process.GetProcessesByName("Engine")
If TargetProcess.Length = 0 Then 'note Length = 0 now, not <> 0, this is important'
Try
Kill("C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez")
Kill("C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez")
Application.Exit()
Timer1.Enabled = False()
Catch ex As Exception
'If you want it to display the error in a message box do MsgBox(ErrorToString)'
End Try
End If
End Sub
[/php]
Think that'll work
I've tested the air coded endingbanner one works perfectly! I don't know how to thank you lol
EDIT:
for the engine.exe one do i just enable the first timer?
and for the
" Timer1.Enabled = False() " the FALSE part i got error
Expression is not an array or a method, and cannot have an arguement list
hehe don't mention it. I'm still a VB beginner too so being able to actually help someone out is nice change :P
I created another code for you that doesn't rely on 2 timers (for Engine)
Pretty sure this should work, haven't actually tested it.
add this declaration to the top of your form, just under "Public Class Form1"
[php]
Dim i As Integer = 1
[/php]
Now make your timer enabled and delay of like 1-100 doesn't really matter
[php]
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim TargetProcess As Process() = Process.GetProcessesByName("Engine")
Select Case (i)
Case 1
If TargetProcess.Length <> 0 Then
i = 2
End If
Case 2
If TargetProcess.Length = 0 Then
Try
Kill("C:\Nexon\Combat Arms\Game\GUNS_M_PV_SMG.rez")
Kill("C:\Nexon\Combat Arms\Game\GUNS_T_PV_SMG.rez")
i = 1
Application.Exit()
Catch ex As Exception
'If you want it to display the error in a message box do MsgBox(ErrorToString)'
End Try
End If
End Select