Jump to content
Sign in to follow this  
stev379

Edit Registry value

Recommended Posts

stev379

I can do this myself, but not quickly and I've got fires burning with staff unable to logon and can't remain at my desk to work on the global fix while I run around assisting individuals.

I need to move part of a registry value to the front of it's string.

In most cases, the value to move will be at the end of the string, but in some cases, it may be second to last or third etc. I need to move it to the front and of course remove the superflous commas.

Any suggestions on completing this are immensely appreciated. Thanks!!!

$ValToMove = "PGPpwflt"

$VAL_HwOrder = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder")

If StringInStr($VAL_HwOrder, ",PGPpwflt") Then

$Split = StringSplit($VAL_HwOrder, ",")

For $i = 1 To $Split[0]

If $Split[$i] = $ValToMove Then....

Share this post


Link to post
Share on other sites
GEOSoft

This can be solved very quickly if you post exactly what the bad string is and what the new string should be. It's a simple RegExReplace.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
stev379

This can be solved very quickly if you post exactly what the bad string is and what the new string should be. It's a simple RegExReplace.

Thanks for the reply.

The bad string isn't always the same, but it's most likely: "RDPNP,LanmanWorkstation,WebClient,PGPpwflt" minues the quotes.

On some machines, there may be extra data before or after the "PGPpwflt".

The good string should be whatever that machines original string is except "PGPpwflt" should be at the front: PGPpwflt,RDPNP,LanmanWorkstation,WebClient

Share this post


Link to post
Share on other sites
stev379

Thanks for the reply.

The bad string isn't always the same, but it's most likely: "RDPNP,LanmanWorkstation,WebClient,PGPpwflt" minues the quotes.

On some machines, there may be extra data before or after the "PGPpwflt".

The good string should be whatever that machines original string is except "PGPpwflt" should be at the front: PGPpwflt,RDPNP,LanmanWorkstation,WebClient

I think I got it, but it sounds like you may have a better method. What do you think?

Dim $FinalString

Dim $FinalString_HwOrder

Dim $FinalString_Order

$ValToMove = "PGPpwflt"

$VAL_HwOrder = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder")

$VAL_Order = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order", "ProviderOrder")

If @error <> 0 Then MsgBox(0, @error, "Error: " & @error)

If StringInStr($VAL_HwOrder, ",PGPpwflt") Then

$Split = StringSplit($VAL_HwOrder, ",")

For $i = 1 To $Split[0]

If $Split[$i] = $ValToMove Then

$StringMinusPGPpwflt = StringReplace($VAL_HwOrder, $ValToMove, "")

$FinalString = $Split[$i] & "," & $StringMinusPGPpwflt

If StringRight ($FinalString, 1) = "," Then $FinalString = StringTrimRight($FinalString, 1)

If StringInStr($FinalString, ",,") Then $FinalString_HwOrder = StringReplace($FinalString, ",,", ",")

EndIf

Next

EndIf

MsgBox(0,'', $FinalString_HwOrder)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder", "REG_SZ", $FinalString_HwOrder)

$FinalString = ""

If StringInStr($VAL_Order, ",PGPpwflt") Then

$Split = StringSplit($VAL_Order, ",")

For $i = 1 To $Split[0]

If $Split[$i] = $ValToMove Then

$StringMinusPGPpwflt = StringReplace($VAL_Order, $ValToMove, "")

$FinalString = $Split[$i] & "," & $StringMinusPGPpwflt

If StringRight ($FinalString, 1) = "," Then $FinalString = StringTrimRight($FinalString, 1)

If StringInStr($FinalString, ",,") Then $FinalString_Order = StringReplace($FinalString, ",,", ",")

EndIf

Next

EndIf

MsgBox(0,'', $FinalString_Order)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order", "ProviderOrder", "REG_SZ", $FinalString_Order)

Share this post


Link to post
Share on other sites
GEOSoft

That's doing it the hard way

$sVal = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder")
$iType = @Extended
Switch $iType
    Case 1
        $sType = "REG_SZ"
    Case 2
        $sType = "REG_EXPAND_SZ"
    Case 3
        $sType = "REG_BINARY"
    Case 4
        $sType = "REG_DWORD"
    Case 7
        $sType = "REG_MULTI_SZ"
    Case 11
        $sType = "REG_QWORD"
    Case Else
        $sType = 0
EndSwitch
$sVal = StringRegExpReplace($sVal, "(?i)(.*),(PGPpwflt)(.*)", "$2,$1$3")
If @Extended AND $sType > 0 Then RegWrite("HKLM64\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder", $sType, $sVal)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

