Sign in to follow this  
Followers 0
englundg

How to modify registry environment path

10 posts in this topic

I am brand new to scripting and AutoIt and would appreciate any help. I need to delete an entry to the environment variable path that was inadvertently made by 3rd party application. The script needs to be deployed to 700 desktops. Specifically, I need to do the following, leaving the rest of the entries in the path intact. Thanks.

Delete: \;c:\Program files\Optika\Acorde

From:

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

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager\Environment

Share this post


Link to post
Share on other sites



And to filter, maybe something like this:

$input = "c:\;c:\Windows;\;c:\Program files\Optika\Acorde;C:\Utils"
;$input="abcdefghijklmnopqrstuvwxyz"
$bad = "\;c:\Program files\Optika\Acorde"
;$bad = "mnop"
$output = _StripStringMid($input, $bad)
ConsoleWrite("Input=" & $input & @CRLF)
ConsoleWrite("Bad=" & $bad & @CRLF)
ConsoleWrite("Output=" & $output & @CRLF)
Func _StripStringMid($iString, $iFilter)
    $pre = StringTrimRight($iString, StringLen($iString) - StringInStr($iString, $iFilter) + 1)
    $tmp = StringTrimLeft($iString, StringLen($pre))
    $post = StringTrimLeft($tmp, StringLen($iFilter))
    Return $pre & $post
EndFunc   ;==>_StripStringMid

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Thanks for replying.

I have entered the following line but it stops at highlighting the Environment key. How do I read what is in the path and then use RegWrite to delete a segment of it. Here is what I have done so far:

RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path")

An example of the existing path on one system is:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Altiris\Software Virtualization Agent\\;c:\Program Files\Optika\Acorde;c:\Program files\Stellent\IBPM

I want to delete just the following: \;c:\Program Files\Optika\Acorde

When it is done I want it to read:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Altiris\Software Virtualization Agent\;c:\Program files\Stellent\IBPM

Share this post


Link to post
Share on other sites

Maybe it will make more sense to you this way:

$input = "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Altiris\Software Virtualization Agent\\;c:\Program Files\Optika\Acorde;c:\Program files\Stellent\IBPM"
$bad = "\;c:\Program Files\Optika\Acorde"
MsgBox(0, "Results", "Input=" & $input & @CRLF & "Bad=" & $bad & @CRLF & "Output=" & _StripStringMid($input, $bad))
Func _StripStringMid($iString, $iFilter)
    $pre = StringTrimRight($iString, StringLen($iString) - StringInStr($iString, $iFilter) + 1)
    $tmp = StringTrimLeft($iString, StringLen($pre))
    $post = StringTrimLeft($tmp, StringLen($iFilter))
    Return $pre & $post
EndFunc   ;==>_StripStringMid

Add in the regread and regwrite portions and you are in business


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

If your just starting out, something a little more basic/easier to understand (and of course not so elegant) would be to do something like the following for each key, that way if a computer has different entries in that key your not affecting them, your only targeting what is part of your "delete" pattern.

$pattern = ";c:\Program files\Optika\Acorde"

$reg = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path")
$New = StringReplace($reg,$pattern,"")
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","Path","REG_EXPAND_SZ",$new)

etc.
etc.
etc.

Share this post


Link to post
Share on other sites

Thanks to both of you for responding. It looks like the more basic approach is going to work. I will update you but this is really a huge help. Thanks again!

Share this post


Link to post
Share on other sites

The last suggestion was very helpful and got the job done. Thanks to both of you for responding. The latter script was easier for me to manage since I am new to scripting but thanks for all of your help. The script was successful!

Share this post


Link to post
Share on other sites

Sounds like you are already done. But my only question would be, why are you scripting this with AutoIt? Was there something else more complex in the script too? If not, simple cmd line would have sufficed and supports remote computers. Do REG /?

Share this post


Link to post
Share on other sites

The primary task was to remove a section in the environment path statement where the faulty entry existed, leaving the rest of the path intact. I looked at the reg help am uncertain as how to accomplish this. Can you tell me how do this with a simple reg command? I needed to look for the pattern above in the path value and delete it.

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