Copy Registry key using VBS Script

25 pts.
Tags:
VB script
Windows Registry
Hi, I have a question i'm trying to copy the PC name witch is located in (HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlComputerNameComputerName)  to a different registry key (HKEY_LOCAL_MACHINESOFTWAREIOLANSphereStation) but i can't get it to work. I thought is should work with the script posted below but is doesn't it gives no error.
Set WshShell = Wscript.CreateObject("Wscript.Shell")

'Read the value of DefaultUserName :
reg = WSHShell.RegRead ("HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlComputerNameComputerNameComputerName")

'Replace the value with "Id" :
WshShell.RegWrite ("HKEY_LOCAL_MACHINESOFTWAREIOLANSphereStation"), "Id" ,"REG_SZ"

'Data Types :
'REG_DWORD
'REG_BINARY
'REG_EXPAND_SZ
As you probable already noticed i havent got that mutch experience with VBS Scripting. I hope you guys can help me out al little.

Software/Hardware used:
Windows Xp Sp3

Answer Wiki

Thanks. We'll let you know when a new response is added.

Try running reg from a command line. You could call from VBScript if you need to use VBScript.

<pre>cmd /c reg add “HKLM\key” /v VALUE /t REG_SZ /d %COMPUTERNAME% /F</pre>

Unfortunately your “<pre>\</pre>” (backslash) characters were stripped. Use the “code” tags around your script sections to prevent them from being stripped.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Digital8
    I can read, the information from the registry using... reg query "HKLMSYSTEMCurrentControlSetControlComputerNameComputerName" /v "ComputerName" and i can also simply add the information to the registry but i want to automate it (Run Once at system start up) The reason i want to automate this is because i have to clone a lot of PC's and each one uses its PC name to logon to our companies software, having to edit every PC's registry to add this information to the registry consumes a lot of time. So if anyone knows of a way to do this, your help would be greatly appreciated.
    25 pointsBadges:
    report
  • Pjb0222
    Is there any reason you cannot use the COMPUTERNAME environment variable?
    3,310 pointsBadges:
    report
  • Digital8
    It works TnX Pjb0222... :)
    25 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following