Results 1 to 20 of 20

Thread: check if app is running?

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    check if app is running?

    OK, I have my app stored on a network drive, and i'm continually making updates to it and having to recompile and overwrite the existing exe...

    How do I tell if someone on the network has the app running? Because I get errors that I can't overwrite the exe if someone is using the program. Is there a way to get the computer name that the app is running on? maybe even the users name?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    i'm not much of a network guru but you could put some code in your program that writes the user's computers that are accessing the exe to a text file and then deletes their entry when they close the app.

    that way you would always have a list of anyone who is using the app and if its empty you know that no-one is using it.

    just an idea
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Actually darre1 has a very good idea, but rather than a text file, I use a db table (Oracle, in my case). Specifically, I write back the user name, machine name, date/time the app opened, date/time they closed their session, and I log all trapped errors that occurred during their session (that makes it easier to understand when I get a call from someone saying "Hey Hack, your stinkin' program don't work.")

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    ok... that sounds like a good idea... now my next question...

    We run mostly Windows NT 4.0 workstations here... but some other workstations are available... how would you go about reading the name of the user logged into the workstation? I'm kind of a newbie so bare with me here... thanks in advance.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    2.  
    3. Private UserAccount As String
    4.  
    5. Private Sub GetUserAccount()
    6.  
    7.     Dim sBuffer As String
    8.     Dim lSize As Long
    9.    
    10.     sBuffer = Space$(255)
    11.     lSize = Len(sBuffer)
    12.     Call GetUserName(sBuffer, lSize)
    13.     If lSize > 0 Then
    14.         UserAccount = Left$(sBuffer, lSize - 1)
    15.     Else
    16.         UserAccount = vbNullString
    17.     End If
    18.    
    19. End Sub

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    As an after thought, in case you are interested, here is how to get the machine name.
    VB Code:
    1. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    2.  
    3. Private MachineName As String
    4.  
    5. Private Sub GetMachineName()
    6.     Dim sBuffer As String
    7.     Dim lSize As Long
    8.     sBuffer = Space$(255)
    9.     lSize = Len(sBuffer)
    10.  
    11.     Call GetComputerName(sBuffer, lSize)
    12.     If lSize > 0 Then
    13.         MachineName = Left$(sBuffer, lSize)
    14.     Else
    15.         MachineName = vbNullString
    16.     End If
    17.    
    18. End Sub

  7. #7
    Addicted Member Sibby's Avatar
    Join Date
    Feb 2001
    Location
    Milwaukee, WI *The United States of America*
    Posts
    144
    I do the same exact thing with my apps. The user name is writen to a DB table as well as the time they logged in. It then removes that record when they quit the program. But I take it a step further. I have a built in piece of code linked up to a timer event. Every minute it checks a boolean flag in the DB. If that flag happens to be true (set by me), the apps gives the user a warning and about 5 minutes before the app shuts itself down. In that time if they are doing something critical, they can give me a call and I can "terminate shutdown" by setting the flag back to FALSE. This has worked great for me...something to think about, it's actually not that tough to implement. Let me know if you need any help with that.

    Try this code though for grabbing the username (this is not mine, don't remember where I got it).

    VB Code:
    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
    2.  
    3. Public Function UID()
    4.     Dim sBuffer As String
    5.     Dim lSize As Long
    6.     Dim UName As String
    7.     Dim MError As String
    8.     sBuffer = Space$(255)
    9.     lSize = Len(sBuffer)
    10.     Call GetUserName(sBuffer, lSize)
    11.     If lSize > 0 Then
    12.         UName = Left$(sBuffer, lSize)
    13.     Else
    14.         UName = vbNullString
    15.     End If
    16.  
    17.     'I added this if statement.  It was returning a null character
    18.     'at the end of the string.  You may or may not need this
    19.     If Right(UName, 1) = Chr(0) Then
    20.         UID = Left(UName, Len(UName) - 1)
    21.     Else
    22.         UID = UName
    23.     End If
    24. End Sub
    If you can think it....you can code it....

  8. #8

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    you guys rock.

    Sibby, I'd love to see how you implement that, what kind of DB you use, etc. Anything you can give me would be appreciated.

    You can just email me if you want:

    my email

    or post here, either way would be fine.
    Last edited by ober0330; Jan 25th, 2002 at 04:08 PM.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  9. #9
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    There is a little drawback to this approach. If your app crashes, it will not remove the entry from the database for the person that just crashed.

  10. #10
    Addicted Member Sibby's Avatar
    Join Date
    Feb 2001
    Location
    Milwaukee, WI *The United States of America*
    Posts
    144
    You're right Serge, that can be a drawback. But that's why you have error trap the hell out of it so you don't have that problem . ober5861, I'll have to post the code for you on Monday. It's all at work and I'm at home now....

    "Everybody's workin' for the weekend!..."
    If you can think it....you can code it....

  11. #11
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Your crash sometimes is not entirely your code. It could be OS, like BSOD. You might have other programs running that might cause the problem.

  12. #12
    Addicted Member Sibby's Avatar
    Join Date
    Feb 2001
    Location
    Milwaukee, WI *The United States of America*
    Posts
    144
    Yeah you're right . I use that name login more as a guide. If I need to do an update for a certain app, I first look at the user log and see whos logged in. If it shows somebody is logged in I'll set the shutdown "toggle switch". Once everyone is out I then do my update. So regardless if they were logged in or not (crashed), everyone is now logged out of the program. I do my update then take then turn the switch off and check the log again. If anyone is still left on the list, I know they must have crashed at some point and I just delete them. I'm not saying it's fullproof, but for me it works 99% of the time.
    If you can think it....you can code it....

  13. #13
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    When I had a shared EXE on the network, I took a different approach. Instead of running the EXE from the network, they ran batch file (for example, MyProgram.bat), which copies the EXE to their local drive and fires the local version, Everytime I have to do an update, I replace the EXE with a new one, so the next time the user runs the program, their local EXE will be replaced with a new one.

    By the way, I like your Mr Roper (Norman Fell) avatar.

    Regards,

  14. #14
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    have it so when they start your app, if the text file or table (whichever your using) already asys that they are running your app, then don't write their computer name to it etc, but still remove it when they close the program.

    The other way is to get it to write 2 lines... One when they log on (run it) and another when they log off (close it), that way if it has two log ons for the same person (computer name) in a row, then you know that it crashed at some point, so you can remove the first one

    should work yes?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  15. #15
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    BTW

    Environ("UserName")
    Environ("ComputerName")

    Will also do the trick

  16. #16
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I once wrote a program that could check which users had a file in use, and send a message to these users. It only works on a NT network for files located on a server, and you need admin rights to use it. I used it a lot when I had to replace a program on the network.

    I will attach the project.

    PS, if you add a shortcut to this program in the SendTo directory, you can right click a file on the network, and send it to this program. It will then show the users who have opened the file.

  17. #17
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    Wow Frans C,

    that is awesome code! Just one question...

    is it possible to send a message to kick people out of the application rather than just listing them?

  18. #18
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You could use the NetFileClose api function for this. This would force the resource to be freed. Please note that this function just kicks the user out of the app, without proper closing it. The memory of the user's machine would not be properly cleared.
    That is the reason I didn't include it in the application. Instead I send a network message to the user's machine and hope they will listen.

    PS, you can always walk to the server, open control panel --> server and kick them out there.

  19. #19
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    Thanks very much for your help

  20. #20
    Addicted Member Sibby's Avatar
    Join Date
    Feb 2001
    Location
    Milwaukee, WI *The United States of America*
    Posts
    144
    Ok, Just pop a timer on your form and use the following code. Make the timer with a minute interval (value 60,000 I think).

    VB Code:
    1. Private Sub tmrMaint_Timer()
    2.     Static MessageFlag as Boolean
    3.  
    4.     If <boolean DB feild> Then
    5.         If Not MessageFlag Then
    6.             <show custom message to user>
    7.         End If
    8.         MessageFlag = True 'Set the flag so the message is only shown once
    9.         tmrMaint.Tag = tmrMaint.Tag + 1
    10.         If tmrMaint.Tag = 3 Then 'set the max tag value depending on how long you want the app to wait untill it shuts down
    11.             If <username is NOT equal to yours> Then 'add this if check so it doesn't log you out and you can monitor and see that all users are logged out.
    12.                 Unload <main form>
    13.             Else
    14.                 tmrMaint.Enabled = False 'if it is you, disable this timer
    15.             End If
    16.         End If
    17.     End If
    18.    
    19. End Sub

    Now, i attached a sample picture of the little utility form I added to my application. It consists of a datagrid bound to a Data control. the Data control being linked to the user table in your database, allowing you to then view everyone logged into the application. Then when I need to kick everyone out to make an update, I just check the "Needs Maintainence" box. The code under this simply changes the DB flag to TRUE, and the timer control described above takes care of the rest; closing everyone out of the app normally. Make sure you hide this form in your app in a way so nobody esle can view it besides you. (I have it set on double-clicking a random label, then the code checks to see if the Username = me, then it shows the form) Don't want users getting into this.

    Hope that was clear enough. Like I said, there are alot of way to handle the situation you're in. This is the way I've delt with it and it works great for me.

    (Serge, thanks for the comps on my avatar , you'd be surprised at how many people actually think that's me!!!)

    Sibby
    Attached Images Attached Images  
    If you can think it....you can code it....

Posting Permissions

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



Click Here to Expand Forum to Full Width