Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing Registry Keys via HTA / VBSCRIPT

Status
Not open for further replies.

zendainc

Technical User
Feb 3, 2011
1
0
0
AU
Hi All,

I am trying to create a script which will allow me to remotely fix Active Desktop Recovery issues via the registry. All of the security shares etc work correctly and I have tried using both the psexec tool and the in built remote registry functionality.

My code appears to be correct, however when I attempt to update the registry key it does not change.

I am launching a HTA file which then launches another file to obtain the SID's on the remote PC, I manually copy these details into a text input box on the original HTA and click a button to execute the registry change, I am not receiving any errors but the key still does not seem to be updating.

My code is modified from a script I use to edit the netcache registry key. Any ideas for why this does not seem to be working?

The code for my first HTA is

----------------------------------------------

<html>
<head>
<title>Active Desktop Recovery</title>
<HTA:APPLICATION
APPLICATIONNAME="Active Desktop Recovery"
ID="MyHTMLapplication"
VERSION="1.0"/>
</head>

<script language="VBScript">
Function contactPing
On Error Resume Next
Set objShell = CreateObject("Wscript.Shell")
Err.Clear
strPingResults = ""
contactPing = False
Set oStrResult = objShell.Exec("ping -a -n 1 -w 50 " & Trim(txtComputerName.value))
Do While Not oStrResult.StdOut.AtEndOfStream
strResult = oStrResult.StdOut.ReadLine()
If InStr(strResult,"Reply") = 1 Then
strPingResults = strPingResults & strResult
contactPing = True
End If
Loop
End Function

Sub btnFindUser_OnClick
If contactPing Then
Set objShell = CreateObject("WScript.Shell")
objShell.Run("""c:\windows\system32\mshta.exe"" ""C:\Program Files\Admin Tools\Log.hta""")
End If
End Sub


Sub btnClearCSC_OnClick
If contactPing Then
Set objShell = CreateObject("Wscript.Shell")
Err.Clear
strResult = objShell.Run("psexec -i -d \\" & trim(txtComputerName.value) & " reg add ""HKU\" & (txtUserID.value) & "\Software\Microsoft\Internet Explorer\Desktop\SafeMode\Components\"" /v DeskHtmlVersion /t reg_dword /d 0x00000001(0)",3,false)
If strResult = 0 Then
If Err.Number <> 0 Then
MsgBox "ERROR starting ClearCSC on " & Trim(txtComputerName.value)
End if
Else
MsgBox "ERROR starting ClearCSC on " & Trim(txtComputerName.value)
End If
Else
MsgBox "ERROR starting ClearCSC on " & Trim(txtComputerName.value)
End If
End Sub
</script>

<body bgcolor="white">

<!--Add your controls here-->
<td><input name="txtComputerName" title="Enter a the computer you wish to query" TYPE="TEXT" SIZE="15"></td>
<td><input name="txtUserID" title="Enter available User ID" TYPE="TEXT" SIZE="50"></td>
<INPUT NAME="btnClearCSC" title="Clear CSC" TYPE="BUTTON" VALUE="Clear CSC">
<INPUT NAME="btnFindUser" title="Clear CSC" TYPE="BUTTON" VALUE="Find User">
<!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>

------------------------------------------------------------------------------
 
have you confirmed that from a dos prompt the following works?

psexec -i -d \\" & trim(txtComputerName.value) & " reg add ""HKU\" & (txtUserID.value) & "\Software\Microsoft\Internet Explorer\Desktop\SafeMode\Components\"" /v DeskHtmlVersion /t reg_dword /d 0x00000001(0)"

where you substitute the variable values for real one? and the quotes?

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
A while ago, I wrote a function to get a user's SID from a remote machine. It will eliminate the need to "manual discovery."

Code:
CONST HKEY_LOCAL_MACHINE = &H80000002

function getUserSID (strComputer, strUserName)
	set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
	getUserSID = "Unknown"
	
	objReg.EnumKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", arrSIDs
	
	for i = 0 to ubound(arrSIDs)
		strSID = arrSIDs(i)
		objReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strSID, "ProfileImagePath", strValue
		if (inStr(ucase(strValue), ucase(strUserName))) then
			getUserSID = strSID
			exit function
		end if
	next
end function

I'm not really sure what the contingencies to REG ADD are but, by default, the key HKU\User_SID\Software\Microsoft\Internet Explorer\Desktop\SafeMode doesn't exists. Therefore, no value can be added to it. Make sure the reg path exists before adding to it.

To get around this simply, use .CreateKey. It will create any subkey that does not exist.

objReg.CreateKey(HKEY_LOCAL_MACHINE, strKey)

This is a simple registry editing reference

NOTE:
One might expect strResult to equal a non-zero if the command failed but .Run returns a code indicating whether the command was EXECUTED or not, not the OUTCOME of the actual command (psexec...). .Run will always return zero if the command was executed even if the command failed - this is way you aren't getting an error.

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top