Jump to content

Need help with "REG QUERY" command


Recommended Posts

Hey guys out there,

I need help with the "REG QUERY" command :blink:

I have to edit the following REG-Keys:

"MouseSpeed"="0"
"MouseThreshold1"="0"
"MouseThreshold2"="0"

The "Master-Key" is the following:

HKEY_USERS\S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-500\Control Panel\Mouse

The "problem" is, that the numbers I marked with "X" are changing on every new OS-Installation.

So I have to use the "REG QUERY" command tho determine the REG-Key!

For antoher operation with "REG QUERY" I'm using the following command:

@FOR /F "DELIMS=" %%? IN ('REG QUERY HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318} /S^|FINDSTR \\Connection$') DO @REG ADD "%%?" /V ShowIcon /T REG_DWORD /D 1 /F >NUL

But what about the syntax? I'm sorry but I don't understand it completely...

So can anyone help me getting the right syntax for the operation I have to do?

Thank you

Link to comment
Share on other sites


As i understand, you're trying to modify mouse option in the local administrator profile.

If you can access to this reg key it is because the administrator is logged in and if you can run your batch with the administrator account then why not use HKey_current_user instead of HKEY_USERS\S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-500 ?

If you still want to edit this reg entry with administrator logged in but with another account, you'll have to get the right sid in a proper way:

Use getsid.exe from the XP support tools and filter its output then do the reg query.

Link to comment
Share on other sites

This works:

' Get an account SID via Win32_Account

Option Explicit
Dim strComputer, strUser, strSID, strMouseSpeedValue, strMouseThreshold1Value, strMouseThreshold2Value
Dim intMouseSpeedValueData, intMouseThreshold1Value, intMouseThreshold2Value
Dim objWMIService, objShellApp, objItem
Dim colItems, gErrData

'// Ensure that cscript is the engine used to run this script:
RunMeWithCScript()

'// Set error handling:
On Error Resume Next

strComputer = "."

'// Reg values we're going to modify:
strMouseSpeedValue = "MouseSpeed"
strMouseThreshold1Value = "MouseThreshold1"
strMouseThreshold2Value = "MouseThreshold2"

'// Values we're going to set them to:
intMouseSpeedValueData = "0"
intMouseThreshold1Value = "0"
intMouseThreshold2Value = "0"

'// Create objects:
Set objShellApp = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

'// Connect to WMI and get the list of Account/SID info:
Set colItems = objWMIService.ExecQuery("Select * from Win32_Account",,48)

'// Find the SID for the user:
For Each objItem in colItems
If objItem.Name = "Administrator" Then
strUser = objItem.Name
strSID = objItem.SID
End If
Next

WScript.Echo strUser & "'s account SID is:"
WScript.Echo strSID

'// Change the registry values for the user:
objShellApp.Exec("reg add ""HKU\" & strSID & "\Control Panel\Mouse"" /v " & strMouseSpeedValue & " /t REG_SZ /d """ & intMouseSpeedValueData & """ /f")
If Not Err.Number = 0 Then
gErrData = gErrData & vbCrLf & "Error writing " & strMouseSpeedValue & " to " & strUser & "'s registry - reason: " & Err.Number & " - " & Err.Description
WScript.Echo gErrData
Err.Clear
Else
WScript.Echo "Registry edit to add " & strMouseSpeedValue & " for user " & strUser & " as data " & intMouseSpeedValueData & " was successful."
End If

objShellApp.Exec("reg add ""HKU\" & strSID & "\Control Panel\Mouse"" /v " & strMouseThreshold1Value & " /t REG_SZ /d """ & intMouseThreshold1Value & """ /f")
If Not Err.Number = 0 Then
gErrData = gErrData & vbCrLf & "Error writing " & strMouseSpeedValue & " to " & strUser & "'s registry - reason: " & Err.Number & " - " & Err.Description
WScript.Echo gErrData
Err.Clear
Else
WScript.Echo "Registry edit to add " & strMouseThreshold1Value & " for user " & strUser & " as data " & intMouseThreshold1Value & " was successful."
End If

objShellApp.Exec("reg add ""HKU\" & strSID & "\Control Panel\Mouse"" /v " & strMouseThreshold2Value & " /t REG_SZ /d """ & intMouseThreshold2Value & """ /f")
If Not Err.Number = 0 Then
gErrData = gErrData & vbCrLf & "Error writing " & strMouseSpeedValue & " to " & strUser & "'s registry - reason: " & Err.Number & " - " & Err.Description
WScript.Echo gErrData
Err.Clear
Else
WScript.Echo "Registry edit to add " & strMouseThreshold2Value & " for user " & strUser & " as data " & intMouseThreshold2Value & " was successful."
End If


On Error GoTo 0


Sub RunMeWithCScript()
Dim ScriptEngine, engineFolder, Args, arg, scriptName, argString, scriptCommand

ScriptEngine = UCase(Mid(WScript.FullName, InstrRev(WScript.FullName, "\") + 1))
engineFolder = Left(WScript.FullName, InstrRev(WScript.FullName, "\"))
argString = ""

If ScriptEngine = "WSCRIPT.EXE" Then
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Set Args = WScript.Arguments

For Each arg in Args
If InStr(arg, " ") > 0 Then arg = """" & arg & """"
argString = argString & " " & Arg
Next

scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & WScript.ScriptFullName & """" & argString

Shell.Run scriptCommand, , False
WScript.Quit
Else
Exit Sub
End If
End Sub

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...