Solved

check reg_sz

Posted on 2008-10-10
11
478 Views
Last Modified: 2012-05-05
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.

0
Comment
Question by:ankur3020
  • 7
  • 3
11 Comments
 
LVL 16

Expert Comment

by:brad2575
ID: 22689575
you may need quotes around the value
If value <> '7BA4C7450-9E86' Then
0
 

Author Comment

by:ankur3020
ID: 22691872
still getting same error
0
 
LVL 5

Accepted Solution

by:
si_shamil earned 50 total points
ID: 22698833
try to use double quotes, single quotes is comments in vbscript

If value <> "7BA4C7450-9E86" Then
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:ankur3020
ID: 22703419
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

0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22704444
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?
0
 

Author Comment

by:ankur3020
ID: 22708095
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

0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22708278
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
0
 

Author Comment

by:ankur3020
ID: 22713493
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.
0
 

Author Comment

by:ankur3020
ID: 22721742
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.
0
 

Author Comment

by:ankur3020
ID: 22723448
i able to do what i tried. thanks. for your support
0
 

Author Closing Comment

by:ankur3020
ID: 31505107
perfect answer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question