code not working - SetDwordValue not working in vbs - vbscript

Here is my code:
Const HKEY_CLASSES_ROOT= &H80000000
Const HKEY_CURRENT_USER= &H80000001
Const HKEY_LOCAL_MACHINE= &H80000002
Const HKEY_USERS= &H80000003
Set StdOut = WScript.StdOut
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Hardware Profiles\UnitedVideo\CONTROL\VIDEO\{D218E173-A430-11E8-80D8-005056C00008}\0001"
strValueName = "venkat"
oReg.SetDWordValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, 800
oReg.GetDWordValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, dval
WScript.Echo "SYSTEM\CurrentControlSet\Control\" & " = " & dval
I'm running in Windows 10.
SetDWordValue of in the script is not working.
GetDwordValue is working fine and I'm getting the data.
Tried all the possibilities. Even the code from MSDN is not working. I want to change my registry key using vbs.

The most likely reason is that you simply don't have permission to write to that registry key. The WMI registry methods don't raise an error when something goes wrong, so you need to check the method's return code, e.g. by changing the line
oReg.SetDWordValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, 800
to
rc = oReg.SetDWordValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, 800)
WScript.Echo rc
A return code of 5 means you have a permission error.
To fix that you probably just need to run the script "as Admin".

Related

How to check the version of oracle provider for ole-db. OraOLEDB.Oracle provider

How to check the version of oracle provider for ole-db. OraOLEDB.Oracle provider on windows 10 and windows 7 ?
You can use for example tool RegDllView. Search for "OraOLEDB", result could be this:
A simpler approach would be this navigate to your ORACE_HOME\bin directory and locate file OraOLEDB??.dll. Check version with right-hand mouse click -> Properties -> Details.
However, you just get the version of the file, it does not necessarily mean that this DLL is also registered and ready for use.
Or use this VBScript:
Option Explicit
Const HKEY_CLASSES_ROOT = &H80000000
Dim Key, strComputer, objRegistry, strPath, arrKeys, fso
Dim strKeyPath, strValueName, strValue, uValue, ver
Set fso = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegistry.enumKey HKEY_CLASSES_ROOT, "CLSID", arrKeys
For Each key In arrKeys
strKeyPath = "CLSID\" & key
strValueName = "OLEDB_SERVICES"
If objRegistry.GetDWordValue (HKEY_CLASSES_ROOT, strKeyPath, strValueName, uValue) = 0 Then
'get the (Default) value which is the name of the provider
objRegistry.GetStringValue HKEY_CLASSES_ROOT, strKeyPath, "", strValue
If InStr(1, strValue, "OraOLEDB.Oracle", vbTextCompare) > 0 Then
' get expanded location
objRegistry.GetStringValue HKEY_CLASSES_ROOT, strKeyPath & "\InprocServer32", "", strPath
ver = fso.GetFileVersion(strPath)
Wscript.Echo strValue & " # " & strPath & " -> " & ver
End If
End If
Next
OLE DB provider may exist in 32-bit or/and in 64-bit, so you may execute the script twice:
C:\Windows\System32\cscript.exe Print_OLE.vbs
C:\Windows\SysWOW64\cscript.exe Print_OLE.vbs

Add trusted sites to windows registry for all users

I want to add trusted web sites to the windows registry for all users using a VBScript. I currently have a script with me and its given below. I'm neither a Windows guy nor a Visual Basic guy, so I have absolutely no idea whether the script would run or not and would it meet my needs or not. Could someone please explain the script and check whether would it run as expected.
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & _
"\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\EscDomains\google.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\EscDomains\google.com\www"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 2
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\Domains\google.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\Domains\google.com\www"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 2
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\EscDomains\hotmail.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\Domains\hotmail.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
If you feel this is an inappropiate script, please share the VBScript which you feel that would work.
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Your script is adding to current user, not all users as you said you need. Will multiple real users be logging into that machine?
The keys you need are:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\<website>.com]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\<website>.com\www]
"http"=dword:00000002
You could create a .reg file with above information for the websites and run it (put "Windows Registry Editor Version 5.00" at the top of that .reg file)
As has already been indicated, some quality time on Google will definitely enhance your knowledge of what the script you posted is trying to do and how to modify it. Don't hesitate to ask any specific (as opposed very general) questions.

Can't use VB Script to create registry keys

I can't use VB Script to create registry keys. I've hecked WMI using wbemtest and I am running the script using administrative privileges. I beleive the code is correct - I've seen several sample on the internet and it seems to be straight forward. Is there anything else within the OS that could prevent a VB Script from creating registry keys?
Sample code is below.
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "ostslhqe-48958"
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\TestKey"
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
strKeyPath = "SOFTWARE\Script Center"
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
An example of registry entry creation would be:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strValueName = "My DWORD Value"
dwValue = 13
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
Source : http://blogs.technet.com/b/heyscriptingguy/archive/2006/11/16/how-can-i-create-a-new-registry-key.aspx

Script to delete user accounts from Profile list on Windows 8.1

The following code is meant to delete all user accounts from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
Code:
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
For Each objSubkey In arrSubkeys
strValueName = "ProfileImagePath"
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
strPath=Left(strvalue,Len(strvalue)-Len(Right(strvalue,Len(strvalue)-9)))
strID=Right(strvalue,Len(strvalue)-9)
if ((strPath="C:\Users\") and (strID<>"rcadmin")) then
return=objRegistry.DeleteKey(HKEY_LOCAL_MACHINE, strSubPath)
end if
Next
wscript.echo "Done"
If I replace "return=objRegistry.DeleteKey(HKEY_LOCAL_MACHINE, strSubPath)" with "wscript.echo strID", it displays what I expect. So all I need to do now is delete the string "strSubPath" from "HKEY_LOCAL_MACHINE". And this is the part that I can not get right.
An example of the output of
wscript.echo strSubPath" is "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"\S-1-5-21-3469983464-63224933-1422604425-8029
What am I missing?

vbscript issue for removing trusted site

I have a script to add the trusted sites to IE.
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\Domains\" & "https://www.google.com"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
strValueName = "*"
dwValue = 2
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
The trusted sites are added successfully. But there is a problem here....
I am not able to remove the trusted sites added through the script which is a serious problem
Thanks in advance.
'**************************************************************************
'VBScript to remove all IE opened tab urls from the Trusted Site list
'***************************************************************************
Dim Windows
Dim tabUrl
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
Set Shell = CreateObject("Shell.Application")
Set Windows = CreateObject(Shell.Windows)
For Each Window In Shell.Windows
If InStr(1, Window.FullName, "iexplore.exe", vbTextCompare) > 0 Then
tabUrl = Window.LocationUrl
Msgbox tabUrl
strComputer = "."
Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" & "ZoneMap\Domains\" &tabUrl
objReg.DeleteKey HKEY_CURRENT_USER, strKeyPath
strValueName = "*"
dwValue = 2
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
End If
Next
The Scripting Guys article tells you how to delete keys and tells you why delete sometimes doesn't work

Resources