?
Solved

add registry key with VBScript

Posted on 2010-01-12
3
Medium Priority
?
1,305 Views
Last Modified: 2012-06-21
Could someone create a VBScript to create a registry key/DWORD value in HKLM named ASSETTag.  I would like the script to prompt for the DWORD name and Value.
0
Comment
Question by:HNMIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
rlandquist earned 200 total points
ID: 26298045
Here you go.  This script will prompt for The DWORD Name and the DWORD Value.  It will not continue if the value is not numeric.

It creates the Key at HKLM\System\ASSETTAG

Let me know if you have any questions.
Const HKEY_LOCAL_MACHINE = &H80000002

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

Do
	strDWORDName = _
	InputBox("Please enter the DWORD Key Name:", _
	"DWORD Key Name", "Key Name")
	If strDWORDName = False Then
		WScript.Quit
	End If
Loop Until strDWORDName <> ""

Do
	strDWORDValue = _
	InputBox("Please enter the DWORD Value:" & VbCrLf & VbCrLf & "This value must be numeric.", _
	"DWORD Value", "1234")
	If strDWORDValue = False Then
		WScript.Quit
	End If
Loop Until IsNumeric(strDWORDValue)

'Create Key
strKeyPath = "System\ASSETTag"
objRegistry.CreateKey HKEY_LOCAL_MACHINE, strKeyPath

'Set DWORD value
strKeyPath = "System\ASSETTag"
strValueName = strDWORDName
intValue = strDWORDValue
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, intValue

WScript.Echo "Script Finished"

Open in new window

0
 

Author Comment

by:HNMIS
ID: 26303345
Maybe a string value would be better so I modified it to write a string value.  I gues the string data name would need to be "AssetTag" (no prompting) and then it would need to prompt me to enter the data.  I dont know how to make that happen.  Could you help?
0
 

Author Comment

by:HNMIS
ID: 26303425
nevermind, I got it.
Const HKEY_LOCAL_MACHINE = &H80000002
 
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
 
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
 
'Do
        strStringName = "AssetTag"
'        InputBox("Please enter the DWORD Key Name:", _
'        "DWORD Key Name", "Key Name")
'        If strStringName = False Then
'                WScript.Quit
'        End If
'Loop Until strStringName <> ""
 
Do
        strStringValue = _
        InputBox("Please enter the Asset Tag of the PC:", _
        "String Value", "1234")
        If strStringValue = False Then
                WScript.Quit
        End If
Loop Until strStringValue <> ""
 
'Create Key
strKeyPath = "System\AssetTag"
objRegistry.CreateKey HKEY_LOCAL_MACHINE, strKeyPath
 
'Set String value
strKeyPath = "System\AssetTag"
strValueName = strStringName
intValue = strStringValue
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, intValue
 
WScript.Echo "Script Finished"


Thanks for your assistance.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 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