[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1502
  • Last Modified:

add registry key with VBScript

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
HNMIS
Asked:
HNMIS
  • 2
1 Solution
 
rlandquistCommented:
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
 
HNMISAuthor Commented:
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
 
HNMISAuthor Commented:
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now