In fact, since we already know what $sType is in this case just run this

$sVal = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder")
$sVal = StringRegExpReplace($sVal, "(?i)(.*),(PGPpwflt)(.*)", "$2,$1$3")
If @Extended Then RegWrite("HKLM64\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder", "REG_SZ", $sVal)

Edit: I should add that the script will have no effect on a value which is already correct since the RegEx will only work if PGPpwflt follows a comma.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
zorphnog

Well to be exact:

$sVal = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder")
$sVal = StringRegExpReplace($sVal, "(?i)(.*),(PGPpwflt)(.*)", "$2,$1$3")
If @Extended Then RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder", "REG_SZ", $sVal)
$sVal = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order", "ProviderOrder")
$sVal = StringRegExpReplace($sVal, "(?i)(.*),(PGPpwflt)(.*)", "$2,$1$3")
If @Extended Then RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order", "ProviderOrder", "REG_SZ", $sVal)

Share this post


Link to post
Share on other sites
Spiff59

Hard to argue with how much you can accomplish with a regular expression.

Some day I might make an effort to get a better handle on them (such as back referencing)

I went the wimpy route and modified stev's last example:

#include <array.au3>

$ValToMove = "PGPpwflt"
$VAL_HwOrder = "RDPNP,LanmanWorkstation,WebClient,PGPpwflt,dddd"
;$VAL_HwOrder = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder")
If @error Then MsgBox(0, @error, "Error: " & @error)
$VAL_HwOrder = Shift($VAL_HwOrder)
MsgBox(0,'', $VAL_HwOrder)
;RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder", "REG_SZ", $FinalString_HwOrder)

Func Shift($in)
    If Not StringInStr($in, $ValToMove) Then Return($in)
    $Split = StringSplit($in, ",")
    _ArrayDelete($Split, _ArraySearch($Split, $ValToMove))
    $Split[0] = $ValToMove
    Return _ArrayToString($Split, ",")
EndFunc
Edited by Spiff59

Share this post


Link to post
Share on other sites
GEOSoft

Just use something decent to test the SREs with and you will catch on quickly. I think I'm uploading a new version of the beta tomorrow.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
stev379

:idea::):(

You guys are awesome. I'm a 6-7 year occasional user of AutoIT who suggests it to anyone who needs to script. I wish I could spend more time on it or focus my time soley on scripting period. To get this kind of assistance within this time frame is impressive to say the least. I get a faster response from you than checking with our own DBA's on SQL issues.

Thank you for the time!!!

I'm going with GEO's offering below, but will retain all options as each one taught me something different.

$sVal = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder")

$sVal = StringRegExpReplace($sVal, "(?i)(.*),(PGPpwflt)(.*)", "$2,$1$3")

If @Extended Then RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder", "ProviderOrder", "REG_SZ", $sVal)

$sVal = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order", "ProviderOrder")

$sVal = StringRegExpReplace($sVal, "(?i)(.*),(PGPpwflt)(.*)", "$2,$1$3")

If @Extended Then RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order", "ProviderOrder", "REG_SZ", $sVal)

Share this post


Link to post
Share on other sites
GEOSoft

Steve, if you're still around. Change that back to the way I gave it to you. I just spotted what Zorphnog did to it other than calling the RegEx twicw. I made it HKLM64 for a reason.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
zorphnog

Sorry, I switched it because I thought you had made a typo. Why HKLM64? I didn't see anything about 64-bit in the OP.

Share this post


Link to post
Share on other sites
GEOSoft

Sorry, I switched it because I thought you had made a typo. Why HKLM64? I didn't see anything about 64-bit in the OP.

It's for a reason that I won't discuss publicly in the forums. I've been using it that way for a long time now and just accept that it works fine. I just hope that Steve ia either still following this thread OR that he doesn't run into a situation where he thinks it has to be re-written.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
stev379

It's for a reason that I won't discuss publicly in the forums. I've been using it that way for a long time now and just accept that it works fine. I just hope that Steve ia either still following this thread OR that he doesn't run into a situation where he thinks it has to be re-written.

Got it and updated. Thanks for the follow up!!

Share this post


Link to post
Share on other sites
GEOSoft

And that means everything is working now?


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
stev379

And that means everything is working now?

Sorry again for the delayed repy. 9 month old daughter had a 104 temp for a couple days! :idea:

Yes. All is well on this front. The registry value's data gets re-ordered exactly as desired. The overall issue we're having with the product persists, but this fix has now been successfully implemented and we can cross this off the list.

Thanks!!

Share this post


Link to post
Share on other sites
GEOSoft

No problem. Come back if we can help further.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.