Jump to content

Avoid starting two programs


Shaarad
 Share

Recommended Posts

Hello everyone...I am facing little difficulty with programming...

I want to create a program which will avoid running itself if it is already running and will exit, but will run normally if it is not running previously....

maybe there is a command for this but i didn't find it so I posted for help...

any help will be greatly appriciated !

Eagerly waiting for your response.... :graduated:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

  • Moderators

Shaarad,

Look at _Singleton in the Help file. :graduated:

Although I tend to use WinExists with title and text parameters myself. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ProcessExists can be used too.:graduated:

Not ideal because you can rename an exe.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Not ideal because you can rename an exe.

that would also cancel out WinExist(), because Window Titles can be renamed as well.

Edit: It all depends on what the OP needs this for. If to insure he does not open the same application twice, than any of the options will work. Otherwise, If he is trying to block his users from running more than once instance, than _Singleton appears to be the best choice, due to the other ways can be deterred.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

I think WinExists won't do because my program doesn't show any window as such.... :(

_Singleton can help. I'll see and let you guys know my status. Thanks all for your replies!

:graduated:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

Realm WinExist() would work because the end user can't change the window title.

Shaarad even though you didn't create a window AutoIt still creates a hidden window on it's on. You can set that window's title with the function AutoItWinSetTitle().

[size="1"]Please stop confusing "how to" with "how do"[/size]

Link to comment
Share on other sites

hey guys _singleton worked. The example given in the help file was exactly what I needed. :graduated:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

at the beginning of your script put

a check for a registry key and if it exists exit

if it doesnt exist write it and then continue the script...

at the end of your script put a regdelete

and if you got a gui put a regdelete before all exits....

you can check for process window title regwrite and even write a @tempdir appname.lock and check for that...

you can make so many checks your end user cannot bypass if you wish....

i hope i helped good luck,

Link to comment
Share on other sites

  • Developers

at the beginning of your script put

a check for a registry key and if it exists exit

if it doesnt exist write it and then continue the script...

at the end of your script put a regdelete

and if you got a gui put a regdelete before all exits....

you can check for process window title regwrite and even write a @tempdir appname.lock and check for that...

you can make so many checks your end user cannot bypass if you wish....

i hope i helped good luck,

_Singleton() sounds a lot simpler and a lot less error prawn.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Realm WinExist() would work because the end user can't change the window title.

Deltaforce229,

You are correct, the 'common end user' would not figure out how to change the window title. Nor would the 'common end user' think about changing the title of an '.exe'. However, I still believe that _Singleton() is the best of the available options if your attempting to advert an above average end user from running multiple instances. With _Singleton() the end user, can change the title of an .exe and even the window title itself, but singleton will still be able to identify it as another instance of the said application.

Realm

Edit: The end user can change a window title, almost every basic syntax language that I know of offer ways to change window titles. AutoIt's very own WinSetTitle() can change another applications window title.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...