Solved

add new key

Posted on 2009-04-12
33
205 Views
Last Modified: 2012-05-06
vbs code to add key with its default value on "update".
0
Comment
Question by:Indarnav
  • 15
  • 9
  • 8
33 Comments
 
LVL 8

Expert Comment

by:MrMintanet
Comment Utility
What?
0
 

Author Comment

by:Indarnav
Comment Utility
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
Comment Utility
sorry forgot to attach picture
Untitled.jpg
0
 
LVL 8

Expert Comment

by:MrMintanet
Comment Utility
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
Comment Utility
it did not add any thing in registry.. i checked at hklm/software/system admin.. no such key exist.
0
 

Author Comment

by:Indarnav
Comment Utility
pls check at ur end once
0
 
LVL 8

Expert Comment

by:MrMintanet
Comment Utility
You will have to modify my code...
0
 

Author Comment

by:Indarnav
Comment Utility
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 250 total points
Comment Utility
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 250 total points
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
it is not right way,, it is giving unwanted results..see attached picture
Untitled.jpg
0
 

Author Comment

by:Indarnav
Comment Utility
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 8

Expert Comment

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

Author Comment

by:Indarnav
Comment Utility
i got solution. thanks for ur advise.
0
 
LVL 8

Expert Comment

by:MrMintanet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I agree. :)
0
 

Author Comment

by:Indarnav
Comment Utility
where  MrMintanet  gave this solution..?

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

Author Comment

by:Indarnav
Comment Utility
0
 
LVL 39

Expert Comment

by:abel
Comment Utility
> 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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
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

7 Experts available now in Live!

Get 1:1 Help Now