Solved

VBS file to modify registry

Posted on 2008-10-31
6
430 Views
Last Modified: 2012-06-27
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!
0
Comment
Question by:dougstech
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
Hubasan earned 125 total points
ID: 22850933
Here is the script you requested. Let me know if you have any questions.
Const HKEY_LOCAL_MACHINE = &H80000002

Const cTitle = "Change Registry Values"

strComputer = "."

Set oWS = CreateObject("wscript.shell")

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 

    strComputer & "\root\default:StdRegProv")
 
 

sKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"

sValueName = "DefaultUserName"

sDomain = "DefaultDomainName"

sDomainValue = "MCPS"

Do

sValue = InputBox("Please type in the DefaultUserName registry value you want to use:", cTitle, "(Enter value)")

	If sValue = "" Then

		sRes = oWS.Popup("Sorry, you must enter the DefaultUserName reg value to continue." &_

		" Do you wish to try again?", ,cTitle,vbExclamation+vbYesNo)

			If sRes = vbNo Then

				oWS.Popup "User canceled, Exiting script!", , cTitle, vbInformation

				WScript.Quit

			End If

	End If

Loop Until sValue <> ""
 

oReg.SetStringValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,sValue

oReg.SetStringValue HKEY_LOCAL_MACHINE,sKeyPath,sDomain,sDomainValue
 

oReg.GetStringValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,sValue2

oReg.GetStringValue HKEY_LOCAL_MACHINE,sKeyPath,sDomain,sDomainValue2
 

If sValue <> sValue2 Or sDomainValue <> sDomainValue2 Then

	oWS.Popup "There was a problem in changing the registry values," &_

	" please check that you have enough rights to write to the HKLM of the registry", , cTitle, vbCritical

Else

	oWS.Popup "Registry values were changed successfuly!", , cTitle, vbInformation

End If

Open in new window

0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22851028
Although hubasan's code appears to be correct, I would HIGHLY advise you not do this.  Storing default domain/user/password information in the registry is a big security hole.  That means that booting the computer (by anyone) will log it in and then the user could navigate to that key to get the users's password.

I realize that you can't do this with vbs, but it's a better setup to use xp power toys to do your auto login as it won't store the PW in cleartext.

http://www.windowsreference.com/windows-xp/enable-autologon-in-windows-2000xp2003/
0
 
LVL 5

Author Comment

by:dougstech
ID: 22853139
BrandonGalderisi

the script does NOT have a password to be stored in the registry. the user will still have to enter their password, but the username and domain would be filled in for them.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22853161
I BELIEVE... the defaultusername and defaultdomainname are only used for auto login when the autologin flag is set.  I believe that the defaultusername and defaultdomainname will still always display the last logged in user.  

But I could be wrong.
0
 
LVL 5

Author Closing Comment

by:dougstech
ID: 31512064
Thank you so much! It worked perfectly! This saves me a TON of time in the registry! thanks again
0
 
LVL 7

Expert Comment

by:Hubasan
ID: 22853351
you are welcome :-)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

16 Experts available now in Live!

Get 1:1 Help Now