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?
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."
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.")
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.
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:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public Function UID()
Dim sBuffer As String
Dim lSize As Long
Dim UName As String
Dim MError As String
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
UName = Left$(sBuffer, lSize)
Else
UName = vbNullString
End If
'I added this if statement. It was returning a null character
'at the end of the string. You may or may not need this
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....
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.
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.
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."
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.
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.
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:
Private Sub tmrMaint_Timer()
Static MessageFlag as Boolean
If <boolean DB feild> Then
If Not MessageFlag Then
<show custom message to user>
End If
MessageFlag = True 'Set the flag so the message is only shown once
tmrMaint.Tag = tmrMaint.Tag + 1
If tmrMaint.Tag = 3 Then 'set the max tag value depending on how long you want the app to wait untill it shuts down
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.
Unload <main form>
Else
tmrMaint.Enabled = False 'if it is you, disable this timer
End If
End If
End If
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!!!)