VB script question

Associate
Joined
28 Dec 2006
Posts
11
Hello

Is anyone any good at VB scripting? I'd like to write a script which comes up with a box where you would enter a computer name then the script would apply a reg file (which I've got) to this computer.

Any ideas?

Cheers

Here's the reg file:
Code:
Windows Registry Editor Version 5.00

[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSLicensing]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermService\Parameters]
"Certificate"=-
 
Last edited:
Hi,

You could not use your reg file at all and edit the remote registry directly. The following *very basic* code will display an input box asking for the name of a computer - then get the reg of that machine (assuming your current credentials have rights) . Then use the methods from Here to set the values etc. you want.

Code:
Option Explicit

Dim strComputerName : strComputerName = InputBox("Computer Name","Enter Computer Name")
Dim objRegistry : Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\default:StdRegProv")

Cheers,
Jamie.
 
HI there,

The first line you are creating a variable called strComputer which will hold the name of the computer you wish to connect to. The inputbox() command will display a box with the bracketed text. Whatever you write in that box will be assigned to the variable strComputer.

The second line creates an object for the remote registry (objRegistry) - this then uses the computername in strComputerName to connect to the remote computer (using the credentials of the person running the script). Through the objRegistry object you now have the ability to edit the registry of the remote machine.

Using the methods from the link in the first post you can do things like objregistry.setDwordValue etc. to add the settings you need.

The Microsoft Script Centre is an excellent resource for admin scripting; theere are plenty of good guides there to get you back in the swing of things.

Cheers,
Jamie.
 
Hi,

This is the script now although when I click on the Cancel button, it brings up an error with line 10 (the line suggested above).

Googling the error e.g. http://www.computerperformance.co.uk/Logon/code/code_80041021.htm

suggests line 10 is right.

Can anyone help?

Thanks

Code:
'Dave and Mark's Remote RemoteAssistance Regfix
'Version 1.1 (01 February 2007)
'


' Define variables
	Const HKEY_LOCAL_MACHINE = &H80000002

	strComputer = InputBox("Enter Computer Name:", "DT/MB Remote RemoteAssistance Fix")
	Set objRegistry = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

	strKeyPathPara = "SYSTEM\CurrentControlSet\Services\TermService\Parameters"
	strValueNameCert = "Certificate"
	strKeyPathMSs = "SOFTWARE\Microsoft\MSLicensing\Store"
	strKeyPathMSh = "SOFTWARE\Microsoft\MSLicensing\HardwareID"
	strKeyPathMS = "SOFTWARE\Microsoft\MSLicensing"


' Delete value
	Return1 = objRegistry.DeleteValue (HKEY_LOCAL_MACHINE,strKeyPathPara,strValueNameCert)


' Delete Key
	Return2 = objRegistry.DeleteKey (HKEY_LOCAL_MACHINE,strKeyPathMSs)
	Return3 = objRegistry.DeleteKey (HKEY_LOCAL_MACHINE,strKeyPathMSh)
	Return4 = objRegistry.DeleteKey (HKEY_LOCAL_MACHINE,strKeyPathMS)
	If (Return1 = 0) And (Return4 = 0) And (Err.Number = 0) Then
		WScript.Echo "Success! HKEY_LOCAL_MACHINE\" & strKeyPathMS & " has been deleted"  & VBNewLine & "Success! HKEY_LOCAL_MACHINE\" & strKeyPathPara & "\" & strValueNameCert & " has been deleted"
	Else
		WScript.Echo "Failed! HKEY_LOCAL_MACHINE\" & strKeyPathMS & " has not been deleted" & VBNewLine & "Failed! HKEY_LOCAL_MACHINE\" & strKeyPathPara & "\" & strValueNameCert & " has not been deleted"
	End If
 
do While (strComputer = vbNullString)
Exit Do
loop

Changing it to the above still doesn't do what I want it to do. I still get the error with the line outlined above...
 
as a quick fix you could put the whole thing in an If --> Then ... something like:

Code:
'Dave and Mark's Remote RemoteAssistance Regfix
'Version 1.1 (01 February 2007)
'


' Define variables
	Const HKEY_LOCAL_MACHINE = &H80000002

	strComputer = InputBox("Enter Computer Name:", "DT/MB Remote RemoteAssistance Fix")

if strcomputer <> vbnullstring then
	Set objRegistry = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

	strKeyPathPara = "SYSTEM\CurrentControlSet\Services\TermService\Para  meters"
	strValueNameCert = "Certificate"
	strKeyPathMSs = "SOFTWARE\Microsoft\MSLicensing\Store"
	strKeyPathMSh = "SOFTWARE\Microsoft\MSLicensing\HardwareID"
	strKeyPathMS = "SOFTWARE\Microsoft\MSLicensing"


' Delete value
	Return1 = objRegistry.DeleteValue (HKEY_LOCAL_MACHINE,strKeyPathPara,strValueNameCer  t)


' Delete Key
	Return2 = objRegistry.DeleteKey (HKEY_LOCAL_MACHINE,strKeyPathMSs)
	Return3 = objRegistry.DeleteKey (HKEY_LOCAL_MACHINE,strKeyPathMSh)
	Return4 = objRegistry.DeleteKey (HKEY_LOCAL_MACHINE,strKeyPathMS)
	If (Return1 = 0) And (Return4 = 0) And (Err.Number = 0) Then
		WScript.Echo "Success! HKEY_LOCAL_MACHINE\" & strKeyPathMS & " has been deleted"  & VBNewLine & "Success! HKEY_LOCAL_MACHINE\" & strKeyPathPara & "\" & strValueNameCert & " has been deleted"
	Else
		WScript.Echo "Failed! HKEY_LOCAL_MACHINE\" & strKeyPathMS & " has not been deleted" & VBNewLine & "Failed! HKEY_LOCAL_MACHINE\" & strKeyPathPara & "\" & strValueNameCert & " has not been deleted"
	End If

else
      msgbox("Please enter something in the box you muppet")
end if
 
That works all fine except... If someone clicks cancel I don't want the message to pop up, I want the program to exit, which I can't work out how to do...
 
Back
Top Bottom