#175806 - 2007-04-30 08:28 AM
Detect running program?
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
How do i get KiX to detect a program if its running or not? and the display something to the user?
|
|
Top
|
|
|
|
#175816 - 2007-04-30 03:46 PM
Re: Detect running program?
[Re: Witto]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
He could always use the EnumProcess() UDF to enumerate what's running or to check for a specific process.
Assuming, of course, that he knows what process he's looking for.
|
|
Top
|
|
|
|
#175882 - 2007-05-02 09:45 AM
Re: Detect running program?
[Re: eriqjaffe]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
I know the prosess yes. So something i know at least The problem is i can't get the EnumProcess to work. Getting lots of errors. And don't understand all i need to place into it. Im just thrown into this and never programmed anything in my life.
Edited by daddster (2007-05-02 09:46 AM)
|
|
Top
|
|
|
|
#175890 - 2007-05-02 01:37 PM
Re: Detect running program?
[Re: Mart]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
Tnx a lot. Just what i needed
|
|
Top
|
|
|
|
#175954 - 2007-05-04 09:42 AM
Re: Detect running program?
[Re: daddster]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
When i run it now i get error: ERROR:unknown command [winmgmts:{impersonationLevel]!
And when i use Kix2EXE since i need to distribute the script it somehow always detect that the program is running. And i know it ain't. If i ; out the funktion to check for the running program whole script goes in compiled EXE mode as intended.
|
|
Top
|
|
|
|
#175956 - 2007-05-04 09:45 AM
Re: Detect running program?
[Re: daddster]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
$pid= EnumProcess("proxy.exe")
If $pid <> ""
If $debug = "yes"
MESSAGEBOX ("Program running", "Test")
EndIf
Run "c:\kix\kix2exe-v121-installer.exe
Exit
EndIf
Sleep 5
Function EnumProcess($exe, optional $terminate, optional $Computer)
DIM $winmgmts, $ExecQuery, $Process, $id, $getobject, $
If Not $computer $computer=@WKSTA EndIf
$winmgmts="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER"
Select
Case Val($exe)>0
$ExecQuery="select * from Win32_Process where ProcessId='$exe'"
$GetObject=GetObject($winmgmts).ExecQuery($ExecQuery)
For Each $Process In $GetObject
If $terminate $=$Process.Terminate EndIf
$EnumProcess = $Process.name
Next
$GetObject=''
Case VarType($exe)=8
$ExecQuery="select * from Win32_Process where Name='$exe'"
$GetObject=GetObject($winmgmts).ExecQuery($ExecQuery)
For Each $Process In $GetObject
If $terminate $=$Process.Terminate EndIf
$id=$Process.ProcessId
$EnumProcess = "$Id" + "|" + "$EnumProcess"
Next
$EnumProcess=Left($EnumProcess,Len($EnumProcess)-1)
$GetObject=''
Case 1
Exit 1
EndSelect
EndFunction
Edited by daddster (2007-05-04 01:34 PM)
|
|
Top
|
|
|
|
#175957 - 2007-05-04 09:45 AM
Re: Detect running program?
[Re: daddster]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
This is the one i use when i get the error
|
|
Top
|
|
|
|
#175959 - 2007-05-04 10:05 AM
Re: Detect running program?
[Re: Mart]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
is the code tags
;;;;;;;;;;;;;;;
; Utrulling av xxx til lokal maskin.
; Laget av xxx, 02.05.2007
;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;
; Om gammel Windows versjon eller Vista vises tekst og beskjed om at det må oppgraderes.
;;;;;;;;;;;;;;;
$debug = "yes"
If @DOS="4.0"
; OR @DOS="6.0"
MESSAGEBOX ("xxx støtter ikke ditt operativ system, vennligst kontakt lokal IT ansvarlig", "xxx", 48)
Exit
Endif
;;;;;;;;;;;;;;;
; Lager en variabel til hvor xxx filene ligger.
;;;;;;;;;;;;;;;
IF EXIST ("q:\xxx\xxx.exe")
$fildir = q:\xxx\
If $debug = "yes"
MESSAGEBOX ("filedir = q", "xxx")
EndIf
EndIf
If Exist ("h:\xxx\xxx.exe")
$fildir = h:\xxx\
If $debug = "yes"
MESSAGEBOX ("filedir = h", "xxx")
EndIf
EndIf
If Exist ("p:\xxx\xxx.exe")
$fildir = p:\xxx\
If $debug = "yes"
MESSAGEBOX ("filedir = p", "xxx")
EndIf
EndIf
;;;;;;;;;;;;;;;
; Funksjon for å se om xxx kjører
;;;;;;;;;;;;;;;
Break on
$pid= EnumProcess("xxx.exe")
If $pid <> ""
If $debug = "yes"
MESSAGEBOX ("xxx kjører funksjon", "xxx")
EndIf
Run "%programfiles%\xxx\xxx.exe"
Exit
EndIf
Sleep 5
Function EnumProcess($exe, optional $terminate, optional $Computer)
DIM $winmgmts, $ExecQuery, $Process, $id, $getobject, $
If Not $computer $computer=@WKSTA EndIf
$winmgmts="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER"
Select
Case Val($exe)>0
$ExecQuery="select * from Win32_Process where ProcessId='$exe'"
$GetObject=GetObject($winmgmts).ExecQuery($ExecQuery)
For Each $Process In $GetObject
If $terminate $=$Process.Terminate EndIf
$EnumProcess = $Process.name
Next
$GetObject=''
Case VarType($exe)=8
$ExecQuery="select * from Win32_Process where Name='$exe'"
$GetObject=GetObject($winmgmts).ExecQuery($ExecQuery)
For Each $Process In $GetObject
If $terminate $=$Process.Terminate EndIf
$id=$Process.ProcessId
$EnumProcess = "$Id" + "|" + "$EnumProcess"
Next
$EnumProcess=Left($EnumProcess,Len($EnumProcess)-1)
$GetObject=''
Case 1
Exit 1
EndSelect
EndFunction
;;;;;;;;;;;;;;;
; Oppretter xxx Directory i Program filer mappen uavhengig av OS språk.
; NB !!! VIRKER IKKE PÅ VISTA ENDA !!!
;;;;;;;;;;;;;;;
; If $debug = "yes"
; MESSAGEBOX ("Lage fildir", "xxx")
; EndIf
;CD %programfiles%
;MD "xxx"
;;;;;;;;;;;;;;;
; @DOS=5.0 er Windows 2000, @DOS=5.1 er Windows XP, @DOS=5.2 er Windows 2003, @DOS=6.0 er Windows Vista
; Speiler mappen på serveren ut på klientmaskin. I silent mode.
; NB !!! VIRKER IKKE PÅ VISTA ENDA !!!
;;;;;;;;;;;;;;;
MESSAGEBOX ("Oppgradering pågår. Vennligst Vent.
xxx vil starte automatisk når oppgradreingen er ferdig", "xxx Oppgragering", 64, 5)
If $debug = "yes"
MESSAGEBOX ("Sjekke Windows versjon og kopiere", "xxx")
EndIf
If @DOS="5.0" OR @DOS="5.1" OR @DOS="5.2" OR @DOS="5.3" OR @DOS="6.0"
If Exist ("q:\xxx\xxx.exe")
Shell 'ROBOCOPY q:\xxx\distribusjon\ "%programfiles%\xxx\ /MIR /R:1 /W:1'
Else
If Exist ("p:\xxx\xxx.exe")
; Shell 'ROBOCOPY p:\xxx\distribusjon\ "%programfiles%\xxx /MIR /R:1 /W:1'
Shell 'ROBOCOPY p:\xxx\distribusjon\ c:\testdir\xxx\ /MIR /R:1 /W:1'
Else
If Exist ("H:\xxx\xxx.exe")
Shell 'ROBOCOPY h:\xxx\distribusjon\ "%programfiles%\xxx\ /MIR /R:1 /W:1'
EndIf
EndIf
;;;;;;;;;;;;;;;
; Funksjon for laging av Shortcut.
;;;;;;;;;;;;;;;
If $debug = "yes"
MESSAGEBOX ("shortcut", "xxx")
EndIf
function WshShortCut($path,$targetpath,optional $arguments,optional $startdir,optional $iconpath,optional $style)
dim $shell,$shortcut
$shell=createobject("wscript.shell")
if $shell
$shortcut=$shell.createshortcut($path)
if $shortcut
$shortcut.targetpath=$targetpath
if $arguments
$shortcut.arguments=$arguments
endif
if $startdir
$shortcut.workingdirectory=$startdir
endif
if $iconpath
$shortcut.iconlocation=$iconpath
endif
if $style
$shortcut.windowstyle=$style
endif
$shortcut.save
$shortcut=0
endif
$shell=0
endif
exit @error
endfunction
WshShortCut("%USERPROFILE%\Desktop\xxx.lnk","$fildir\xxx.EXE")
EndIF
;;;;;;;;;;;;;;;
; Avslutte med å starte xxx
;;;;;;;;;;;;;;;
If $debug = "yes"
MESSAGEBOX ("starte xxx", "xxx")
EndIf
run "%programfiles%\xxx\xxx.exe"
Here u go 
Edited by daddster (2007-05-04 10:11 AM)
|
|
Top
|
|
|
|
#175961 - 2007-05-04 10:20 AM
Re: Detect running program?
[Re: Mart]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
we want to update programfiles on local computer from a server, with the Robocopy /mir function. The Function to check running program was so it would not copy when the program is in use, since its and oracle database u can have many open instances. so something like:
Copy to local server -> when user start program it starts script then program -> the script check if program is running -> if running not do anything but start a new instance and that will result in an error from that. -> if not running then copy files from local server to local computer and start them from there at the end.
|
|
Top
|
|
|
|
#175969 - 2007-05-04 12:30 PM
Re: Detect running program?
[Re: daddster]
|
daddster
Fresh Scripter
Registered: 2007-04-18
Posts: 15
|
Found the error Called the executable file same as the check if running file. Can i in that function also ask on description?
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 764 anonymous users online.
|
|
|