Jump to content

Pathnames of Macros


Recommended Posts

Moin,

maybe it's Offtopic, but I need for my Script the english names of the Paths from the Macros.

Like:

@ProgramFilesDir = C:\Program Files

@MyDocumentsDir = X:\My Documents

@AppDataDir = ???

etc.

Could anybody give me a List or a Link, where I can investigate it ?

In Google I don't find the right Search Pattern Ithink ...

Thx.

Greenhorn

Link to comment
Share on other sites

That I have in my Helpfile. But I need the correct names from an english Windows version.

For example:

On my Windows (German) means @ProgramFilesDir = 'C:\Programme' in an english Windows it's 'C:\Program Files', @MyDocumentsDir = 'E:\Eigene Dateien' in english 'E:\My Documents', @AppDataDir = 'C:\Dokumente und Einstellungen\Pokerface\Anwendungsdaten' in english 'C:\???', and so on ...

The reason is, that I want to replace this Pathnames in a String with the Macros, but it could may happen that the Pathnames are the english ones, so I want my Script to recognize this.

An example:

If StringRegExp($sString, '([a-zA-Z]:\\Program\w*\\)') Then
        StringRegExpReplace($sString, '([a-zA-Z]:\\Program\w*\\)', "@ProgramFilesDir & '\")    ; @ProgramFilesDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Eigene Dateien)?(My Documents)?\\)') Then
        StringRegExpReplace($sString, '[a-zA-Z]:\\(Eigene Dateien)?(My Documents)?\\)', "@MyDocumentsDir & '\")    ; @MyDocumentsDir

Sorry, if I made me misunderstood. :D

So, where can I retrieve the english Pathnames for AppData, CommonDocuments & Co. ?

Greenhorn

Edited by Greenhorn
Link to comment
Share on other sites

That I have in my Helpfile. But I need the correct names from an english Windows version.

For example:

On my Windows (German) means @ProgramFilesDir = 'C:\Programme' in an english Windows it's 'C:\Program Files', @MyDocumentsDir = 'E:\Eigene Dateien' in english 'E:\My Documents', @AppDataDir = 'C:\Dokumente und Einstellungen\Pokerface\Anwendungsdaten' in english 'C:\???', and so on ...

The reason is, that I want to replace this Pathnames in a String with the Macros, but it could may happen that the Pathnames are the english ones, so I want my Script to recognize this.

An example:

If StringRegExp($sString, '([a-zA-Z]:\\Program\w*\\)') Then
        StringRegExpReplace($sString, '([a-zA-Z]:\\Program\w*\\)', "@ProgramFilesDir & '\")    ; @ProgramFilesDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Eigene Dateien)?(My Documents)?\\)') Then
        StringRegExpReplace($sString, '[a-zA-Z]:\\(Eigene Dateien)?(My Documents)?\\)', "@MyDocumentsDir & '\")    ; @MyDocumentsDir

Sorry, if I made me misunderstood. :D

So, where can I retrieve the english Pathnames for AppData, CommonDocuments & Co. ?

Greenhorn

One way is to write a little script where you write all the macros you are interested in to an ini file, eg

IniWrite("macros.txt","@macr1",@macro1)

Then you post the script for someone in the UK, maybe me, to try and they send you the ini file.

There is probably an easier way, it's just a suggestion.

EDIT:

By the way, why can't you construct the string using the macros so that it doesn't matter that you don't know what they are? That's the advantage of the macros isn't it?

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

That I have in my Helpfile. But I need the correct names from an english Windows version.

For example:

On my Windows (German) means @ProgramFilesDir = 'C:\Programme' in an english Windows it's 'C:\Program Files', @MyDocumentsDir = 'E:\Eigene Dateien' in english 'E:\My Documents', @AppDataDir = 'C:\Dokumente und Einstellungen\Pokerface\Anwendungsdaten' in english 'C:\???', and so on ...

The reason is, that I want to replace this Pathnames in a String with the Macros, but it could may happen that the Pathnames are the english ones, so I want my Script to recognize this.

An example:

If StringRegExp($sString, '([a-zA-Z]:\\Program\w*\\)') Then
        StringRegExpReplace($sString, '([a-zA-Z]:\\Program\w*\\)', "@ProgramFilesDir & '\")    ; @ProgramFilesDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Eigene Dateien)?(My Documents)?\\)') Then
        StringRegExpReplace($sString, '[a-zA-Z]:\\(Eigene Dateien)?(My Documents)?\\)', "@MyDocumentsDir & '\")    ; @MyDocumentsDir

Sorry, if I made me misunderstood. :D

So, where can I retrieve the english Pathnames for AppData, CommonDocuments & Co. ?

Greenhorn

I do not understand why you are unable to use the @macros directly anywhere you need to use these paths as they will always return the correct paths for the PC the script is run on whatever the language version of Windows or where the user may have changed the locations too.

These are the paths returned by my English version of Windows

@AppDataCommonDir = "C:\Documents and Settings\All Users\Application Data"
@DesktopCommonDir = "C:\Documents and Settings\All Users\Desktop"
@DocumentsCommonDir = "C:\Documents and Settings\All Users\Documents"
@FavoritesCommonDir = "C:\Documents and Settings\All Users\Favorites"
@ProgramsCommonDir = "C:\Documents and Settings\All Users\Start Menu\Programs"
@StartMenuCommonDir = "C:\Documents and Settings\All Users\Start Menu"
@StartupCommonDir = "C:\Documents and Settings\All Users\Start Menu\Programs\Startup"
@AppDataDir = "C:\Documents and Settings\Bowmore\Application Data"
@DesktopDir = "C:\Documents and Settings\Bowmore\Desktop"
@MyDocumentsDir = "C:\Documents and Settings\Bowmore\My Documents"
@FavoritesDir = "C:\Documents and Settings\Bowmore\Favorites"
@ProgramsDir = "C:\Documents and Settings\Bowmore\Start Menu\Programs"
@StartMenuDir = "C:\Documents and Settings\Bowmore\Start Menu"
@StartupDir = "C:\Documents and Settings\Bowmore\Start Menu\Programs\Startup"
@UserProfileDir = "C:\Documents and Settings\Bowmore"
@HomeDrive = "C:"
@HomePath = "\Documents and Settings\Bowmore"
@HomeShare = ""
@ProgramFilesDir = "C:\Program Files"
@CommonFilesDir = "C:\Program Files\Common Files"
@WindowsDir = "C:\WINDOWS"
@SystemDir = "C:\WINDOWS\system32"
@TempDir = "C:\DOCUME~1\BOWMOR~1\LOCALS~1\Temp"
@ComSpec = "C:\WINDOWS\system32\cmd.exe"
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

This is my Function I want to use ...

Func _SetPathMacroToString($sString)

    ; @CommonFilesDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Program\w*)?.*\\(Gemeinsame Dateien)?(Common Files)?\\)') Then
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Program\w*)?.*\\(Gemeinsame Dateien)?(Common Files)?\\)', "@CommonFilesDir & '\")
    ; @ProgramFilesDir !
    If StringRegExp($sString, '([a-zA-Z]:\\Program\w*\\)') Then
        $sString = StringRegExpReplace($sString, '([a-zA-Z]:\\Program\w*\\)', "@ProgramFilesDir & '\")
    ; @MyDocumentsDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(.*\\)?(.*\\)?(Eigene Dateien)?(My Documents)?\\))') Then
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(.*\\)?(.*\\)?(Eigene Dateien)?(My Documents)?\\))', "@MyDocumentsDir & '\")
    ; @AppDataCommonDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Anwendungsdaten)?(Documents\w*\\All Users\\Application Data)?\\)') Then    
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Anwendungsdaten)?(Documents\w*\\All Users\\Application Data)?\\)', "@AppDataCommonDir & '\")
    ; @AppDataDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Anwendungsdaten)?(Documents\w*\\.*\\Application Data)?\\)') Then  
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\.*\\Anwendungsdaten)?(Documents\w*\\.*\\Application Data)?\\)', "@AppDataDir & '\")
    ; @ProgramsCommonDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Startmenü\\Programme)?(Documents\w*\\All Users\\Start Menu\\\Programs)?\\)') Then 
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Startmenü)?(Documents\w*\\All Users\\Start Menu)?\\)', "@ProgramsCommonDir & '\")
    ; @ProgramsDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü\\Programme)?(Documents\w*\\.*\\Start Menu\\\Programs)?\\)') Then   
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü)?(Documents\w*\\.*\\Start Menu)?\\)', "@ProgramsDir & '\")
    ; @StartMenuDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü)?(Documents\w*\\.*\\Start Menu)?\\)') Then 
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü)?(Documents\w*\\.*\\Start Menu)?\\)', "@StartMenuDir & '\")
    ; @DocumentsCommonDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Documents)?(Documents\w*\\All Users\\Documents)?\\)') Then 
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Documents)?(Documents\w*\\All Users\\Documents)?\\)', "@DocumentsCommonDir & '\")
    ; @DesktopCommonDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Desktop)?(Documents\w*\\All Users\\Desktop)?\\)') Then 
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Desktop)?(Documents\w*\\All Users\\Desktop)?\\)', "@DesktopCommonDir & '\")
    ; @DesktopDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Desktop)?(Documents\w*\\.*\\Desktop)?\\)') Then   
        $sString = StringRegExpReplace($sString, _
        '([a-zA-Z]:\\(Dokumente\w*\\.*\\Desktop)?(Documents\w*\\.*\\Desktop)?\\)', "@DesktopDir & '\")
    ; @UserProfileDir ???
;   ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\)?(Documents\w*\\.*\\)?\\)') Then ; @UserProfileDir ???
;       $sString = StringRegExpReplace($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\)?(Documents\w*\\.*\\)?\\)', "@UserProfileDir & '\")
    ; @WindowsDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\WINDOWS\\)') Then
        $sString = StringRegExpReplace($sString, '([a-zA-Z]:\\WINDOWS\\)', "@WindowsDir & '\")
    ; @SystemDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\WINDOWS\\system32\\)') Then
        $sString = StringRegExpReplace($sString, '([a-zA-Z]:\\WINDOWS\\system32\\)', "@SystemDir & '\")
    EndIf
    Return $sString

EndFunc

The first both entries are working, maybe the Desktop, too ...

Thanx for reply, martin !

At first I had also the idea to generate the default Strings by using the AutoIt Macros and then compare it with thwe String of the Textlines, but what's up if the User set custom paths for some Folders ?!

Maybe you have an idea ? :D

If you want, I could post the hole Script I'm working at, maybe then it is more clear to you what I wanna do ...

Greetz from Hamburg

Greenhorn

p.s.: Sorry, but SciTE is fooling me, during the last weeks. It sometimes doesn't save my Scripts or change it back ... Hmmm.

Edited by Greenhorn
Link to comment
Share on other sites

The whole Script ... (still in progress!)

#cs =================================================================================
    ;
    ;    AutoIt Version:     3.2.10.0
    ;    Author:             Greenhorn
    ;
    ;    Script Name:        reg2.au3
    ;    Script Function:    Converts *.reg files to *.au3 files.
    ;                        Supports REGEDIT4 and Windows Registry Editor Version 5.00.
    ;                        Readable Valuelength is limited to 32767 Chars!
    ;
    ;
#ce =================================================================================

$sPathRegFile = 'J:\Redo.reg'
$sPathAu3File = 'J:\example.au3'

$fhRegFile = FileOpen($sPathRegFile, 0)
If FileReadLine($fhRegFile, 1) = 'REGEDIT4'  Then
    $iVersionRegedit = 4
Else
    $iVersionRegedit = 5
EndIf
$fhAu3File = FileOpen($sPathAu3File, 2)
$fhRegFileTMP = FileOpen(StringReplace($sPathRegFile, '.reg', '.tmp'), 2)
;    Datei in Array einlesen == _FileReadToArray
$arText = StringSplit(StringStripCR(FileRead($fhRegFile, FileGetSize($sPathRegFile))), @LF)
;_ArrayDisplay($arText)
Dim $sConvText, $sClipText
For $i = 1 To $arText[0]
    If StringRegExp($arText[$i], '\A;') Then FileWriteLine($fhAu3File, $arText[$i])
    If StringRegExp($arText[$i], '((hex\(?0?\d?\)?:)[[:xdigit:]]{2}(,[[:xdigit:]]{2})*,\\)\z') Then
        $sClipText &= StringReplace($arText[$i], "\", '')
    ElseIf StringRegExp($arText[$i], '((,[[:xdigit:]]{2})*,\\)\z') Then
        $sClipText &= StringStripWS(StringReplace($arText[$i], "\", ''), 8)
    ElseIf StringRegExp($arText[$i], '(,[[:xdigit:]]{2})\z') Then
        $sClipText &= StringStripWS($arText[$i], 8) & @CRLF
        If StringLen($sClipText) > 32767 Then $sClipText = 'hex:Limit exceeded'
        $sConvText &= $sClipText
        $sClipText = ''
    Else
        $sConvText &= $arText[$i] & @CRLF
    EndIf
Next

FileWrite($fhRegFileTMP, StringStripWS($sConvText, 2))
FileClose($fhRegFile)
FileClose($fhRegFileTMP)

$arSectionNames = IniReadSectionNames(StringReplace($sPathRegFile, '.reg', '.tmp'))

For $i = 1 To $arSectionNames[0]
    If StringRegExp($arSectionNames[$i], '\A(HKEY)') Then
        $sHiveKey = "'" & $arSectionNames[$i]
        $iRegAdd = 1
    Else
        $sHiveKey = "'" & StringReplace($arSectionNames[$i], '-HKEY', 'HKEY')
    EndIf
    $sHive = StringRegExp($sHiveKey, '(HKEY\w*\\)', 1)
    If @extended Then
        Switch $sHive[0]
            Case 'HKEY_CLASSES_ROOT\'
                $sHiveKey = StringReplace($sHiveKey, $sHive[0], 'HKCR\')
            Case 'HKEY_CURRENT_USER\'
                $sHiveKey = StringReplace($sHiveKey, $sHive[0], 'HKCU\')
            Case 'HKEY_LOCAL_MACHINE\'
                $sHiveKey = StringReplace($sHiveKey, $sHive[0], 'HKLM\')
            Case 'HKEY_USERS\'
                $sHiveKey = StringReplace($sHiveKey, $sHive[0], 'HKU\')
                $sHiveKey = _HKUsersToHKCUser($sHiveKey)
            Case 'HKEY_CURRENT_CONFIG\'
                $sHiveKey = StringReplace($sHiveKey, $sHive[0], 'HKCC\')
        EndSwitch
    EndIf
    $sHiveKey &= "'"
    $arSection = IniReadSection(StringReplace($sPathRegFile, '.reg', '.tmp'), $arSectionNames[$i])
    If @error Then
        FileWriteLine($fhAu3File, 'RegWrite(' & $sHiveKey & ')')
        ContinueLoop
    EndIf
    For $ii = 1 To $arSection[0][0]
        If $arSection[$ii][0] = '@'  Then
            $sValueName = "''"     ; Default ValueName
        ElseIf StringInStr($arSection[$ii][0], '\\') Then
            $sValueName = StringReplace(StringReplace($arSection[$ii][1], '\\', '\'), '"', "'")
        Else
            $sValueName = StringReplace($arSection[$ii][0], '"', "'")     ; ValueName
        EndIf
        If Not $iRegAdd Then ContinueLoop    ; RegDelete.
        $sValue = "'"
        Select
            Case StringRegExp($arSection[$ii][1], '(hex\(0?1?4?5?6?8?9?a?\):)')     ; Not supported Registry Valuetypes!
                FileWriteLine($fhAu3File, '; Can not write ' & $sHiveKey & $sValueName & ': Valuetype is not supported by AutoIt!')
                ContinueLoop
            Case StringInStr($arSection[$ii][1], '\"')     ; REG_SZ
                $sValueType = "'REG_SZ'"
                $sValue &= StringTrimLeft(StringTrimRight(StringReplace(StringReplace($arSection[$ii][1], '\\', '\'), '\"', '"'), 1), 1)
                $sValue = StringRegExpReplace(_SetCustomMacroToString($sValue), '\A"', "'" & '"' & "' & ")
                ;$sValue = _SetPathMacroToString($sValue)
            Case StringInStr($arSection[$ii][1], '\\')     ; REG_SZ
                $sValueType = "'REG_SZ'"
                $sValue &= StringReplace(StringReplace($arSection[$ii][1], '\\', '\'), '"', '')
                $sValue = _SetCustomMacroToString($sValue)
                ;$sValue = _SetPathMacroToString($sValue)
            Case StringInStr($arSection[$ii][1], 'dword:')     ; REG_DWORD
                $sValueType = "'REG_DWORD'"
                $sValue &= StringReplace($arSection[$ii][1], 'dword:', '')
            Case StringRegExp($arSection[$ii][1], '(hex\(?0?3?\)?:)')     ; REG_BINARY
                If $arSection[$ii][1] = 'Limit exceeded'  Then FileWriteLine($fhAu3File, '; Can not write ' & $sHiveKey & $sValueName & ': Valuelimit exceeded!')
                $sValueType = "'REG_BINARY'"
                $sValue &= StringRegExpReplace(StringReplace($arSection[$ii][1], ',', ''), '(hex\(?0?3?\)?:)', '')
            Case StringRegExp($arSection[$ii][1], '(hex\(0?7\):)')     ; REG_MULTI_SZ
                $sValueType = "'REG_MULTI_SZ'"
                If $iVersionRegedit = 4 Then
                    $sValue &= _HexToCharString($arSection[$ii][1])
                    If @error Then FileWriteLine($fhAu3File, '; Can not write ' & $sHiveKey & $sValueName & ': Valuelimit exceeded!')
                Else
                    $sValue &= _HexToCharString($arSection[$ii][1], 1)
                    If @error Then FileWriteLine($fhAu3File, '; Can not write ' & $sHiveKey & $sValueName & ': Valuelimit exceeded!')
                EndIf
            Case StringRegExp($arSection[$ii][1], '(hex\(0?2\):)')     ; REG_EXPAND_SZ
                $sValueType = "'REG_EXPAND_SZ'"
                $sValue &= _HexToCharString($arSection[$ii][1])
                If @error Then FileWriteLine($fhAu3File, '; Can not write ' & $sHiveKey & ', ' & $sValueName & ': Valuelimit exceeded!')
            Case Else     ; REG_SZ
                $sValueType = "'REG_SZ'"
                $sValue &= StringReplace($arSection[$ii][1], '"', '')
                $sValue = _SetCustomMacroToString($sValue)
                ;$sValue = _SetPathMacroToString($sValue)
        EndSelect
        $sValue &= "'"
        If $iRegAdd Then
            FileWriteLine($fhAu3File, 'RegWrite(' & $sHiveKey & ', ' & $sValueName & ', ' & $sValueType & ', ' & $sValue & ')')
        Else
            FileWriteLine($fhAu3File, 'RegDelete(' & $sHiveKey & ', ' & $sValueName & ')')
        EndIf
    Next
Next

FileDelete(StringReplace($sPathRegFile, '.reg', '.tmp'))
ShellExecute($sPathAu3File, '', '', 'edit')
Exit

Func _HexToCharString($sHexValues, $iFlag = 0)

    If $sHexValues = 'hex:Limit exceeded'  Then Return SetError(1)
    Local $sHexANSI, $arHexANSI, $sChar
    If $iFlag Then    ; Windows Registry Editor Version 5.00 REG_MULTI_SZ !
        $sHexANSI = StringRegExpReplace(StringReplace(StringReplace(StringReplace($sHexValues, ',00,00,00,00,00', ''), ',00,00,00', ',0a'), ',00', ''), '(hex\(0?\d\):)', '')
    Else     ; REGEDIT4 REG_MULTI_SZ & REG_EXPAND_SZ / Windows Registry Editor Version 5.00 REG_EXPAND_SZ !
        $sHexANSI = StringRegExpReplace(StringReplace($sHexValues, ',00', ''), '(hex\(0?\d\):)', '')
    EndIf
    $arHexANSI = StringSplit($sHexANSI, ',')
    For $i = 1 To $arHexANSI[0]
        Switch $arHexANSI[$i]
            Case '0a'
                $sChar &= "' & @LF & '"
            Case '27'
                $sChar &= "' & " & '"' & Chr(39) & '"' & " & '"
            Case Else
                $sChar &= Chr(Dec($arHexANSI[$i]))
        EndSwitch
    Next
    Return $sChar

EndFunc   ;==>_HexToCharString

Func _SetPathMacroToString($sString)

    ; @CommonFilesDir
    If StringRegExp($sString, '([a-zA-Z]:\\(Program\w*)?.*\\(Gemeinsame Dateien)?(Common Files)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Program\w*)?.*\\(Gemeinsame Dateien)?(Common Files)?\\)', "@CommonFilesDir & '\\"), 1)
        ; @ProgramFilesDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\Program\w*\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, '([a-zA-Z]:\\Program\w*\\)', "@ProgramFilesDir & '\\"), 1)
        ; @MyDocumentsDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(.*\\)?(.*\\)?(Eigene Dateien)?(My Documents)?\\))') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(.*\\)?(.*\\)?(Eigene Dateien)?(My Documents)?\\))', "@MyDocumentsDir & '\\"), 1)
        ; @AppDataCommonDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Anwendungsdaten)?(Documents\w*\\All Users\\Application Data)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Anwendungsdaten)?(Documents\w*\\All Users\\Application Data)?\\)', "@AppDataCommonDir & '\\"), 1)
        ; @AppDataDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Anwendungsdaten)?(Documents\w*\\.*\\Application Data)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\.*\\Anwendungsdaten)?(Documents\w*\\.*\\Application Data)?\\)', "@AppDataDir & '\\"), 1)
        ; @ProgramsCommonDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Startmenü\\Programme)?(Documents\w*\\All Users\\Start Menu\\\Programs)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Startmenü)?(Documents\w*\\All Users\\Start Menu)?\\)', "@ProgramsCommonDir & '\\"), 1)
        ; @ProgramsDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü\\Programme)?(Documents\w*\\.*\\Start Menu\\\Programs)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü)?(Documents\w*\\.*\\Start Menu)?\\)', "@ProgramsDir & '\\"), 1)
        ; @StartMenuDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü)?(Documents\w*\\.*\\Start Menu)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\.*\\Startmenü)?(Documents\w*\\.*\\Start Menu)?\\)', "@StartMenuDir & '\\"), 1)
        ; @DocumentsCommonDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Documents)?(Documents\w*\\All Users\\Documents)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Documents)?(Documents\w*\\All Users\\Documents)?\\)', "@DocumentsCommonDir & '\\"), 1)
        ; @DesktopCommonDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Desktop)?(Documents\w*\\All Users\\Desktop)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\All Users\\Desktop)?(Documents\w*\\All Users\\Desktop)?\\)', "@DesktopCommonDir & '\\"), 1)
        ; @DesktopDir !
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\Desktop)?(Documents\w*\\.*\\Desktop)?\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, _
                '([a-zA-Z]:\\(Dokumente\w*\\.*\\Desktop)?(Documents\w*\\.*\\Desktop)?\\)', "@DesktopDir & '\\"), 1)
        ; @UserProfileDir ??? Does it work at this place ? Hmmm ...
