Dana L. Houseman Posted June 5, 2007 Share Posted June 5, 2007 I'd like to pass a Variable to an input Box, does anyone have a suggestion for my code? Specif. Get the COMPUTER NAME, Prompt user for new name with old name in the INPUT box so the user can edit the old or enter a new name. CODE;Places the input box in the top left corner displaying the characters as they ;are typed. $var = RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName") $answer = InputBox("My Rename Workstation", "What is the Name for this computer?", "", "", _ 350, 100, 200, 200) Send("{"& $var"}") ; Write a single REG_SZ value RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $answer) TKS, D~ Link to comment Share on other sites More sharing options...
AcidCorps Posted June 5, 2007 Share Posted June 5, 2007 ;Places the input box in the top left corner displaying the characters as they ;are typed. $var = RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName") $answer = InputBox("My Rename Workstation", "What is the Name for this computer?", $var, "", _ 350, 100, 200, 200) ; Write a single REG_SZ value RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $answer) $var's don't work in quotes, simply put the $var where you would put the quotes and text Link to comment Share on other sites More sharing options...
Helge Posted June 5, 2007 Share Posted June 5, 2007 Send would've been executed after Inputbox had been closed and not while it's still up, since it has to wait for the user to input something. The way you've scripted it now requires Send to be executed while the inputbox is still up but that the RegWrite however somehow magically knows that he should wait. Even though Send wouldn't have worked like you wanted it to, I would like to point out the proper way of sending the value of the variable. Curly brackets are only for special keys so no need to use them here (for example, {enter} equals the enter-key while "enter" simply equals the string as it is shown). You also missed a ampersand after the variable. Send($var) Ok, this is just some extra information. For solving your problem look at AcidCorps' post Link to comment Share on other sites More sharing options...
Dana L. Houseman Posted June 5, 2007 Author Share Posted June 5, 2007 ;Places the input box in the top left corner displaying the characters as they ;are typed. $var = RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName") $answer = InputBox("My Rename Workstation", "What is the Name for this computer?", $var, "", _ 350, 100, 200, 200) ; Write a single REG_SZ value RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $answer) $var's don't work in quotes, simply put the $var where you would put the quotes and text I changed it and the $var does not put the Current COMPUTERNAME in the INPUTBOX. Link to comment Share on other sites More sharing options...
herewasplato Posted June 5, 2007 Share Posted June 5, 2007 (edited) I changed it and the $var does not put the Current COMPUTERNAME in the INPUTBOX.You might want to manually check the value of the registry key that you have been reading from and writing to - it may be blank now.Edit: Selecting cancel from the input box will make $answer = to an empty string - which the RegWrite gladly wrote to the key - subsequent runs of the script will look like the computer name is not being displayed as the default prompt in the input box... but it is :-) Edited June 5, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Dana L. Houseman Posted June 6, 2007 Author Share Posted June 6, 2007 (edited) You might want to manually check the value of the registry key that you have been reading from and writing to - it may be blank now.Edit: Selecting cancel from the input box will make $answer = to an empty string - which the RegWrite gladly wrote to the key - subsequent runs of the script will look like the computer name is not being displayed as the default prompt in the input box... but it is :-)Well that was a duh moment, because I had realized this before, but didn't think about it when I ran the above code. Thanks for the reminder, it's working. Now a quick Question; Can I remove the CANCEL button, because I'd never want the end user to CANCEL the entry. Edited June 6, 2007 by Dana L. Houseman Link to comment Share on other sites More sharing options...
herewasplato Posted June 6, 2007 Share Posted June 6, 2007 ...I'd never want the end user to CANCEL the entry.Try this loop. Pressing cancel causes it to just ask again.$var = RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName") Do $answer = InputBox("My Rename Workstation", _ "What is the Name for this computer?", _ $var, "", 350, 100, 200, 200) Until Not @error ; Write a single REG_SZ value RegWrite("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $answer) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
herewasplato Posted June 6, 2007 Share Posted June 6, 2007 You might also want to consider doing some error checking before you allow a user to write an invalid character to the registry.expandcollapse popup$var = RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName") Do Do $answer = InputBox("My Rename Workstation", _ "What is the Name for this computer?", _ $var, "", 350, 100, 200, 200) Until Not @error ; I'm not sure that this is too kind $valid = False $bad = "" ;http://support.microsoft.com/kb/228275 ;there might be more invalid characters If StringInStr($answer, "/", 1) Then $bad &= "/";slash If StringInStr($answer, "\", 1) Then $bad &= "\";backslash If StringInStr($answer, "[", 1) Then $bad &= "[";left bracket If StringInStr($answer, "]", 1) Then $bad &= "]";right bracket If StringInStr($answer, '"', 1) Then $bad &= '"';double quote If StringInStr($answer, ":", 1) Then $bad &= ":";colon If StringInStr($answer, ";", 1) Then $bad &= ";";semicolon If StringInStr($answer, "|", 1) Then $bad &= "|";pipe If StringInStr($answer, "<", 1) Then $bad &= "<";less than If StringInStr($answer, ">", 1) Then $bad &= ">";greater than If StringInStr($answer, "+", 1) Then $bad &= "+";plus If StringInStr($answer, "=", 1) Then $bad &= "=";equals If StringInStr($answer, ",", 1) Then $bad &= ",";comma If StringInStr($answer, "?", 1) Then $bad &= "?";question mark If StringInStr($answer, "*", 1) Then $bad &= "*";asterisk If StringInStr($answer, " ", 1) Then $bad &= " ";space If StringInStr($answer, "_", 1) Then $bad &= "_";underscore If StringInStr($answer, "", 1) Then $bad &= "";empty or null If Not $bad = "" Then MsgBox(0, "Error", "Invalid Character(s)" & @CR _ & ">>>" & $bad & "<<<") ContinueLoop Else $valid = True EndIf Until $valid = True ConsoleWrite(">>>" & $answer & "<<<" & @CR)I've replaced the actual RegWrite with a ConsoleWrite for testing. Now let's wait for a much smaller solution using StringRegExp to be posted by someone smarter than the MSP :-) [size="1"][font="Arial"].[u].[/u][/font][/size] 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