c# - How to prevent to run an exe from two different computers -


i have form application written in c#. put exe server in company reached computers. need find solution know if exe running in another computer.

so when 1 computer tries run application should check if computer running same app.

i found in working fine if same computer runs exe 2 times.

here

have file writable users on server. when application starts, open file write , keep reference stream in static field. when application closed, close stream. if application crashes or network down, file automatically released os.

for instance, in program.cs :

private static stream lockfile; public static void main() {   try   {     try     {       lockfile = file.openwrite(@"\\server\folder\lock.txt");     }     catch (ioexception e)     {       int err = system.runtime.interopservices.marshal.getlastwin32error();       if (err == 32)       {         messagebox.show("app running on computer");         return;       }       throw; //you should handle properly...     }      //... run apps   }     {     if (lockfile != null)       lockfile.dispose();   } } 

based on


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -