Link to home
Start Free TrialLog in
Avatar of ankur3020
ankur3020

asked on

check reg_sz

i am trying to check whether

{ 7BA4C7450-9E86} value exists in registry or not and if not i want to add. but when i am using if statement it is giving error , pls tell how to write if statement for this value.

i am typing like as follows.

If value <> 7BA4C7450-9E86 Then

and error i got is "then required".
should i need to quote value i m checking or some other thing.

Avatar of brad2575
brad2575
Flag of United States of America image

you may need quotes around the value
If value <> '7BA4C7450-9E86' Then
Avatar of ankur3020
ankur3020

ASKER

still getting same error
ASKER CERTIFIED SOLUTION
Avatar of si_shamil
si_shamil
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
nothing happened.pls check attached code to find error. now even i removed if statement still not able to add below string.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "HKEY_CLASSES_user\software"
strValueName = "stop"
strValue = "7BA4C7450-9E86"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

Open in new window

You trying to write to path "HKEY_LOCAL_MACHINE\HKEY_CLASSES_user\software" Reg ValueName "stop" and Value "7BA4C7450-9E86".

Are you sere that this path exists in toy registry?
no, by mistake i added additional path.

find the correct code.


const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "software\myvb"
strValueName = "stop"
strValue = "7BA4C7450-9E86"
oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

Open in new window

In the script above you have "HKEY_CURRENT_USER" variable/constant that is not defined.

you must define it before you can use it
HIVE ID for HKEY_CURRENT_USER is &H80000001
u r ok. but real problem now i got and it is i am trying to change default key. which is not changed by my code.

pls guide how to change default key value of any registry.
pls guide now i m using attached code, but it is not working.

Set oWS = CreateObject("wscript.shell")
 
sKeyPath = "AllFilesystemObjects\shellex\ContextMenuHandlers\Send To\"
 
oWS.RegWrite "HKCR\" & sKeyPath, 0, "REG_SZ"

it is not changing value of default key.
i able to do what i tried. thanks. for your support
perfect answer