Solved

How to create a vbscript for a text box?

Posted on 2009-05-14
10
557 Views
Last Modified: 2012-05-07
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.
0
Comment
Question by:keonh
  • 5
  • 5
10 Comments
 
LVL 10

Expert Comment

by:TakedaT
Comment Utility
Do you mean an inputbox rather than a textbox?
0
 

Author Comment

by:keonh
Comment Utility
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. :)
0
 
LVL 10

Expert Comment

by:TakedaT
Comment Utility
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?

0
 

Author Comment

by:keonh
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:TakedaT
Comment Utility
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

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:keonh
Comment Utility
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!!

0
 
LVL 10

Expert Comment

by:TakedaT
Comment Utility
Not a problem, but I am not at a pc right now, I will fix it for you hopefully later tonight.
0
 

Author Comment

by:keonh
Comment Utility
No problem!! I can wait. Its not like I can figure it out. Btw, can you recommend any scripting books for beginners? Thanks again!!
0
 
LVL 10

Accepted Solution

by:
TakedaT earned 500 total points
Comment Utility
Here you go.  Honestly, what I know, I have learned from online tutorials/helpdocs and just years of experience.  But, if you are looking for good sources of reference, then MSDN is a good place to go.  If you have none/minimal knowledge of vbscript, then just a simple google search for vbscript tutorials can help get you started.  No one book is going to be enough.

http://msdn.microsoft.com/en-us/library/sx7b3k7y(VS.85).aspx

And of course, EE has plenty of examples for you to learn from.  Thats why Im here.
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

    End If

Next

If bKeyExists = False then

	objReg.CreateKey HKEY_LOCAL_MACHINE,strRegKey

End If
 

objReg.GetStringValue HKEY_LOCAL_MACHINE,strRegKey,strValue,strTech

If vartype(strTech)<>8 then

	strNewVal = InputBox("Enter the value")

	objReg.SetStringValue HKEY_LOCAL_MACHINE,strRegKey,strValue,strNewVal

Elseif strTech = "" then

	strNewVal = InputBox("Enter the value")

	objReg.SetStringValue HKEY_LOCAL_MACHINE,strRegKey,strValue,strNewVal

Else

	wscript.quit

End If

Open in new window

0
 

Author Closing Comment

by:keonh
Comment Utility
Thanks TakedaT!! This is perfect!!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now