Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 Yay, that works, thank you!So now I just need to learn the text box, take text box input as add it as an argument.I'll need to continue this in a VM because messing around with slmgr on a live system is dangerous, no? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 4, 2010 Share Posted August 4, 2010 Running slmgr on a already activated PC with a valid serial number might not be a great idea indeed. Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 Oh and a question about Process.StartAssuming I'll be running my app from a dvd, does it assume files in the directory it was run from if they aren't in a system path? IE I wouldn't have to specify which folder Keyfinder.exe was on the dvd if it's in the same folder as the executable for this app? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 4, 2010 Share Posted August 4, 2010 It'll look in the current directory first, then on the system path. Just like if you ran the command from a command prompt. Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 And another question:How difficult would it be relative to what we've done so far, to require the correct Windows product key format in the textbox? 5alphanumeric > a dash > 5 alphanumeric etcI'm guessing MUCH more difficult? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 4, 2010 Share Posted August 4, 2010 How difficult would it be relative to what we've done so far, to require the correct Windows product key format in the textbox? 5alphanumeric > a dash > 5 alphanumeric etcChecking formatting is normally done using regular expressions. Otherwise you could check that the length of the typed text is just enough chars, then making sure that each character (one by one) is either alphanumeric or a dash depending on their position but that's not much easier... Once the app is working then yes, you should add that kind of validation. I'll help you with it too (it's more complex indeed). Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 Ok, I've got a strong rudimentary grasp of what we've done so far, I owe you a bunch.I've added the textbox. Now I am working on using the input. Here's code so far:Imports System.DiagnosticsPublic Class Form1 Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click Process.Start("slmgr.vbs") End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End SubEnd ClassWhat is the correct format for adding arguments, and how to use TextBox.Text?Also I notice it defaulted to TextBox1.TextChanged, would I need to used .TextChanged (or rename all instances of TextChanged to Text)? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 4, 2010 Share Posted August 4, 2010 This part: Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Subisn't needed right now (although it doesn't do any harm just being there either).Try this (type something in the textbox like dir or ping 127.0.0.1 before clicking the button):Imports System.DiagnosticsPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Process.Start("cmd.exe", "/K " & TextBox1.Text) End SubEnd Class Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 Aha!So.. what I want is something like this:Process.Start("slmgr.vbs", "-ipk " & TextBox1.Text)? Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 Now another question not related to programming but slmgr.vbs:Do you know if it REQUIRES dashes or if the 25 alphanumeric alone can be entered? And are they case insensitive? Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 AND another question! (Feel free to climb up a tower with a high powered rifle any time I ask too many questions!)If the entire text string would need to be entered enclosed in parenthesis in the command prompt (IE directories with long filenames), do they need parenthetical enclosure when run from a program like this? And if so, how would I go about doing that? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 4, 2010 Share Posted August 4, 2010 So.. what I want is something like this:Process.Start("slmgr.vbs", "-ipk " & TextBox1.Text)?That works just fine Do you know if it REQUIRES dashes or if the 25 alphanumeric alone can be entered? And are they case insensitive?As far as I know the dashes are required, and it's case insensitive.Edit:As for the regular expression (to validate the format of the typed text), you will have to add "Imports System.Text.RegularExpressions" at the top where the other Imports is/are.A simple* regular expression to handle this would be: ^([A-Za-z0-9]{5}-){4}([A-Za-z0-9]{5})$^ <- matches the beginning of the text$ <- matches the end of the text[A-Z] would match any single character between A and Z but we've added more "allowed ranges":[A-Za-z0-9] will match any single character between A and Z *or* between a and z *or between 0 and 9 -- basically any digit of the serial{5} means it will have to be repeated 5 times so:[A-Za-z0-9]{5} will match a group of 5 characters, each being in the allowed ranges- <- matches the dash in the key, so:[A-Za-z0-9]{5}- matches a 5 allowed characters followed by a dash() are used to create a group, so([A-Za-z0-9]{5}-) will match a group of 5 allowed characters followed by a dash([A-Za-z0-9]{5}-){4} will match a set of 4 groups of 5 allowed characters each followed by a dash([A-Za-z0-9]{5}-){4}([A-Za-z0-9]{5}) will match 4 groups of 5 chars with their dash and a 5th group of 5 chars (no dash)^([A-Za-z0-9]{5}-){4}([A-Za-z0-9]{5})$ will match the same thing, but only if nothing else is typed before or after that.so the validator works like this:Regex.IsMatch(TextBox1.Text, "^([A-Za-z0-9]{5}-){4}([A-Za-z0-9]{5})$")This will return true if the text matches the regular expression i.e. if it's in the right format, otherwise it will return false.So you would use a If statement, that will run the slgmr command line if the Regex returns true (proper key), otherwise popup an error message using a MessageBox. The result would like this:Imports System.DiagnosticsImports System.Text.RegularExpressionsPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Regex.IsMatch(TextBox1.Text, "^([A-Za-z0-9]{5}-){4}([A-Za-z0-9]{5})$") Then Process.Start("slmgr.vbs", "-ipk " & TextBox1.Text) Else MessageBox.Show("Key format is invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End SubEnd ClassI know that it might be quite a bit to grasp at once. Don't focus too much on the Regex but rather the logic and program flow instead (i.e. the if/then/else)* By simple I mean that it fails to account for some alphanumeric characters that aren't allowed in CD keys (there's only 24 allowed characters out of the 36 letters & numbers), not that it's ridiculously easy to understand the first time you get into it. Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 Awesome, this is whizzing right along!So now I'm ready for the more advanced parts I think.So I want Button0 to clear the window, and have the textbox, "Change Key" and "Cancel" buttons to appear. The text "Change Customer Product Key" should be displayed somewhere in the window. Link to comment Share on other sites More sharing options...
Chocobits Posted August 4, 2010 Author Share Posted August 4, 2010 And urgh, I thought of two more questions :/"slmgr.vbs" This is available in ALL versions of Vista/7, or is it a stripped out of some versions?Will UAC interfere with this program's functions? And if so, is there a way to flag this program to require Admin rights to run? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 4, 2010 Share Posted August 4, 2010 So I want Button0 to clear the window, and have the textbox, "Change Key" and "Cancel" buttons to appearYou mean, popup another window (form) with these on it? I'm not totally sure I followed.And urgh, I thought of two more questions :/There's an edit button at the bottom of your posts "slmgr.vbs" This is available in ALL versions of Vista/7, or is it a stripped out of some versions?As far as I know, this is included in all editions of both.Will UAC interfere with this program's functions? And if so, is there a way to flag this program to require Admin rights to run?This program doesn't need to run elevated but slmgr does. If you don't run slmgr.vbs elevated it will just popup an error message. There is a way to make sure you run elevated but it's not perfect... Look over here to see how you check if you're running elevated (you check using .IsInRole(WindowsBuiltInRole.Administrator) on WindowsPrincipal). Then if you determine you're not running elevated, you basically make your app run itself but in a special way (you create a ProcessStartInfo and set its verb to "runas", which will then popup the UAC window automatically). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now