English
Source / code snippets

Doppelstart Instanzen several Programmstarts prevent

 

Michael
Wodrich
because I one Weilchen needed, it from the Ärmel To shake...
!
Keywords: several Programmaufrufe/several Instanzen/Mehrfachaufruf blocken/prevent
Def $AppTitle "Mein Programmtitel"
Declare WindowHandle&
Window 100,100 - %Maxx-300,%Maxy-300
on this place ought to yet no cover
definiert his, otherwise GEHTS schief
WindowHandle& = FindWindow($AppTitle)

if WindowHandle& <> 0

    print "Huch, i'm already there."
    print "Nach Tastendruck becomes on The 1. instance umgeschaltet."
    waitinput
    ShowWindow(WindowHandle&, 1)  possibly verstecktes Window again enable
    SetWindowPos WindowHandle& = 100,100 - %Maxx-300,%Maxy-300; 0  in whom Vordergrund fetch
    end  ...and The 2. instance terminate

else

    print "Ich be einmalig."

endif

first to the Check becomes the Window Title staid.
Window Title $AppTitle
waitkey
end

Best wishes
Michael Wodrich
 
Programmieren, das spannendste Detektivspiel der Welt.
09/07/06  
 




Michael
Wodrich
and to Info of TS-Soft another Mutex-Variante from the Phorum of Ragnar Rehbein.
Def CreateMutex(3) !"KERNEL32","CreateMutexA"
def GetLastError(0) !"KERNEL32.dll","GetLastError"

proc check_doppelstart    return is 0 if doppelstart vorliegt

    Parameters name$           Mutexname
    declare mutex&,error&
    name$  = translate $(name$ ,"\","/")   Have I somewhere red, that / prohibited are
    mutex& = CreateMutex(0,1,addr(name$))
    error& = GetLastError()
    print error&

    if error& = 183

        return 0

    endif

    return 1

endproc

print check_doppelstart("test")
print check_doppelstart("test")
print check_doppelstart("c:\testAaaaaaaaaaaaaaaaaa")
print check_doppelstart("c:\testAaaaaaaaaaaaaaaaaa")
waitinput

Gibts yet further Opportunities?

Best wishes
Michael Wodrich
 
Programmieren, das spannendste Detektivspiel der Welt.
09/07/06  
 



[quote:1532fb2073=Michael Wodrich]
Gibts yet further Opportunities?

Best wishes
Michael Wodrich[/quote:1532fb2073]
clear
CreateSemaphore(...) z.B. findeste somewhere in MSDN or PSDK
But the Mutex not unähnlich. for the Mutexstring use I mostly a GUID.
 
09/07/06  
 



the Simplest:
 $u pipe.pcu = pipe.
declare pipe&
case pipe.is("odoku") : end
pipe&:=pipe.create("odoku")
cls
waitinput
pipe.close pipe&
 
09/07/06  
 




Uwe
''Pascal''
Niemeier
Hello people!

here another Possibility by FileMapping.
thereby won't only the new instance automatically exits, separate too The ongoing instance by Usermmessage informed, so tappt im dunkeln itself possibly into Vordergrund settle can.
The principle can so strain, that possible Parameter, The with Calling the 2. instance transfer go, on The 1.instance weitergereicht go.
!
 $H Messages.ph
 $H windows.ph
declare MapHandle&,ViewHandle&
MapHandle&=~OpenFileMapping(~FILE_MAP_ALL_ACCESS,0,"Programm 1.1")

if MapHandle&--MappedFile present (contains %hwnd of already laufender instance)

    ViewHandle&=~MapViewOfFile(MapHandle&,~FILE_MAP_ALL_ACCESS,0,0,32)
    messagebox("Programm runs bereits","Meldung",0)
    sendmessage(long(ViewHandle&,0),5066,0,0)--Message on 1. instance
    ~UnmapViewOfFile(ViewHandle&)
    end
    else--These Instant is The first > MappedFile lay out!
    MapHandle&=~CreateFileMapping($FFFFFFFF,0,~PAGE_READWRITE,0,32,"Programm 1.1")
    ViewHandle&=~MapViewOfFile(MapHandle&,~FILE_MAP_WRITE,0,0,32)
    window 100,100-600,400----first here becomes the Window created!!
    long ViewHandle&,0=%hwnd--lever in MappedFile write

endif

usermessages 16----WM_CLOSE
usermessages 5066--some worth, the high enough is for selbstdefinierte Msg.

while 1------------Eingabeschleife

    waitinput
    case %umessage=16:break--end

    if %umessage=5066--------User Message of new instance

        shownormal
        setactivewindow(%hwnd)
        setfocus(%hwnd)
        print "Aktivierung through new Instanz"

    endif

    ----further Eingabeabfragen

endwhile

--ought to with end access go:
~UnmapViewOfFile(ViewHandle&)
~CloseHandle(MapHandle&)

HTH
Pascal
 
09/07/06  
 



good idea! and here the same only kürzer and without nötige Headerfiles:
 
09/07/06  
 




Jac
de
Lad
I find The best method is still by Mutex:
Def CreateMutex(3) !"KERNEL32","CreateMutexA"
Def GetLastError(0) !"KERNEL32","GetLastError"
CreateMutex(0,1,"PROGRAMM")
case Equ(GetLastError(),183):end

Jac
 
Profan² 2.6 bis XProfan 11.1+XPSE+XPIA+XPRR (und irgendwann XIDE)
Core2Duo E8500/T2250, 8192/1024 MB, Radeon HD4850/Radeon XPress 1250, Vista64/XP
09/07/06  
 




Ragnar
Rehbein
I use as mutexnamen (or. with filemapping) meanwhile with almost all programmen par$(0), means whom programmnamen inkl. way.
but pay attention, that the backslsh raustranslatet becomes!
I have almost always The demand, that one Program not twice launched go can, one start unterschiedlicher konfigurationen from different verzeichnissen or. through umbenenn the program should possible his.
for terminalserverumgebungen is yet the prefix Global and Local interestingly (here must the backslash beiben!).
so can z.b. prevented go, that one Program in several sessions carryed out becomes (z.b. a einplatzlizenz).

r.r.
 
09/08/06  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

9.667 Views

Untitledvor 0 min.
RudiB.08/28/22
RICOSCH05/09/19
AndreasS12/26/18
PETER195607/18/18
More...

Themeninformationen



Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie