Solved

check reg_sz

Posted on 2008-10-10
11
472 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
Comment Utility
you may need quotes around the value
If value <> '7BA4C7450-9E86' Then
0
 

Author Comment

by:ankur3020
Comment Utility
still getting same error
0
 
LVL 5

Accepted Solution

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

If value <> "7BA4C7450-9E86" Then
0
 

Author Comment

by:ankur3020
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:ankur3020
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i able to do what i tried. thanks. for your support
0
 

Author Closing Comment

by:ankur3020
Comment Utility
perfect answer
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

12 Experts available now in Live!

Get 1:1 Help Now