Link to home
Start Free TrialLog in
Avatar of Indarnav
Indarnav

asked on

add new key

vbs code to add key with its default value on "update".
Avatar of MrMintanet
MrMintanet

What?
Avatar of Indarnav

ASKER

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

sorry forgot to attach picture
Untitled.jpg
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

it did not add any thing in registry.. i checked at hklm/software/system admin.. no such key exist.
pls check at ur end once
You will have to modify my code...
what and where?? u can give me a sample code. then i will change path value etc.
ASKER CERTIFIED SOLUTION
Avatar of MrMintanet
MrMintanet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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. :)
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

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 --
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

it is not right way,, it is giving unwanted results..see attached picture
Untitled.jpg
Perhaps you should read the article, then ask questions regarding what you do not understand.
i got solution. thanks for ur advise.
Would you please post the solution that worked for you so that someone else could benefit in the future?
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: https://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 --
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

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.
I agree. :)
where  MrMintanet  gave this solution..?

this solution has been given by yehudaha..and i have given point to him.
> 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 --
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.

> 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 --
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.

> 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...
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..
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 --