Sign in to follow this  
Followers 0
prpldodge

Reading a sting from a variable

8 posts in this topic

I want to add the path of office to the environmental path. I can read the registry but do not want to add the path if it already there. Here is what I am trying. I am using the message box to see what is returned but it keeps coming back it can not find it. I have verified the path is in the path statement.

Global $join, $path,

$path = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.EXE", "Path")

$cur = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","path")

$result = StringInStr("$cur","path")

MsgBox(4096, "Program files are in:", $result)

Alan

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Unlike some other languages, AutoIt will not render variables in quotes.

$result = StringInStr("$cur","path")

$result = StringInStr($cur,$path)

Edited by weaponx

Share this post


Link to post
Share on other sites

Unlike some other languages, AutoIt will not render variables in quotes.

$result = StringInStr("$cur","path")

$result = StringInStr($cur,$path)

Thank you weaponix for your fast response

Ok if I understand you I can take out the quotes and it should work. I tried that and I still get a 0 as the results. I assume that means it did not find it. I have verified it is there so I guess I am still missing something. Is there a better way?

Alan

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

When you are having this kind of problem, always take another look at what is in your variables:

$path = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.EXE", "Path")
$cur = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "path")
$result = StringInStr($cur, $path)

MsgBox(4096, "Program files are in:", $cur & @CRLF & $path & @CRLF & $result)

[edit] hehe, forgot to pull the original quote issue out of my example

Edited by SpookMeister

[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

When you are having this kind of problem, always take another look at what is in your variables:

$path = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.EXE", "Path")
$cur = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "path")
$result = StringInStr($cur, $path)

MsgBox(4096, "Program files are in:", $cur & @CRLF & $path & @CRLF & $result)

[edit] hehe, forgot to pull the original quote issue out of my example

Same general thought process - this example will break all of the %PATH% entries into individual lines for easier readability:

Global $join, $path, $cur
$path = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.EXE", "Path")
$cur = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","path")
$envpaths = StringSplit($cur,";")

$envlist = ""
For $i = 1 To $envpaths[0]
    $envlist &= $envpaths[$i] &@LF
Next

MsgBox(4096, "Comparison:", "Winword.exe path:" &@LF &$path &@LF &@LF &"**************"  &@LF &@LF &"Environment Variable 'Path' entries:" &@LF &$envlist)

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

When you are having this kind of problem, always take another look at what is in your variables:

$path = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.EXE", "Path")
$cur = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "path")
$result = StringInStr($cur, $path)

MsgBox(4096, "Program files are in:", $cur & @CRLF & $path & @CRLF & $result)

[edit] hehe, forgot to pull the original quote issue out of my example

Thanks. Why can it stare you right in the eye and you not see it. There was a "\" at the end of the path statement and not in the other.

Alan

Share this post


Link to post
Share on other sites

Thanks. Why can it stare you right in the eye and you not see it. There was a "\" at the end of the path statement and not in the other.

Alan

OK I thought this should be so simple but I am not getting the results. Caution running this it could mess up your path statement. It just returns the $cur

Global $join, $path, $cur, $result, $newpath
$path = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.EXE", "Path")
$cur = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","Path")
$result = StringInStr($cur,$path)
$newpath = StringTrimRight($path, 1)

If $result < 1 then
         
      If StringRight($CUR, 1) = ';' then 
        RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', 'REG_SZ', $cur & $newpath) 
            
                    
      If StringRight($CUR, 1) not = ';'then
        RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', 'REG_SZ', $cur & ";" & $newpath) 

    endif

ElseIf $result > 0 then
    
    MsgBox(0, 'Path does not need to be changed ', $cur)

    EndIf

EndIf
MsgBox(0, 'Path Changed', $cur)

Share this post


Link to post
Share on other sites

Global $path, $cur, $result, $newpath
$path = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.EXE", "Path")
$cur = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path")
$newpath = StringTrimRight($path, 1)
$result = StringInStr($cur, $newpath)
If $result = 0 Then
    Select
        Case StringRight($cur, 1) = ';'
            RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', 'REG_SZ', $cur & $newpath)
        Case StringRight($cur, 1) <> ';'
            RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', 'REG_SZ', $cur & ";" & $newpath)
    EndSelect
    MsgBox(0, 'Path Changed', RegRead('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path'))
ElseIf $result > 0 Then
    MsgBox(0, 'Path does not need to be changed ', RegRead('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path'))
EndIf

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