Solved

check reg_sz

Posted on 2008-10-10
11
475 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now