Link to home
Start Free TrialLog in
Avatar of keonh
keonh

asked on

How to create a vbscript for a text box?

Hi all,

I'm new to VBScripts. I need a script for a textbox with a titlebar that has a OK button and the data from the textbox is written to a registry key in a specific location in the registry without overwriting the key if the script is ran again.

Hope I didn't confuse anyone.  Any help will be appricated!!

Thanks.
Avatar of TakedaT
TakedaT
Flag of United States of America image

Do you mean an inputbox rather than a textbox?
Avatar of keonh
keonh

ASKER

Yes, inputbox or a textbox that you can type in. Like a login dialog box. I guess it can be called either depending on its use. I remember it being called a textbox a long time ago. :)
Can you provide more info?
1 The name of the key.
2 Does this key already exist or does it need to be created?
3 Where does the input data get written to, an actual key name, value name, or value data?

Avatar of keonh

ASKER

The key will be need to be written to HKEY_LOCAL_MACHINE\SOFTWARE\Image
as a String Vaule named Tech (Vaule Name) and the value data needs to be what was typed in the box.

Let me know if you need more info.
I think this is what you are looking for.
Const HKEY_LOCAL_MACHINE = &H80000002
 
strComputer="."
strRegKey="SOFTWARE\Image"
strValue = "Tech"
bKeyExists = False
 
Set objReg=GetObject("winmgmts:{impersonationlevel=impersonate}!\\" &_
	strComputer & "\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE,"SOFTWARE",arrSubKeys
 
For Each subkey In arrSubKeys
    If subkey = "Image" then
    	bKeyExists = True
    	wscript.quit
    End If
Next
strNewVal = InputBox("Enter the value")
objReg.CreateKey HKEY_LOCAL_MACHINE,strRegKey
objReg.SetStringValue HKEY_LOCAL_MACHINE,strRegKey,strValue,strNewVal

Open in new window

Avatar of keonh

ASKER

Takeda, This works great!!

I do have one change, I noticed that the input box doesn't run after the first entry because the Image key is created.. That's fine but I would like to validate against the "Tech" key value and not the Image sub key. If the Tech key has a value, then quit, but a value is required.

Thanks again!!

Not a problem, but I am not at a pc right now, I will fix it for you hopefully later tonight.
Avatar of keonh

ASKER

No problem!! I can wait. Its not like I can figure it out. Btw, can you recommend any scripting books for beginners? Thanks again!!
ASKER CERTIFIED SOLUTION
Avatar of TakedaT
TakedaT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of keonh

ASKER

Thanks TakedaT!! This is perfect!!