VBS file to modify registry

Posted on 2008-10-30
Last Modified: 2013-12-23
I am looking to create a simple .vbs file that will modify a registry key. I need it to have a prompt to change one key, and automatically change the other key.

The keys are
hkey_local_machine>software>microsoft>windows nt>winlogon>defaultusername
hkey_local_machine>software>microsoft>windows nt>winlogon>defaultdomainname

I need a simple prompt that will ask me for the defaultusername, and when I enter it, it will change the key with my value. And, I need it to always change the defaultdomainname to "MCPS".

I have never programmed, and I am not even sure if this is the correct way to do this. Thanks for your help!
Question by:dougstech
  • 4
  • 3
LVL 67

Expert Comment

ID: 22851646
easy batch method:

@echo off
set /p defUser=Enter the default username:
set /p defDomain=Enter the default domain:
reg add "hklm\software\microsoft\windows nt\currentversion\winlogon /v defaultusername /d %defUser% /f
reg add "hklm\software\microsoft\windows nt\currentversion\winlogon /v defaultdomain /d %defDomain% /f
echo. Changes complete.
LVL 67

Accepted Solution

sirbounty earned 125 total points
ID: 22851691
vbs method:
const HKLM = &H80000002

Dim objReg : Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")


strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"

defUser = InputBox("Enter the default username", "Data needed")

defDomain = InputBox("Enter the default domain", "Data needed")

objReg.SetStringValue HKLM, strKeyPath, "DefaultUserName",defUser

objReg.SetStringValue HKLM, strKeyPath, "DefaultDomainName",defDomain

Set objReg = Nothing

Open in new window


Author Comment

ID: 22857692
Both methods are superb, but I want to split points.
Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

LVL 67

Expert Comment

ID: 22858675

Author Comment

ID: 22858973
Right but 125/2=62.5. I wont let me add half points.
LVL 67

Expert Comment

ID: 22859048
You can do 75/50 or if you want to be closer to exact 63/62.  Either way, I posted both solutions - I don't mind if you only accept one... :^)

Author Comment

ID: 22859051
oh lol, I didn't even see that it was both you :p

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

911 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

20 Experts available now in Live!

Get 1:1 Help Now