ashley Posted January 17, 2009 Posted January 17, 2009 (edited) Ok, well im still making this parental Control system,I have the user browse for a file, so that it has the Full file path!How to i check to see if that file is running!And if it is running how to i close it!Would i use?If ProcessExists($File) Then MsgBox(0, "Parental Control", $File & " is running.") EndIf ProcessClose($File) $PID = ProcessExists($File); Will return the PID or 0 if the process isn't found. If $PID Then ProcessClose($PID)Thanks in advanceCode taken from helpfiles Edited January 17, 2009 by ashley Free icons for your programs
Rental Posted January 17, 2009 Posted January 17, 2009 you can use Processexists() to see if something is running, and processclose() to to close it Rental
ashley Posted January 17, 2009 Author Posted January 17, 2009 So, how would i do this if the user has inputted "C:\Users\Public\Games\World of Warcraft\Launcher.exe" as the file to check for. Thanks in advance Free icons for your programs
NerdFencer Posted January 17, 2009 Posted January 17, 2009 You would do it like this: If ProcessExists("Launcher.exe") Then ProcessClose("Launcher.exe") EndIf _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell
ashley Posted January 17, 2009 Author Posted January 17, 2009 You would do it like this: If ProcessExists("Launcher.exe") Then ProcessClose("Launcher.exe") EndIf But what about if the file opens another file and then closes? Will the other file open? Free icons for your programs
Andreik Posted January 17, 2009 Posted January 17, 2009 But what about if the file opens another file and then closes? Will the other file open? Try this, original code by Siao: Func IsOpenFile($PATH) Local $GENERIC_READ = 0x80000000 Local $GENERIC_WRITE = 0x40000000 Local $OPEN_EXISTING = 3 Local $FILE_ATTRIBUTE_NORMAL = 0x80 If Not FileExists($PATH) Then SetError(1,0,-1) LOCAL $hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", $PATH, _ "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _ "int", 0, _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", $FILE_ATTRIBUTE_NORMAL, _ "int", 0) If $hFile[0] = -1 Then Return True Else DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile[0]) Return False EndIf EndFunc
ashley Posted January 17, 2009 Author Posted January 17, 2009 Try this, original code by Siao: Func IsOpenFile($PATH) Local $GENERIC_READ = 0x80000000 Local $GENERIC_WRITE = 0x40000000 Local $OPEN_EXISTING = 3 Local $FILE_ATTRIBUTE_NORMAL = 0x80 If Not FileExists($PATH) Then SetError(1,0,-1) LOCAL $hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", $PATH, _ "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _ "int", 0, _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", $FILE_ATTRIBUTE_NORMAL, _ "int", 0) If $hFile[0] = -1 Then Return True Else DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile[0]) Return False EndIf EndFunc Okay, i have noidea what any of that means or does! Free icons for your programs
Andreik Posted January 18, 2009 Posted January 18, 2009 Okay, i have noidea what any of that means or does!I don't know what you don't understand, it's very simple: Run("calc.exe") MsgBox(0,"","Run/Open: " & IsOpenFile(@SystemDir & "\Calc.exe")) ProcessClose("calc.exe") MsgBox(0,"","Run/Open: " & IsOpenFile(@SystemDir & "\Calc.exe")) Func IsOpenFile($PATH) Local $GENERIC_READ = 0x80000000 Local $GENERIC_WRITE = 0x40000000 Local $OPEN_EXISTING = 3 Local $FILE_ATTRIBUTE_NORMAL = 0x80 If Not FileExists($PATH) Then SetError(1,0,-1) LOCAL $hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", $PATH, _ "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _ "int", 0, _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", $FILE_ATTRIBUTE_NORMAL, _ "int", 0) If $hFile[0] = -1 Then Return True Else DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile[0]) Return False EndIf EndFunc
ashley Posted January 18, 2009 Author Posted January 18, 2009 How would this work if the user had to type in the file path into an input box? Free icons for your programs
jerem488 Posted January 18, 2009 Posted January 18, 2009 (edited) Otherwise, you can use the WinList() function. $var = WinList() For $i = 1 to $var[0][0] ; Only display visble windows that have a title If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then WinClose($var[$i][0]) EndIf Next Func IsVisible($handle) If BitAnd( WinGetState($handle), 1 ) Then ; if windows exists Return 1 Else Return 0 EndIf EndFunc After you can play with differents values of WinGetState Edited January 18, 2009 by jerem488 Qui ose gagneWho Dares Win[left]CyberExploit[/left]
Andreik Posted January 18, 2009 Posted January 18, 2009 How would this work if the user had to type in the file path into an input box?Please post your code.
jerem488 Posted January 18, 2009 Posted January 18, 2009 $var = WinList() For $i = 1 to $var[0][0] ; Only display visble windows that have a title If $var[$i][0] <> "" And IsVisible($var[$i][1]) And StringInStr($var, $File) Then MsgBox(0, "Parental Control", $File & " is running.") WinClose($var[$i][0]) EndIf Next Func IsVisible($handle) If BitAnd( WinGetState($handle), 1 ) Then ; if windows exists Return 1 Else Return 0 EndIf EndFunc normally this code works.... Qui ose gagneWho Dares Win[left]CyberExploit[/left]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now