Sign in to follow this  
Followers 0
DEVIOUZ

If If Not ProcessExists From specific location..?

16 posts in this topic

is there any way to use this code "If Not ProcessExists "like this: If Not ProcessExists("c:\folder\smss.exe") Then Run("c:\folder\smss.exe")

I need to check if a specific process is running from a specific location and if its not then it needs to be started.

but the process is the same name as an already running process so it doesn't seem to work..

and I don't want to rename my process to something other than what it is (smss.exe) because that way no one can end my process via taskmanager.

so is what im asking possible at all..??

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

Check this UDF:

$PathIsProcess = _ProcessPathExists("c:\folder\smss.exe")
MsgBox(0, '', $PathIsProcess & @LF & @extended)

;===============================================================================
;
; Function Name:    _ProcessPathExists()
; Description:      Check if given path is an existing process.
;
; Parameter(s):     $sPath - Path of executable to check.
;
; Requirement(s):   AutoIt v3.2.8.1 or higher.
;                   Kernel32.dll (included with Windows)
;                   Psapi.dll (included with most Windows versions)
;
; Return Value(s):  On Success - Returns PID of executable process, @extended include total number of similar processes runing.
;                   On Failure - Returns False and sets @Error to:
;                                                               1 - Given path not exists.
;                                                               2 - Process with name of the executable not exists.
;                                                               3 - Error to open Psapi.dll.
;                                                               4 - Error to call Kernel32.dll.
;                                                               5 - Unknown/other error related to DllCalls.
;
; Author(s):        G.Sandler (a.k.a CreatoR)
;
;===============================================================================
Func _ProcessPathExists($sPath)
    If Not FileExists($sPath) Then Return SetError(1, 0, False)
    
    Local $sPathName = StringRegExpReplace($sPath, "^.*\\", "")
    Local $aProcList = ProcessList($sPathName)
    
    If Not ProcessExists($sPathName) Then Return SetError(2, 0, False)
    Local $iUbound = UBound($aProcList)-1
    
    Local $hPsapi_Dll = DllOpen('Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(3, 0, False)
    
    Local $aProc, $aPath
    Local $vStruct = DllStructCreate('int[1024]')
    
    For $i = 1 To $iUbound
        $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $aProcList[$i][1])
        If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(4, 0, False)
        
        DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
            'hwnd', $aProc[0], _
            'ptr', DllStructGetPtr($vStruct), _
            'int', DllStructGetSize($vStruct), _
            'int*', 0) 
        
        $aPath = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
            'hwnd', $aProc[0], _
            'int', DllStructGetData($vStruct, 1), _
            'str', '', _
            'int', 2048)
        
        If IsArray($aPath) And $aPath[3] = $sPath Then
            DllClose($hPsapi_Dll)
            Return SetExtended($iUbound, $aProcList[$i][1])
        EndIf
    Next
    
    DllClose($hPsapi_Dll)
    Return SetError(5, 0, False)
EndFunc

Edit: changed int_ptr to int* (so it will work with latest AutoIt version).

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Woot, now the guy can finish his l33t virus...


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

im not making a viruz.. why u saa that 4..??

Anyway thanks for the code MsCreatoR, but when i run it in scite editor it it gives me some message box that only says:

False

0

the process c:\folder\smss.exe is not running when i run the script, and the c:\folder\smss.exe doesnt get executed..??

do i need to edit the code at all or what exactly..??

Sorry, I'm new to autoit so please bare with me..

Share this post


Link to post
Share on other sites

im not making a viruz.. why u saa that 4..??

-snip-

Sorry, I'm new to autoit so please bare with me..

So enlight us what is it you want to accomplish here ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

So enlight us what is it you want to accomplish here ?

i did in my first post...

Share this post


Link to post
Share on other sites

I thought these forums were for getting help & support for using Autoit,

I'm just asking for a lil help here...

why do I have to get accused of making a virus, then giving th 3rd degree about it.

I just want to make a simple autoit app to check if a specific process is running from a specific location and if its not then it gets started.

how is that a virus...??

Share this post


Link to post
Share on other sites

I thought these forums were for getting help & support for using Autoit,

I'm just asking for a lil help here...

why do I have to get accused of making a virus, then giving th 3rd degree about it.

I just want to make a simple autoit app to check if a specific process is running from a specific location and if its not then it gets started.

how is that a virus...??

You know... its really simple. Add the way you asked the question and the "words" you use together with your membername and you get as result "suspicious".

The way you answer the questions asked really only confirm the feelings.

Now, don't get me wrong here, I am not accusing you of anything (yet)..

Its your choise what you ask and how you reply, but I won't help you unless I get a better feeling for what you truly want here.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

nuff wif all teh damn hatin already.. sheesh

discriminating on me mow jus cuz of my name wtf.. so should i change it then to "carebearwuss143" will that make you happy. LOL..

sorry if you take my posts the wrong way, but i just came here to get some help not to be interrogated.

so in what way did i ask my question, that makes yall think im makin a viruz..??

look You know... its really simple, as i've asked before. I just want to make a simple autoit app to check if a specific process is running from a specific location and if its not then it gets started.

sorry, but i don't see anything malicious about that do you..

you need a better feeling for what I truly want here..??

how many times do i have to say it..??

What I truly want is to make a simple autoit app to check if a specific process is running from a specific location and if its not then it gets started."

Share this post


Link to post
Share on other sites

You seem to have a problem reading my posts. Also writing normal English so people like myself are able to understand you seems to be difficult for you.

Anyways ... as said: do as you please ... :D


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

look man i aint got no beef with you nore anyone else in here ok.

can we just put all this BS aside and get back on topic here..

what do you need me to do to get some help..??

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

As long as I don't understand the purpose of your question I won't be helping you.

You could have made it sooo much easier by just telling us about what you really want to do in stead of getting in your high horse and starting the "wtf language bs".

Now why on earth would you want to know if smss.exe is started from folder "x" and when it isn't start it from there as well ?

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I already told you what i wanted to do, cmon man

im just defending myself from these virus accusations..

smss.exe is just a security app i use, and i don't want anyone else that uses my PC to be able to close it, so if they do, this auto it app will auto reopen it upon detecting it not running..

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I already told you what i wanted to do, cmon man

im just defending myself from these virus accusations..

smss.exe is just a security app i use, and i don't want anyone else that uses my PC to be able to close it, so if they do, this auto it app will auto reopen it upon detecting it not running..

Read the below article and just shut up being a whiner about being accused of something, maybe you realize why you sound (and keep on sounding) suspicious:

http://www.neuber.com/taskmanager/process/smss.exe.html

*I am done with you and this thread is as well.. click*

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


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