Jump to content

stringregexp to get two file paths


Recommended Posts

There is a portable program. When this program runs, it leaves no other traces in the MuiCache registry key.
There are two versions of the program, Beta and Release.
I need to check the existence of Plugin.pl file. If there is a plug-in in both folders, the file path has after loop (MyPluginC:\) merged problem, the following sample codes are available.

#RequireAdmin
#cs
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache]
"C:\\Users\\USER\\Desktop\\Program\\GeneralPurposeAppz\\Beta\\my.exe"="my.exe"
"C:\\Users\\USER\\Desktop\\Program\\GeneralPurposeAppz\\Release\\my.exe"="my.exe"
"LangID"=hex:1f,04
#ce

Local $Enum = 0
Local $sSubkey
$found = ""
Local $sKey = "HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
While 1
    $Enum = $Enum + 1
    $sSubkey = RegEnumVal($sKey, $Enum)
    If @error <> 0 Then
        ExitLoop
    Else
        If StringInStr($sSubkey, "my.exe") Then
            If FileExists($sSubkey) Then
                $Replace = StringReplace($sSubkey, "my.exe","")
                If FileExists($Replace & "MyPlugin\plugin.pl") Then
                    $found &= $Replace
                    ;ConsoleWrite($found & @CRLF)
                Else
                    $found &= "No plugin.pl found"
                EndIf
            EndIf
        EndIf
    EndIf
WEnd
If StringInStr($found, "\GeneralPurposeAppz\") Then
ConsoleWrite("$found : " & $found & @CRLF)
;---------------------------------
;C:\Users\USER\Desktop\Program\GeneralPurposeAppz\Beta\C:\Users\USER\Desktop\Program\GeneralPurposeAppz\Release\
;The problem is exactly that ShellExecute won't run because it gives an error.
ShellExecute($found & "MyPlugin\")
;----------------------------------
Else
MsgBox(48,"Not found", $found)
EndIf

 

Edited by youtuber
Link to comment
Share on other sites

You are concatenating without adding an @CRLF to $found, so will just display one line

$found &= $Replace

;Use:
$found &= $Replace & @CRLF

You also appear to have different format for MuiCache, I see values with .ApplicationCompany and .FriendlyAppName for example:

C:\Program Files\TechSmith\Snagit 2020\SnagitEditor.exe.ApplicationCompany
C:\Program Files\TechSmith\Snagit 2020\SnagitEditor.exe.FriendlyAppName

To get the path and filename (with or without the .ApplicationCompany or .FriendlyAppName) you could use something like:

$aSubkey = StringRegExp($sSubkey, "(.*\\(?:[^.]*$)?)(.*\.exe)", 3)
    If Not @error Then
        ConsoleWrite("Directory : " & $aSubkey[0] & @CRLF & "Filename : " & $aSubkey[1] & @CRLF)
    EndIf

 

Link to comment
Share on other sites

The problem continues.

Gives "Windows cannot find" error in ShellExecute command.

https://prnt.sc/10lmubx

#RequireAdmin
Local $Enum = 0
Local $sSubkey
$found = ""
Local $sKey = "HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
While 1
    $Enum = $Enum + 1
    $sSubkey = RegEnumVal($sKey, $Enum)

    If @error <> 0 Then
        ExitLoop
    Else
        If StringInStr($sSubkey, "my.exe") Then
            $aSubkey = StringRegExp($sSubkey, "(.*\\(?:[^.]*$)?)(.*\.exe)", 3)
            If Not @error Then
                If FileExists($aSubkey[1]) Then
                    ConsoleWrite($aSubkey[1] & @CRLF)
                    ;ConsoleWrite("Directory : " & $aSubkey[0] & @CRLF & "Filename : " & $aSubkey[1] & @CRLF)
                    If FileExists($aSubkey[0] & "MyPlugin\plugin.pl") Then
                        $found &= $aSubkey[0] & @CRLF
                        ConsoleWrite($found & @CRLF)
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
WEnd
If StringInStr($found, "\GeneralPurposeAppz\") Then
    ;ConsoleWrite("$found : " & $found & @CRLF)
    ShellExecute($found & "MyPlugin\")
Else
    MsgBox(48, "Not found", $found)
EndIf

 

Link to comment
Share on other sites

So on Windows 10 you would need to detect if that folder has already been found, you would also need to separate variables to hold Beta and Release directory

Example: (Untested)

#RequireAdmin
Local $Enum = 0
Local $sSubkey
Local $sBetaDir, $sReleaseDir
Local $sKey = "HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
While 1
    $Enum = $Enum + 1
    $sSubkey = RegEnumVal($sKey, $Enum)

    If @error <> 0 Then
        ExitLoop
    Else
        If StringInStr($sSubkey, "my.exe") Then
            $aSubkey = StringRegExp($sSubkey, "(.*\\(?:[^.]*$)?)(.*\.exe)", 3)
            If Not @error Then
                If FileExists($aSubkey[1]) Then
                    ConsoleWrite($aSubkey[1] & @CRLF)
                    ;ConsoleWrite("Directory : " & $aSubkey[0] & @CRLF & "Filename : " & $aSubkey[1] & @CRLF)
                    If FileExists($aSubkey[0] & "MyPlugin\plugin.pl") Then
                        If StringInStr($aSubkey[0], "\GeneralPurposeAppz\Beta\") > 0 And $sBetaDir <> $aSubkey[0] Then $sBetaDir = $aSubkey[0]
                        If StringInStr($aSubkey[0], "\GeneralPurposeAppz\Release\") > 0 And $sReleaseDir <> $aSubkey[0] Then $sReleaseDir = $aSubkey[0]
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
WEnd

If FileExists($sBetaDir) Then
    ShellExecute($sBetaDir)
ElseIf FileExists($sReleaseDir) Then
    ShellExecute($sReleaseDir)
Else
    MsgBox(48, "Not found", "Plugin not found")
EndIf

 

Link to comment
Share on other sites

@Subz

The code you recently sent is,No problem in Windows 10 tested ok.
But in windows 7 it gives an error message "Plugin not found", interesting situation I don't know why :unsure:

Edit: The problem seems to be pattern RegExp

Edited by youtuber
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...