![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | %SystemRoot% being changed in script Modified a script I found online that removes specified strings from the Path environment variable. It works, but one thing it does that I don't get is change "%SystemRoot%" to the hard-coded value of the variable ("C:\Windows\system32", for example). Can anyone tell me why it does that, or how I can prevent it? Here's the code: Option Explicit On Error Resume Next Dim objReg, strComputer, strValueRight, strValueLeft Dim strSearchFor, strKeyPath, strEntryName, strValue Dim strTotalLength, strSearchForLength, strStartAt dim strArraySearchFor Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." strArraySearchFor=Array("C:\blah;") ' Connect to the registry (StdRegProv) ' Get the value for strValue (GetExpandedStringValue) Set objReg=GetObject _ ("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" strEntryName = "path" objReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue If (Right(strValue, 1) <> ";") Then strValue=strValue+";" objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath,strEntryName, strValue End if For Each strSearchFor In strArraySearchFor surgery Next Wscript.Quit(1) Function surgery ' Calculates strStartAt which cuts the strSearchFor value from the path strSearchForLength=Len(strSearchFor) strStartAt = inStr(lCase(strValue), lCase(strSearchFor)) ' Build the new path ' join the values to the left and right of strSearchFor strTotalLength=Len(strValue) strValueLeft=Left(strValue,(strStartAt-1)) strValueRight=Right(strValue, (strtotalLength-strSearchForLength-(strStartAt-1))) strValue=strValueLeft + strValueRight ' Reset the path in the registry (SetStringValue) objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath,strEntryName, strValue End Function |
My System Specs![]() |
| | #2 (permalink) |
| | Re: %SystemRoot% being changed in script "Tony Logan" <TonyLogan@xxxxxx> wrote in message news:765B1BC4-0C27-41BE-B90A-6EA278601912@xxxxxx Quote: > Modified a script I found online that removes specified strings from the > Path > environment variable. It works, but one thing it does that I don't get is > change "%SystemRoot%" to the hard-coded value of the variable > ("C:\Windows\system32", for example). > > Can anyone tell me why it does that, or how I can prevent it? > then all environmental variables are resolved. You will have to "unresolve" them by obtaining the value x=%SystemRoot%, then performing this function: path = replace(path, x, "%SystemRoot%", 1, -1, 1) (untested) |
My System Specs![]() |
| | #3 (permalink) |
| | Re: %SystemRoot% being changed in script "Tony Logan" <TonyLogan@xxxxxx> wrote in message news:765B1BC4-0C27-41BE-B90A-6EA278601912@xxxxxx Quote: > Modified a script I found online that removes specified strings from the > Path > environment variable. It works, but one thing it does that I don't get is > change "%SystemRoot%" to the hard-coded value of the variable > ("C:\Windows\system32", for example). > > Can anyone tell me why it does that, or how I can prevent it? program is not nice. It makes trouble-shooting very difficult. Much better to insert specific code that deals with errors, e.g. by checking for the existence of a file *before* attempting to open it. Alternatively you could cover individual blocks of code with an "On Error" statement and take appropriate action when an error occurs (which you can determine by checking err.number). |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Changed monitor also changed position of Window Mail Send/Receivewindow | Vista mail | |||
| How to find %SystemRoot%\System32 folder | Vista General | |||
| Re: VB Script Code to get alert when a folder get changed in intranet FTP Folder | VB Script | |||
| Changed User name, but User folder name didnt get changed? | Vista account administration | |||
| I need to change my %SystemRoot% | Vista account administration | |||