Jump to content
Sign in to follow this  
UltraFine

3 questions (1) finding a text (2) closing autoit apps (3) 1024=1MB

Recommended Posts

UltraFine

Hi, i want to ask three questions. can i? Ok

(1) how can i find a text in a line for example in @ComputerName ?

@ComputerName = "Thisis my computername"

now how will i check if the word computer is in it or not?

(2) i have installed some applications from this forum (Example Scripts) and some of them are in StartUp but i don't remember their names. how can i close their processes and delete them with a script which will do the trick?

i want to close the process of all running AutoIt Exe's and delete them.

(3) i know about FileGetSize() but don't know how to get it in KB,MB,GB also how to equal

$size = 1024KB

If $size = 1MB or 1024KB then

.....

EndIf

Example:

$a = FileGetSize(@AutoItExe) ; will get the file size in bytes.

and i want to get the file size in MB,GB,etc

i hope you will understand and try to help me out, thanks for reading the thread.

Edited by L0veUK

Share this post


Link to post
Share on other sites
Spiff59

Hi, i want to ask three questions. can i? Ok

(1) how can i find a text in a line for example in @ComputerName ?

@ComputerName = "Thisis my computername"

now how will i check if the word computer is in it or not?

(2) i have installed some applications from this forum (Example Scripts) and some of them are in StartUp but i don't remember their names. how can i close their processes and delete them with a script which will do the trick?

(3) Updating...

I'll tackle #1 for you:

$result = StringInStr("This is my computer name", "computer")
If $result Then
    Msgbox(1,"","I found the search string!")
Else
    Msgbox(1,"","Search string not found")
Endif
Edited by Spiff59

Share this post


Link to post
Share on other sites
UltraFine

I'll tackle #1 for you:

