Search and replace registry

(imported comment written by SystemAdmin)

The brackets just tell action script to interpret whatever is in them as relevance. Since you already have the expression in brackets, adding “{parameter “_FindServer” of action }” is equivalent to putting brackets into QNA, which is an illegal character.

replace those brackets with parentheses and you should be fine

-Zak

(imported comment written by SystemAdmin)

Since you can’t guarentee that the user of your fixlet will always type in lowercase, you might want to lowercase the parameter.

I didn’t test this (I’m at home), but maybe something like:

appendfile {("%22" & name of it & “%22=%22” & escape of ("\SOMETHINGELSE" & following text of position 13 of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with (parameter “_FindServer” of action as lowercase)) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry}

(imported comment written by tscott91)

OK… I got it working with one action parameter…

appendfile {("%22" & name of it & “%22=%22” & escape of ("\SOMETHINGELSE" & following text of position 13 of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with

parameter “_FindServer” of action

) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry}

It didn’t work when I tried to add another:

appendfile {("%22" & name of it & “%22=%22” & escape of ("\SOMETHINGELSE" & following text of position

parameter “_NumberofCharacters” of action

of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with parameter “_FindServer” of action) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry}

What am I doing wrong now?

(imported comment written by SystemAdmin)

I’d suspect your parameter is being treated as a string.

Try this:

appendfile {("%22" & name of it & “%22=%22” & escape of ("\SOMETHINGELSE" & following text of position (parameter “_NumberofCharacters” of action as integer) of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with parameter “_FindServer” of action) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry}

Paul

(imported comment written by SystemAdmin)

For what it’s worth, depending on how you’re using the fixlet will denote the best approach to writing the whole relevence. In the sample I started you with, it was assumed that we’re manipulating environment variables that contain a UNC where you need to replace the server with another. So I’m assuming it must be “\” + oldserver + “”.

I wouldn’t bother with your second parameter at all. The second parameter is simply the length of the old server name + 3.

So skip _NumberofCharacters and change it to be…

appendfile {("%22" & name of it & “%22=%22” & escape of ("\SOMETHINGELSE" & following text of position

(3+length of parameter “_FindServer” of action)

of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with (parameter “_FindServer” of action

as lowercase

)) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry}

ps. I added the additional “as lowercase”. See the bolded areas.

Paul

(imported comment written by tscott91)

OK. This is what I have now:

appendfile {("%22" & name of it & “%22=%22” & escape of (parameter “_ReplaceServer” of action & following text of position (3+length of parameter

“_ReplaceServer”

of action) of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with (parameter “_FindServer” of action as lowercase)) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry}

I had to change the bolded parameter to the REPLACE server and not the find server… Have an issue still, however…

Here are the results:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

“CBSDRIVE”="\\tom\\CBSAPPS"

“HOME-FS”="\\tom\\CBSAPPS"

Here is what the results NEED to look like:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

“CBSDRIVE”="\\tom

\

CBSAPPS"

“HOME-FS”="\\tom

\

CBSAPPS"

The action is putting another set of “\” and I’m not sure why…

Also, to make this easier for user input… It will also be a UNC so it would be nice if I didn’t have to enter the \ before the server name and the \ after (ie: \SERVERNAME\ ) and instead would be nice to just enter the server name for both the find and replace values.

Thanks so much.

(imported comment written by SystemAdmin)

No, it’s 3+length of _FindServer. In the registry it’s currently like “\findserver\whatever”. We’re trying to take everything after “\findserver” which is simply “whatever”. So you need to take everything after position 13 in this case. If it was “\old\whatever” in the registry, then we want to take everything after position 6.

To not have to type in the backslashes, just add it to the action…

appendfile {("%22" & name of it & “%22=%22” & escape of ("\" & parameter “_ReplaceServer” of action & “” & following text of position (3+length of parameter “_FindServer” of action) of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with (parameter “_FindServer” of action as lowercase)) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry}

Paul

(imported comment written by tscott91)

Paul, almost there!

One last thing is the “FindServer” I still have to type in the \SERVERNAME\ instead of SERVERNAME… When I type in just servername it doesn’t find anything but when I type in \servername\ it does.

Thanks!!

(imported comment written by SystemAdmin)

Try this:

("%22" & name of it & “%22=%22” & escape of ("\" & parameter “_ReplaceServer” of action & “” & following text of position (3+length of parameter “_FindServer” of action) of it & “%22%0d%0a”) of (it as string)) of values whose (it as string as lowercase starts with ("\" & parameter “_FindServer” of action as lowercase & “”)) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry

(imported comment written by tscott91)

I need the very last “” to not be there…

So this:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

“CBSDRIVE”="\\server-fs\CBSAPPS"

Needs to be this:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

“CBSDRIVE”="\\server-fs\CBSAPPS"

I tried dropping the & “” after the “of action as lowercase” but it still included it…

(imported comment written by SystemAdmin)

I’m assuming it was in the registry to begin with?

(imported comment written by tscott91)

Nope, the registry looks just like the second example…

http://img715.imageshack.us/img715/1185/110117134414itlap192168.jpg

(imported comment written by SystemAdmin)

Found it. A double-quote in unicode would be "

Try creating a value in the registry with a ", then export that to a .reg. You’ll see it’s in there as "

So that makes sense.

Like this:

escape of “%22”

Try this. I put the “%22%0d%0a” outside of the “escape of”:

("%22" & name of it & “%22=%22” & escape of ("\" & parameter “_ReplaceServer” of action & “” & following text of position (3+length of parameter “_FindServer” of action) of it) of (it as string) & “%22%0d%0a”) of values whose (it as string as lowercase starts with ("\" & parameter “_FindServer” of action as lowercase & “”)) of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry

(imported comment written by tscott91)

Paul, you are the MAN!

For the relevance… Would I be able to use something like this or would this not work?

exists value

whose

(

it as string as lowercase starts with parameter “_FindServer” of action

)

of key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” of registry

(imported comment written by SystemAdmin)

No, action parameters can only be in actions.

If you have a known number of server names that need to be replaced, you should look for those specific server names in the relevance. In doing that, you can probably eliminate the whole parameter thing since you know that the PCs must have at least 1 of the targeted server names to replace. But that would change your action around again. This is why it’s good to define your relevence properly so you don’t keep rewriting your actions.

(imported comment written by tscott91)

Sorry to bump again… This should be easy for you Paul but not so much for me… You helped me find and replace variables… Now I simply want to be able to create a NEW one with the action parameters…

IE:

Action Parameter: Variable Name (SAMPLE_NAME)

Action Parameter: Variable Value (\SERVERNAME\SHARENAME)

Sample reg file:

Windows Registry Editor Version 5.00

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

“PRT1”="\\PRINT_SERVER\BACKOFFICE2430"

Thanks!

(imported comment written by SystemAdmin)

So your the action parameters would contain “Variable Name”=“PRT1” and “Variable Value”="\PRINTSEVER\BACKOFFICE2430" for your sample reg file?

(imported comment written by tscott91)

I think I got it… It worked anyways…

action parameter query “_VariableName” with description “Please enter the variable NAME:” with default value “HOME-FS”

action parameter query “_VariableValue” with description “Please enter the variable VALUE. NOTE THE DOUBLE SLASH AFTER THE SERVER NAME:” with default value “\SERVERNAME\CBSAPPS”

delete __appendfile

delete variable.reg

appendfile Windows Registry Editor Version 5.00

appendfile

appendfile

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

appendfile {"%22" & parameter “_VariableName” & “%22=%22” & “\” & parameter “_VariableValue” & “%22”}

move __appendfile variable.reg

wait regedit /s variable.reg

(imported comment written by SystemAdmin)

Yep, that will work. But maybe you want to look at “escape of” so the console user can enter it as \server\service without having to remember the extra slashes.

Paul

(imported comment written by tscott91)

That would be even better. How do I go about doing that?