Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

add new key

Posted on 2009-04-12
33
Medium Priority
?
248 Views
Last Modified: 2012-05-06
vbs code to add key with its default value on "update".
0
Comment
Question by:Indarnav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 15
  • 9
  • 8
33 Comments
 
LVL 8

Expert Comment

by:MrMintanet
ID: 24126310
What?
0
 

Author Comment

by:Indarnav
ID: 24126340
i m trying following script it is not working..

but when i run attached code, it adds hello key in microsoft as shown in picture. but i want to add hello key as new main key like active setup (see 3rd key below microsoft tree)

when i run my code it adds new string key but not aloting value to default string key.

see in picture  (default ) value is shown as value not set.
pls guide.
set shell = createobject("wscript.shell")
 
shell.Regwrite "HKLM\software\microsoft\hello","Folder Options","REG_SZ"
Set shell = Nothing

Open in new window

0
 

Author Comment

by:Indarnav
ID: 24126344
sorry forgot to attach picture
Untitled.jpg
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:MrMintanet
ID: 24126358
http://www.microsoft.com/technet/scriptcenter/scripts/os/registry/default.mspx?mfr=true

Const HKEY_LOCAL_MACHINE = &H80000002
 
strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "Expanded String Value Name"
strValue = "%PATHEXT%"
 
oReg.SetExpandedStringValue _
    HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

Open in new window

0
 

Author Comment

by:Indarnav
ID: 24126375
it did not add any thing in registry.. i checked at hklm/software/system admin.. no such key exist.
0
 

Author Comment

by:Indarnav
ID: 24126378
pls check at ur end once
0
 
LVL 8

Expert Comment

by:MrMintanet
ID: 24126395
You will have to modify my code...
0
 

Author Comment

by:Indarnav
ID: 24126407
what and where?? u can give me a sample code. then i will change path value etc.
0
 
LVL 8

Accepted Solution

by:
MrMintanet earned 1000 total points
ID: 24126441
I did...  Here it is again.
Const HKEY_LOCAL_MACHINE = &H80000002
 
strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "Expanded String Value Name"
strValue = "%PATHEXT%"
 
oReg.SetExpandedStringValue _
    HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

Open in new window

0
 
LVL 39

Assisted Solution

by:abel
abel earned 1000 total points
ID: 24126644
@Indarnav: remember the other questions you asked? All these methods have the same approach. If you get one working, just replace the call on oReg to whether you want to set a value or to retrieve a value.

All these methods are explained here: http://msdn.microsoft.com/en-us/library/aa393664(VS.85).aspx

you can use all these methods with any of the various code samples you have received throughout the day.
0
 
LVL 8

Expert Comment

by:MrMintanet
ID: 24126665
LOL.  Thanks, Abel.  I was getting a tad confused.  Honestly, I thought I had a syntax error in my code, and I'd been staring at it for a while, but to no avail.

Indarnav, if I plug in the code for you, I wouldn't suspect that you'd learn from this.  I do enjoy helping others, but I take even more pride in knowing that someone can learn from what I have given them. :)
0
 

Author Comment