$result = StringInStr("This is my computer name", "computer")
If $result Then
    Msgbox(1,"","I found the search string!)
Else
    Msgbox(1,"","Search string not found)
Endif
Thanks, and do you know about my questions #2 and #3?

Share this post


Link to post
Share on other sites
Spiff59

Thanks, and do you know about my questions #2 and #3?

I'm not entirely sure what you're asking in #2, and have no idea what #3 refers to.

Share this post


Link to post
Share on other sites
UltraFine

I'm not entirely sure what you're asking in #2, and have no idea what #3 refers to.

First post updated.

Share this post


Link to post
Share on other sites
monoceres

To convert bytes->KB/MB/GB/TB you can use this function :mellow:

MsgBox(0,"2048 bytes",_BytesConvert(2048,1)&" kb")

; Level 0 is bytes, level 1 is kB, level 2 is MB etc.
Func _BytesConvert($bytes,$level)
    Return $bytes/(1024^$level)
EndFunc

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
UltraFine

To convert bytes->KB/MB/GB/TB you can use this function :mellow:

MsgBox(0,"2048 bytes",_BytesConvert(2048,1)&" kb")

; Level 0 is bytes, level 1 is kB, level 2 is MB etc.
Func _BytesConvert($bytes,$level)
    Return $bytes/(1024^$level)
EndFunc
Thanks monoceres, now only Question #2 is unresolved.

Share this post


Link to post
Share on other sites
UltraFine

no one can help me?

Share this post


Link to post
Share on other sites
Richard Robertson

You can look for all windows with the class "AutoIt v3", call WinGetProcess for each window you find, then close the window and delete the executable file you find though the process information.

Share this post


Link to post
Share on other sites
UltraFine

You can look for all windows with the class "AutoIt v3", call WinGetProcess for each window you find, then close the window and delete the executable file you find though the process information.

Thanks

a user sent me a script by Smoke_n but it's not deleting the files.

Func Kill_AutoIt_Processes()
    Local $AutoIT_PID = @AutoItPID
    Local $AutoIT_WinList = WinList("[REGEXPCLASS:.*?AutoIt.*?]")
    Local $I_PID = 0, $I_COUNT = 0
    For $I = 1 To $AutoIT_WinList[0][0]
        $I_PID = WinGetProcess($AutoIT_WinList[$I][1])
        If $I_PID <> $AutoIT_PID Then
            $I_COUNT += 1
            WinKill($AutoIT_WinList[$I][1])
            ProcessClose($I_PID)
        EndIf
    Next
    Return $I_COUNT
EndFunc

can you help me to improve this code?

Share this post


Link to post
Share on other sites
Spiff59

I have too much time on my hands!

Just playing around with your #2...

$filesize = 123456
$filesize_str = _BytesConvert($filesize)
MsgBox(0,"",$filesize_str)
Exit
;------------------------------------------------------------------------------
Func _BytesConvert($bytes)
    Local $x, $bytes_suffix[5] = ["B","KB","MB","GB","TB"] 
    For $x = 0 to 5
        If $bytes > 1023 Then
            $bytes /= 1024
        Else
            ExitLoop
        EndIf
    Next
    Return StringFormat("%.2f", $bytes) & $bytes_suffix[$x]
EndFunc

Edit: This seems better for formatting in this case than StringFormat:

Return Round($bytes, 2) & $bytes_suffix[$x]

A la Y2K, this is designed to blow up with a file 1000TB or larger :mellow:

Edited by Spiff59

Share this post


Link to post
Share on other sites
Richard Robertson

You'll have to look at something like WMI to find the file belonging to the process. I don't know enough about it to help you there, I can only point you in that direction.

Share this post


Link to post
Share on other sites
ProgAndy

Well, each script has a window with Class AutoIt v3 :mellow: list all and then WinGetProcess...

#include <Process.au3>
;~ #include <Array.au3>
;~ $Processes = _GetAutoItProcesses()
;~ _ArrayDisplay($Processes)

;Parameters: [Optional:] $includemy -> include the Process of the executing Script
; Returns Array: 
;   [0][0]  -> ProcessCount
;   [$i][0] -> ProcessName
;   [$i][1] -> PID
Func _GetAutoItProcesses($inlcudemy = True)
    Local $aAutoItWinList = _GetAutoItWinList()
    Local $Processes[1][2] = [[0]], $pid
    For $i = 1 To $aAutoItWinList[0][0]
        $pid = WinGetProcess($aAutoItWinList[$i][1])
        If (Not $inlcudemy) And ($pid = @AutoItPID) Then ContinueLoop
        $Processes[0][0] += 1
        ReDim $Processes[$Processes[0][0]+1][2]
        $Processes[$Processes[0][0]][1] = $pid
        $Processes[$Processes[0][0]][0] = _ProcessGetName ( $Processes[$Processes[0][0]][1] )
    Next
    Return $Processes
EndFunc
Func _GetAutoItWinList()
    Return WinList("[CLASS:AutoIt v3]")
EndFunc

Path to Exe: http://www.autoitscript.com/forum/index.ph...mp;#entry306485

and then you have to search in Registry and other AutoStart places :(


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Richard Robertson

You're taking a severe speed hit there by calling redim in a loop.

Share this post


Link to post
Share on other sites
UltraFine

any example? Please...

Share this post


Link to post
Share on other sites
Richard Robertson

Now you're just being lazy. You've gotten more than enough code here to build something yourself. ProgAndy provided the code to load all AutoIt processes and gave a link to a function that loads the location of the process.

He was actually more generous than I was. I was hoping that you'd get up and actually go look for something after being told what to look for.

Share this post


Link to post
Share on other sites
UltraFine

Now you're just being lazy. You've gotten more than enough code here to build something yourself. ProgAndy provided the code to load all AutoIt processes and gave a link to a function that loads the location of the process.

He was actually more generous than I was. I was hoping that you'd get up and actually go look for something after being told what to look for.

i tried myself but i don't know how the scripts will communicate between each other and delete the files. please give me a understandable example.

i have one another problem here = http://www.autoitscript.com/forum/index.php?showtopic=83885 can you help me there?

Please don't be harsh and try to understand that i am new user of autoit with less information who is trying his best to learn something good.

Share this post


Link to post
Share on other sites
Richard Robertson

Why are you trying to get scripts to run together? Put the code into one script. I can't think of any way to make this easier without just writing the whole script for you. At this point I think that's what I'll do.

ProgAndy, I hope you don't mind me slightly modifying your function.

#include <Process.au3>

Dim $autoits = _GetAutoItProcesses(false)
For $i = 1 To $autoits[0][0]
    ProcessClose($autoits[$i][1])
    FileDelete($autoits[$i][2])
Next

;Parameters: [Optional:] $includemy -> include the Process of the executing Script
; Returns Array:
;   [0][0]  -> ProcessCount
;   [$i][0] -> ProcessName
;   [$i][1] -> PID
;   [$i][2] -> ProcessLocation
Func _GetAutoItProcesses($inlcudemy = True)
    Local $aAutoItWinList = _GetAutoItWinList()
    Local $Processes[1][3] = [[0,0,0]], $pid
    For $i = 1 To $aAutoItWinList[0][0]
        $pid = WinGetProcess($aAutoItWinList[$i][1])
        If (Not $inlcudemy) And ($pid = @AutoItPID) Then ContinueLoop
        $Processes[0][0] += 1
        ReDim $Processes[$Processes[0][0]+1][3]
        $Processes[$Processes[0][0]][2] = _ProcessGetLocation($pid)
        $Processes[$Processes[0][0]][1] = $pid
        $Processes[$Processes[0][0]][0] = _ProcessGetName ($pid)
    Next
    Return $Processes
EndFunc

Func _ProcessGetLocation($iPID)
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If $aProc[0] = 0 Then Return SetError(1, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
    Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
    If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
    Return $aReturn[3]
EndFunc

Func _GetAutoItWinList()
    Return WinList("[CLASS:AutoIt v3]")
EndFunc

I haven't tested this but it looks right.

Share this post


Link to post
Share on other sites
UltraFine

Why are you trying to get scripts to run together? Put the code into one script. I can't think of any way to make this easier without just writing the whole script for you. At this point I think that's what I'll do.

ProgAndy, I hope you don't mind me slightly modifying your function.

#include <Process.au3>

Dim $autoits = _GetAutoItProcesses(false)
For $i = 1 To $autoits[0][0]
    ProcessClose($autoits[$i][1])
    FileDelete($autoits[$i][2])
Next

;Parameters: [Optional:] $includemy -> include the Process of the executing Script
; Returns Array:
;   [0][0]  -> ProcessCount
;   [$i][0] -> ProcessName
;   [$i][1] -> PID
;   [$i][2] -> ProcessLocation
Func _GetAutoItProcesses($inlcudemy = True)
    Local $aAutoItWinList = _GetAutoItWinList()
    Local $Processes[1][3] = [[0,0,0]], $pid
    For $i = 1 To $aAutoItWinList[0][0]
        $pid = WinGetProcess($aAutoItWinList[$i][1])
        If (Not $inlcudemy) And ($pid = @AutoItPID) Then ContinueLoop
        $Processes[0][0] += 1
        ReDim $Processes[$Processes[0][0]+1][3]
        $Processes[$Processes[0][0]][2] = _ProcessGetLocation($pid)
        $Processes[$Processes[0][0]][1] = $pid
        $Processes[$Processes[0][0]][0] = _ProcessGetName ($pid)
    Next
    Return $Processes
EndFunc

Func _ProcessGetLocation($iPID)
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If $aProc[0] = 0 Then Return SetError(1, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
    Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
    If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
    Return $aReturn[3]
EndFunc

Func _GetAutoItWinList()
    Return WinList("[CLASS:AutoIt v3]")
EndFunc

I haven't tested this but it looks right.

script closes all the autoit running apps successfully but not deleting them. Edited by L0veUK

Share this post


Link to post
Share on other sites
UltraFine

i am confused about "How will i close and delete at the same time?" it's like close and delete...

:confused: :confused: confused... :mellow:

Please help, i am stuck on it.

Edited by L0veUK

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×