;    ElseIf StringRegExp($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\)?(Documents\w*\\.*\\)?\\)') Then    ; @UserProfileDir ???
;        $sString = StringTrimLeft(StringRegExpReplace($sString, '([a-zA-Z]:\\(Dokumente\w*\\.*\\)?(Documents\w*\\.*\\)?\\)', "@UserProfileDir & '\\"), 1)
        ; @WindowsDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\WINDOWS\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, '([a-zA-Z]:\\WINDOWS\\)', "@WindowsDir & '\\"), 1)
        ; @SystemDir
    ElseIf StringRegExp($sString, '([a-zA-Z]:\\WINDOWS\\system32\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, '([a-zA-Z]:\\WINDOWS\\system32\\)', "@SystemDir & '\\"), 1)
    EndIf
    Return $sString

EndFunc   ;==>_SetPathMacroToString

Func _SetCustomMacroToString($sString, $sCustom = '@ScriptDir')

    ; @ProgramFilesDir to @ScriptDir
    If StringRegExp($sString, '([a-zA-Z]:\\Program\w*\\)') Then
        $sString = StringTrimLeft(StringRegExpReplace($sString, '([a-zA-Z]:\\Program\w*\\)', $sCustom & " & '\\"), 1)
    EndIf
    Return $sString

EndFunc   ;==>_SetCustomMacroToString

Func _HKUsersToHKCUser($sHiveKey)

    Local $sChangeKey = StringRegExpReplace($sHiveKey, 'HKU\\.*?\\', 'HKCU\\')
    Return $sChangeKey

EndFunc   ;==>_HKUsersToHKCUser

Greetz

Edited by Greenhorn
Link to comment
Share on other sites

Thank you very much Bowmore !

That's exactly what I was looking for !

I do not understand why you are unable to use the @macros directly anywhere you need to use these paths as they will always return the correct paths for the PC the script is run on whatever the language version of Windows or where the user may have changed the locations too.

I try to explain again:

I've got some *.reg Files and the values sometimes contain paths like "C:\Documents and Settings\All Users\Application Data" or rather "C:\Dokumente und Einstellungen\Pokerface\Anwendungsdaten".

Now I want to make sure that these Paths where changed to AutoIt-Macros, cause my Script will generate an AutoIt Script, containing the RegWrite() and RegDelete() !

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib\{F8937E53-D444-4E71-9275-35B64210CC3B}\1.0\0\win32]
@="C:\\Programme\\AutoIt3\\AutoItX\\AutoItX3.dll"

RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib\{F8937E53-D444-4E71-9275-35B64210CC3B}\1.0\0\win32', '', 'REG_SZ', @ProgramFilesDir & '\AutoIt3\AutoItX\AutoItX3.dll')
Edited by Greenhorn
Link to comment
Share on other sites

Thank you very much Bowmore !

That's exactly what I was looking for !

I try to explain again:

I've got some *.reg Files and the values sometimes contain paths like "C:\Documents and Settings\All Users\Application Data" or rather "C:\Dokumente und Einstellungen\Pokerface\Anwendungsdaten".

Now I want to make sure that these Paths where changed to AutoIt-Macros, cause my Script will generate an AutoIt Script, containing the RegWrite() and RegDelete() !

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib\{F8937E53-D444-4E71-9275-35B64210CC3B}\1.0\0\win32]
@="C:\\Programme\\AutoIt3\\AutoItX\\AutoItX3.dll"

RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib\{F8937E53-D444-4E71-9275-35B64210CC3B}\1.0\0\win32', '', 'REG_SZ', @ProgramFilesDir & '\AutoIt3\AutoItX\AutoItX3.dll')
Thanks I now understand what you are trying to do.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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...