It's a bit unsafe, waiting for someone who will test it. I won't do it.
Okay this is kinda hard to explain so I'll post a pic of my form as well as it may help this make more sense.
Here's my form:
Okay basically it's a game auto-login I'm making for a friend of mine. To give a brief overview of what the program does: You browse for your game .exe using the browse button provided. Then you select your account from the list box and hit the big login button. The button first checks whether the game is running or not, if no it runs the given file path and then inputs the username and password of the given account into the game. If the game is running it simply inputs the account details.
The add account button is pretty self explanatory, you put in your new account password and username and it will save it to the listbox under the given username.
This brings me to the problem I'm having. What I would like to happen is when the person goes to the "Add new account" menu and inputs a username and password and presses "Save Details" I would like the following to happen:
1. The username given to be saved as a new listbox entry (Already done)
2. Have both the username and password saved somewhere so they can be recalled after the form has been shut and re-opened.
Now when the person selects their account from the listbox I would like the "Username" box to come up with the username they inputted for their account and the "Password" textbox to come up with their inputted password (*** out of course but that's simple enough)
So my question is, how do I save their inputted information from the "Add new account" section so that when they choose their username from the listbox, both the username and password will come up in their respective boxes?
Hope someone understands what I'm asking, if you need more information please ask and I shall try and give it to you.
Thanks,
J-Deezy.
Last edited by KING; 04-29-2010 at 02:43 PM.
It's a bit unsafe, waiting for someone who will test it. I won't do it.
I'm Italian. Italy is falling down.
I come from the Count of Tuscany (Dream Theater)
Store them internally or in an ini file.
"I don't believe in an afterlife, so I don't have to spend my whole life fearing hell, or fearing heaven even more. For whatever the tortures of hell, I think the boredom of heaven would be even worse." - Isaac Asimov
Use SaveSetting on exiting the form, and GetSetting on form's load event.
Format is:
And GetSetting:Code:SaveSetting(Application.ProductName,"Settings","ReplaceWithSettingName","ReplaceWithSettingValue")
Then assign this value where it belongs !!Code:Dim val as string = GetSetting(Application.ProductName,"Settings","ReplaceWithSettingName","ReplaceWithDefaultValue")
Okay thanks for that MJ I'll test it out when I get home from school. I've also hit another snag, could someone please tell me how to check if a process is already running? I googled around but most of it was some huge code which didn't really relate to what I wanted.
All i want to happen is to have a timer running constantly in the background checking whether the process is running or not and check/uncheck the checkbox accordingly.
Thanks,
J-Deezy
Create a Function
[php]
Function CheckProcess(ByVal strProcess)
Dim Process, strObject
CheckProcess = False
strObject = "winmgmts://"
For Each Process In GetObject(strObject).InstancesOf("win32_process")
If UCase(Process.name) = UCase(strProcess) Then
CheckProcess = True
' MsgBox("explorer.exe")
Exit Function
End If
Next
End Function
[/php]
Now you can use form load, or a button , or whatever to determine if a process is running
CheckProcess("Process to check for")
Example, If I want to check for explorer.exe
CheckProcess("explorer.exe")
If it is true it will turn on the flag "CheckProcess" , then you do whatever you want
[php]
If CheckProcess=True then
Yada yada
Else
Yada Yada
End If
[/php]
You can ignore the 'MessageBox part, I was testing to be sure it was working right
Jason (04-27-2010)
Thanks, just by looking at it seems to be exactly what I'm looking for. I'm currently sitting in last period so I can't actually test it but I'll be sure to thank you after I give it a test. Been considering how I can use the "SaveSettings" to save each individual account and I think I have a solution haha. We'll see.
Thanks again for all your help.
J-Deezy.
Not a prob, No need to thank, it's just a button , You already said it .
@ settings, the tut section has 1 or 2 setting tutorials that may help as well.
[php] Public Function IsProcessOpen(ByVal name As String) As Boolean
For Each clsProcess As Process In Process.GetProcesses
If clsProcess.ProcessName.Contains(name) Then
Return True
End If
Next
' Do nothing
Return False
End Function[/php]
Code:If Isprocessopen("process") then whatever end ifCode:If not isprocessopen("process") then whatever end if
I like Blubbs version better, effective and clean, good job.
My version can check applications running on a server as well though
Okay thanks for that guys. It's now checking processes perfectly. The only problem I'm having at the moment is if the process is already running, bring it to the topmost window. Because I'm using SendKeys.Send to send the text I need the application to be at the top to successfully get the inputted user/pass.
Is there any way to bring it to top? I've heard that with OS changes microsoft did something to change the old VB code to bring to top and since most tuts i found via google are for VB6 or earlier, they aren't much help.
Cheers,
J-Deezy
Me.Topmost = True
That'll bring the form to the top, but you'll need some edits to bring the process. Waiting for NextGen input..
Woot! After much brainstorming I managed to come up with a code for saving the settings that works! For once I managed to figure something out without using Google haha, I must be progressing.
Sure, it's not the prettiest code in the world but it's effective.
This is the "Save Details" button code
And this is how it pulls the information of each account according to whichever is selected in the listbox:Code:Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Accounts.Items.Add(NewUserTxt.Text) SaveSetting("AutoLogin.exe", NewUserTxt.Text, "User", NewUserTxt.Text) SaveSetting("AutoLogin.exe", NewUserTxt.Text, "Pass", NewPassTxt.Text) End Sub
So yeah that works perfectly despite it being a bit clumsy.Code:Private Sub Accounts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Accounts.SelectedIndexChanged UserTxt.Text = GetSetting("AutoLogin.exe", Accounts.SelectedItem, "User") PassTxt.Text = GetSetting("AutoLogin.exe", Accounts.SelectedItem, "Pass") End Sub
The only thing left to do is figure out how to move the process to the top window if it's already running (for example after I do (CheckProcess("Notepad.exe")) if the value is true then Notepad should become to focus window)
Any ideas? Thanks so much for your help on this guys, really made it a lot less frustrating haha
J-Deezy.
EDITTT: Spoke wayyy too soon. While that code is all fine and dandy while the app is still running, I'm having trouble recalling all the usernames into the ListBox on start. More brainstorming it seems
Okay EDIT2: I changed the order of the "SaveSetting(" to
Because I figure in theory using "Listbox1.Items.Add(GetSetting("AutoLogin.Exe" , "Users")"Code:SaveSetting("AutoLogin.exe", "Users", NewUserTxt.Text, NewUserTxt.Text)
Would simply load all the .text saved into the "Users" folder into separate Listbox entries. Apparently not. Is there any way to do this?
Cheers. (Still need help on the "bring process to top" question )
Last edited by Jason; 04-27-2010 at 03:33 AM.
EDIT3: Okay it appears the only way to save the contents of a listbox is to save to a .txt file and get them from there upon form reload. I'm currently googling it at the moment but if anyone wants to provide a quick snippet to save time feel free
Still working on trying to call process to top :@ it's annoying haha, so close to being finished.