by:Indarnav
ID: 24127595
below code is adding key as required..but how to add value to default..?
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject( _
    "winmgmts:{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\NewKey"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
WScript.Echo "Created registry key HKEY_LOCAL_MACHINE\SOFTWARE\NewKey"

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24128453
Use "@" for the value name, iirc, which will set the default value (I assume now you mean the value  that goes by the name  "(default)") of a certain key.

-- Abel --
0
 
LVL 39

Expert Comment

by:abel
ID: 24128465
Taking the script you have, change it like this:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject( _
    "winmgmts:{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\NewKey"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
WScript.Echo "Created registry key HKEY_LOCAL_MACHINE\SOFTWARE\NewKey"
 
 
strValueName = "@"
strValue = "some new value"
 
oReg.SetExpandedStringValue _
    HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
 
WScript.Echo "Added default value"

Open in new window

0
 

Author Comment

by:Indarnav
ID: 24129345
it is not right way,, it is giving unwanted results..see attached picture
Untitled.jpg
0
 

Author Comment

by:Indarnav
ID: 24131488
0
 
LVL 8

Expert Comment

by:MrMintanet
ID: 24131492
Perhaps you should read the article, then ask questions regarding what you do not understand.
0
 

Author Comment

by:Indarnav
ID: 24131684
i got solution. thanks for ur advise.
0
 
LVL 8

Expert Comment

by:MrMintanet
ID: 24131998
Would you please post the solution that worked for you so that someone else could benefit in the future?
0
 
LVL 39

Expert Comment

by:abel
ID: 24135585
Great that you found the solution. Remember that EE is all about solutions that the asker and the experts are trying to find together. The archive of EE is very important, and questions should be closed with an answer when there is one (and participating experts like myself would love to know how it is done to help others better next time).

Please post the answer and then select your own comment (with full answer) as the solution, together with the experts that directed you there.

See help on how to close questions: http://www.experts-exchange.com/help.jsp?hi=407 quote:

Accept your own comment as the solution
If you solved your problem with no assistance from any Expert, post your solution and then click the Accept As Solution button in your own comment.
in all other cases: split or award points to the experts that pointed you in the right direction.

-- Abel --
0
 

Author Comment

by:Indarnav
ID: 24137135
here is solution..
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject( _
    "winmgmts:{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\NewKey"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
strkey = ""
value = "test"
objreg.setstringvalue HKEY_LOCAL_MACHINE,strKeyPath,strKey,value
WScript.Echo "Created registry key HKEY_LOCAL_MACHINE\SOFTWARE\NewKey"

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24137148
Tx. Apparently you used the code provided by MrMintanet and took it from there. I suggest you split the points, select your answer as solution and give the points to MrMintanet #24126358.
0
 
LVL 8

Expert Comment

by:MrMintanet
ID: 24137154
I agree. :)
0
 

Author Comment

by:Indarnav
ID: 24146803
where  MrMintanet  gave this solution..?

this solution has been given by yehudaha..and i have given point to him.
0
 
LVL 39

Expert Comment

by:abel
ID: 24146968
> this solution has been given by yehudaha..and i have given point to him.

that was in a different thread, MrMintanet could not know he came with something similar.

Try to see any of your questions only in the context of the current thread. We, the experts, do not know anything from your previous questions and we always assume that if you have previous questions, you have closed them appropriately.

In this thread, MrMintanet came with a solution (here: #24126441 is the answer) maybe on his own, maybe through research and googling (the way I did it for your other question). Please give him the proper credits for doing so (A-grade) and investing time and energy helping you out (and make sure your comment is checked as final answer). That's the way EE works.

Check the Help section (moderator CoolleoMod pasted the link) for more info on asking questions and awarding points.

-- Abel --
0
 

Author Comment

by:Indarnav
ID: 24154345
dear : #24126441 is the answer)  is not correct solution... if u have doubt u can run the code and check.

in : #24126441 is the answer)  answer, strkey is not defined, which is main in the solution.

i just say, u can run both code exactly as they are given here and compare their results. if both are doing same, tell me . i will share point equally as u said.

0
 
LVL 39

Expert Comment

by:abel
ID: 24156108
> dear : #24126441 is the answer)  is not correct solution... if u have doubt u can run the code and check. > answer, strkey is not defined, which is main in the solution.

I did. I don't know where you see a strKey, but if you copy and paste, there is no strKey, only a strValueName (which is replaced by strKey in your own solution). That's a variable name.
> if both are doing same, tell me .

That's not the point here. They're not supposed to do the same....

Remember that EE is about pointing you in the direction of how to do it, not doing the job for you. You're making that hard. If you feel you should treat experts differently then the guidelines, or if you think we are totally off here, that's fine. Everybody's entitled to his or her own opinions.

But we are here to help, and we are doing so for the credits we get and even more so, for knowing we made someone's day by showing them a way out of their problem. That's the only "payment" we have. If we can't make you happy because we can't make you understand the solution, we will continue to try to help you to understand it (usually).

It's up to you what you do with this info. I suggest next time you put in your question that you need a full working solution so that we know that we should only help if we want to do the job for you and not only give some helpful hints and pointers.

-- Abel --
0
 

Author Comment

by:Indarnav
ID: 24158152
abels, the solution provided in #24126441 is the answer, is not what i have asked.. what i asked is given by yehudaha. so that's it.

read my requirement and just compare,is solution given in #24126441 is the answer is fullfilling or guiding me that way or not. i do not think so. i did not ask how to write/add regsitry. i asked specifically how to set value for default key.read my question and my first 2 inputs where i attached picture.

0
 
LVL 39

Expert Comment

by:abel
ID: 24158289
> what i asked is given by yehudaha. so that's it.

you're funny. There is no post where-ever of "yehudada" in this thread, so that's way off and ridiculous. Please refer to my earlier comment that you should keep a discussion in one thread.

I don't say the answer is correct, I say it is closest to what you came up with yourself. Give the guy his dues, or not. It is up to you. But you're by en large violating the guidelines of EE and people remember that...

> i asked specifically how to set value for default key.

I know, but that's not the point here, you are not reading my comments....

Like I said, the comment was closest to what you came up with. That you ask in two threads the same thing is strongly discouraged by Experts-Exchange. If you do so, you pull the fruits of your actions: confusion and incomplete threads.

That you didn't give an expert the chance to discuss with you towards a solution after possibly misinterpreting your question (as I did, too), is one thing, but not meriting his/her efforts, is another thing.

But I'm a bit done with this, sorry, but like everybody else I'm a volunteer and sometimes you just have to step back. Sorry it goes this way and that you do not want to read up on the guidelines, nor act like them. Remember that this is a way to miss out on many good advices...
0
 

Author Comment

by:Indarnav
ID: 24158365
abel,
i understand ur concern, answer might be close from ur point. but i did not get anything from there. so that was not of my use.

anyway, now, please leave this...i have given equal points to both . so close the matter and be happy..
i try to abide ee rules next time and hope ur volunteer involvement in other questions too..

thanks once again..
0
 
LVL 39

Expert Comment

by:abel
ID: 24158526
Thanks for closing this (I didn't mean you give me points, I don't think I helped you, but thanks anyway ;-)

Maybe a good idea in the future if you give a follow-up question on something you already asked in another thread is to refer to that other question by pasting in a link to it. Then experts can see what solutions have already been given. Even better is posting the solution you already have and then comment on the line where you are lost.

thanks again, no hard feelings,

-- Abel --
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

660 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