VS 2013 Use VB.net form on one Computer Only-VBForums
Results 1 to 15 of 15

Thread: Use VB.net form on one Computer Only

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2010
    Posts
    232

    Use VB.net form on one Computer Only

    Hi there,

    I have an application which is shared on network for 7 users.
    There is a form which I want to use by any one user only at single time. If any other user open the form he should receive a message that this form is already opened by user "ABC". Once ABC closed the form then any other user can open for same form.

    Please let me know to how to check that a specific form is opened by user (name) on network.
    There is only one application file on server and it is shared to 7 users.

    Thanks
    Ladak

  2. #2
    Lively Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    75

    Re: Use VB.net form on one Computer Only

    First thing thats springs to mind is.

    You could use a file on the net work to hold the status of that form.

    The applicaton could then check and update the status.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2010
    Posts
    232

    Re: Use VB.net form on one Computer Only

    Thanks Goggy for your reply,

    Same thing i have in mind to create a table and save status of form, it is open or closed, if open then don't allow other user to use it otherwise ok.
    But I am looking for some solution without table or status of that form, is there any direct way to check the form if open on network or not.

    Thanks
    Ladak

  4. #4
    Lively Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    75

    Re: Use VB.net form on one Computer Only

    Well not that i'm aware of, but maybe a real Guru will prove me wrong :-)
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,218

    Re: Use VB.net form on one Computer Only

    You may be able to see the application status by get process by id or by name.
    It's like finding if it is open.
    Please note that I'm not sure about the remote process get. There may be network issues that prevent that. You may need some extra manip by the admin.
    Here is a brief example on byyname:

    https://msdn.microsoft.com/en-us/lib...code-snippet-2
    Slow as hell.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,572

    Re: Use VB.net form on one Computer Only

    All that's going to tell you is if the process is running or not... it's not going to tell you if a form/window within that process is open. The simplest solution is going to be setting a flag in a file. That's also going to be the simplest solution to clean up from if somethign goes wrong - such as the computer of the user that had the form open crashes and leaves the flag turned on. If it's in a file, it simple enough to reset or delete. If it's in a database, then you have to open the database and make the necessary adjustments. Do you need to keep track of who had it open when, or just that it is open currently?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,550

    Re: Use VB.net form on one Computer Only

    You're going to have to use a file or some other kind of persistence, and it will never be 100% perfect. Windows Forms applications didn't have this use case in mind at all when the framework was designed.

    The only relatively guaranteed way to get this is with a web app, even then I feel like it's a race. It's much easier to use the facilities in types like DataSet to detect and deal with the problems that happen if 2 users edit the same data simultaneously.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  8. #8
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,218

    Re: Use VB.net form on one Computer Only

    Ah.
    Form. OK I was under the impression that you need to know if the application is open or not.
    Yes a file.
    Also there might be a way but I'm getting very rusty at windows API that you could get the address of the application and then find the sprawn forms of the application.
    Not the least sure that this can works on networks. Ahh "findwindowEX" was it?I think so.
    Hmmm yes my suspicions where true, you cannot run this remotely.

    OK, so , you could install a service app or more preferable a web service along with the client app in each machine that will communicate with the application and give information if the appreciation has that form open (the application itself will give that info when the form opens up, will call the service and the service will maintain in memory, the open form and the workstation that is open).
    Every instance on each machine will call the service to see if the status of the application form.
    OR, you can install a central web app that every workstation that is using the application will communicate to and get info about the applications status.
    That, would be a good idea if you want to further expand the "communication" between the different instances of you application to more than just a form open close.

    So as this is, on a scale of 100, a 20% difficulty and the file is, on a scale of 100% again, a 1% difficulty, you could either go with the file or go for pro for extra education and do the service thingy.
    Slow as hell.

  9. #9
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,550

    Re: Use VB.net form on one Computer Only

    20% is a hopelessly optimistic assessment of how difficult it might be to "just ask".

    The closest you can reasonably come to enumerating the open forms of a particular process would probably be to get its child window handles, then poke at them. In an actual API project, this might be sufficient since you'd have to register a unique window class for each form. But in .NET, that bit is done by generated code and I'm not sure the window class names generated are 100% predictable.

    But even if you overcome that hurdle, you can't use API to inspect the processes of other machines. For that, you have two choices: WMI or writing some kind of server that runs on all client machines. Now you have all the problems of networking to deal with.

    But even if you overcome that hurdle, you have to solve another problem: "How do I tell which machines are on the network, and what subset of those could potentially be running my application and displaying this form?" And there's always the chance that while you're checking the several machines on the network, you ask Machine A an instant before it opens the form, then by the time you finish asking machine Z, machine A has the form open and you don't know.

    So.

    You could write a web application. That architecture requires every client to ask a server for a page to do anything. You can design a page with this logic:
    • Insert a row into a table indicating this user has requested the page with a timestamp.
    • Check if the table has more than one row.
    • If there are two rows, and this user isn't the earliest request:
      • Remove the user's row.
      • Send back a page indicating another user is using the page.
    • If there is only one row, or this user is the earliest request:
      • The user is allowed to use this page, send back the appropriate page.


    It doesn't have to be a web application, but what's important here is key to solving the problem if you want to do it via Winforms: you have to have a central server that is asked for permission to view the page. The only sane way to handle the problem is if ONE machine is responsible for access.

    Or.

    You can identify WHY you want only one user at a time to access a page and try to address that problem. Maybe the issue is, "It's a page for editing appointments and I don't want two users to make different edits to the same one". Handling that is built-in to most data access frameworks. For example, if you're using DataAdapter/TableAdapter, the Update() call will notice this and mark the row as having an error. It keeps a copy of the original data, the data it found, and the data the user edited, so you can display all three and let the user choose what is correct.

    Neither of those solutions are "simple", but they're easier than trying to implement a distributed algorithm for enumerating open forms.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,622

    Re: Use VB.net form on one Computer Only

    The solution to this problem actually should be very simple. Lock the file whenever an instance of the Form in question is opened in any instance of the app on the network. Unlock it when it is closed. Then use exception handlers to determine when the file is locked. All this assumes you're using mapped drives of course.

    The best solution to this as far as I'm concerned is to not use a file. Use a database engine designed for multiple concurrent users. There should be free lightweight versions of SQL Server or other database engines available online, which you can use.

    If this file is special in a way that cannot be accurately represented by a relational database, my solution would be to design a second program that would act as a server. It would communicate using Winsock and I would designed this application to handle concurrency as I see fit. The client application, the one that the users would be running would communicate with this server app when it needs something from the file or it needs to write to the file. The communication between client and server can be used to determine whatever you want about the state of other client instances on the network and/or the state of the server itself. You will have to freedom to communicate whatever you want about anything you want, including which Forms in which applications open. This freedom comes at the price of having to develop everything yourself. It's not that difficult, only a little time consuming.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  11. #11
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,033

    Re: Use VB.net form on one Computer Only

    There is a form which I want to use by any one user only at single time.
    I have not really read the other replies, but a simple and dirty solution would simply be check and see if its open! If its all used from the same .EXE for the application, you can simply use a setting and change it back and forth to true and false based on the form state. If the form is in use, set it to false, and return the access to false.

    You can use a database if you perfer, but the setting will do the same thing. When the form is launched change the setting value and set it back to default of True (which means the next person can access) on close. You could use anything and check to see if its in the setting "Open" "Close" etc. will work too, I just used True/False here as an example for the situation.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,572

    Re: Use VB.net form on one Computer Only

    I have not really read the other replies, but a simple and dirty solution would simply be check and see if its open! If its all used from the same .EXE for the application, you can simply use a setting and change it back and forth to true and false based on the form state. If the form is in use, set it to false, and return the access to false.
    You probably should have read the replies... it's not that simple. If *I* open the form, then *you* cannot ... that's what the OP is after. Given multiple users on the network, all using the app... there's no way built-in way for anyone to know if someone else has opened the form. It requires talking to something external.

    -tg


    Edit - I see what you mean... I thought of that too... problem is settings are either User or Application-scoped. Application-scoped settings are read-only... and user settings would be, well, on the users's machine... so that's out too...
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,033

    Re: Use VB.net form on one Computer Only

    Quote Originally Posted by techgnome View Post
    You probably should have read the replies... it's not that simple. If *I* open the form, then *you* cannot ... that's what the OP is after. Given multiple users on the network, all using the app... there's no way built-in way for anyone to know if someone else has opened the form. It requires talking to something external.

    -tg


    Edit - I see what you mean... I thought of that too... problem is settings are either User or Application-scoped. Application-scoped settings are read-only... and user settings would be, well, on the users's machine... so that's out too...


    He said it was using the same application, I am assuming being launched its the same Executable, I mentioned this in my reply, therefore if you store it in a database or even the settings, you should be able to read it and find out if its True or false
    If its all used from the same .EXE for the application, you can simply use a setting and change it back and forth to true and false based on the form state. If the form is in use, set it to false, and return the access to false.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  14. #14
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,550

    Re: Use VB.net form on one Computer Only

    I guess this part is relevant:
    There is only one application file on server and it is shared to 7 users.
    I still hold the opinion there is no "simple" solution to doing this with a WinForms app, and it's not exactly trivial with a web app, either. But web-style apps are more well-structured for it. Niya's not far off either, the main thing is you don't want 7 clients trying to build a Peer-to-Peer network if you can avoid it. That's complex and hard to do. It's much easier to build a client-server relationship.

    It's still not an easy task, and Application Settings aren't designed for this use case so there are going to be race conditions. It's possible Windows even keeps a temporary copy of some of the files on a local machine instead of on the network: in that case all users would have a separate copy of the settings and it won't work at all.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  15. #15
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,033

    Re: Use VB.net form on one Computer Only

    hmm, in that case you would need a shared network file, such as a xml or database, either one, and you would have to make sure windows doesn't use any sort of cache, so in that case if the settings thing wouldn't work, it would be complicated, or at least it sounds complicated. This is one of those there is nothing easy enough to say for sure solutions, but the database would be the next best thing, you can accomplish similar "1 user" tasks e.g. logging in only on 1 computer through a VB.NET application via a database etc.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width