Sign in to follow this  
Followers 0
2tim3_16

Script won't run in specified directory

20 posts in this topic

We have a large number of scripts using the RunAsSet function. The uncompiled copies of these scripts are stored on a secure network drive, but we'd like to have the ability to encrypt the RunAsSet passwords anyway, just so that they don't appear as the actual password in the files. Granted, anybody with AutoIt (who had access to the drive, of course) could just unencrypt them. But that's really beside the point. The point is, the password used changes at least once a year. Rather than manually changing the password in every file, I've written a script to do the change automatically. However, I can only get it to run on the files in the current directory, even if I specify a different directory. Anyone know what's wrong with my script? (Sorry it's not documented.)

Here's the script:

#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
$mainwindow = GUICreate("Change Password", 375, 155)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$path = GUICtrlCreateInput("", 105, 13, 260)
$SelectPath = GUICtrlCreateButton("Directory path:", 10, 10, 85)
    GUICtrlSetOnEvent($SelectPath, "Path")
$OldLabel = GUICtrlCreateLabel("Old password:", 15, 45)
$OldPassword = GUICtrlCreateInput("", 155, 40, 100,"", $ES_PASSWORD)

$NewLabel = GUICtrlCreateLabel("New password:", 15, 70)
$NewPassword = GUICtrlCreateInput("", 155, 67, 100,"", $ES_PASSWORD)

$Encrypted = GUICtrlCreateCheckbox("Old password already encrypted?", 10, 95)

$NewEncrypted = GUICtrlCreateCheckbox("Save new password encrypted?", 195, 95)
    GUICtrlSetState($NewEncrypted, $GUI_CHECKED)

$okbutton = GUICtrlCreateButton("OK", 70, 120, 60)
    GUICtrlSetOnEvent($okbutton, "OKButton")
$cancelbutton = GUICtrlCreateButton("Cancel", 140, 120, 60)
    GUICtrlSetOnEvent($cancelbutton, "CLOSEClicked")

GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd
 
Func Path()
    GUICtrlSetData($path, FileSelectFolder("Please select the folder to search:",""))
EndFunc

Func OKButton()
    If GUICtrlRead($path) = "" Then
        MsgBox(0, "Path", "Please select a directory to search before proceeding.")
    ElseIf GUICtrlRead($OldPassword) = "" Then
        MsgBox(0, "Old Password", "Please enter the old password before proceeding.")
    ElseIf GUICtrlRead($Encrypted) = $GUI_CHECKED Then
        If GUICtrlRead($NewEncrypted) = $GUI_CHECKED Then
            Call("ProceedOldEncrypted")
        Else
            Call("ProceedOldEncryptNewUn")
        EndIf
    ElseIf GUICtrlRead($Encrypted) = $GUI_UNCHECKED Then
        If GUICtrlRead($NewEncrypted) = $GUI_CHECKED Then
            Call("ProceedOldUnencrypted")
        Else
            Call("ProceedOldUnencryptedNewUn")
        EndIf
    EndIf
EndFunc

Func ProceedOldEncrypted()
    $filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)
    
    While 1
        $filename = FileFindNextFile($file) 
        If @error Then ExitLoop
        
        If GUICtrlRead($NewPassword) = "" Then
            $retval1 = _ReplaceStringInFile($filename, '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($filename, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($filename)
                        FileDelete($filename)
                        FileWriteLine($filename, "#include <String.au3>")
                        FileWriteLine($filename, $text)
                    EndIf
            EndIf
        Else
            $retval1 = _ReplaceStringInFile($filename, '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($NewPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($filename, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($filename)
                        FileDelete($filename)
                        FileWriteLine($filename, "#include <String.au3>")
                        FileWriteLine($filename, $text)
                    EndIf
            EndIf
        EndIf
    WEnd
    
    FileClose($filename) 
    
    MsgBox(0, "Complete", "Operation complete.")
EndFunc
    
Func ProceedOldUnencrypted()
    $filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)
    
    While 1
        $filename = FileFindNextFile($file) 
        If @error Then ExitLoop
        
        If GUICtrlRead($NewPassword) = "" Then
            $retval1 = _ReplaceStringInFile($filename, '"' & GUICtrlRead($OldPassword) & '"', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($filename, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($filename)
                        FileDelete($filename)
                        FileWriteLine($filename, "#include <String.au3>")
                        FileWriteLine($filename, $text)
                    EndIf
            EndIf
        Else
            $retval1 = _ReplaceStringInFile($filename, '"' & GUICtrlRead($OldPassword) & '"', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($NewPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($filename, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($filename)
                        FileDelete($filename)
                        FileWriteLine($filename, "#include <String.au3>")
                        FileWriteLine($filename, $text)
                    EndIf
            EndIf
        EndIf
    WEnd
    
    FileClose($filename) 
    
    MsgBox(0, "Complete", "Operation complete.")
EndFunc

Func ProceedOldEncryptNewUn()
    $filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)
    
    While 1
        $filename = FileFindNextFile($file) 
        If @error Then ExitLoop
        
        If GUICtrlRead($NewPassword) = "" Then
            $retval1 = _ReplaceStringInFile($filename, '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)', '"' & GUICtrlRead($OldPassword) & '"')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($filename, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($filename)
                        FileDelete($filename)
                        FileWriteLine($filename, "#include <String.au3>")
                        FileWriteLine($filename, $text)
                    EndIf
            EndIf
        Else
            $retval1 = _ReplaceStringInFile($filename, '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)', '"' & GUICtrlRead($NewPassword) & '"')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($filename, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($filename)
                        FileDelete($filename)
                        FileWriteLine($filename, "#include <String.au3>")
                        FileWriteLine($filename, $text)
                    EndIf
            EndIf
        EndIf
    WEnd
    
    FileClose($filename) 
    
    MsgBox(0, "Complete", "Operation complete.")
EndFunc

Func ProceedOldUnencryptedNewUn()
    $filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)
    
    While 1
        $filename = FileFindNextFile($file) 
        If @error Then ExitLoop
        
        If GUICtrlRead($NewPassword) = "" Then
            $retval1 = _ReplaceStringInFile($filename, '"' & GUICtrlRead($OldPassword) & '"', '"' & GUICtrlRead($OldPassword) & '"')
        Else
            $retval1 = _ReplaceStringInFile($filename, '"' & GUICtrlRead($OldPassword) & '"', '"' & GUICtrlRead($NewPassword) & '"')
        EndIf
    WEnd
    
    FileClose($filename) 
    
    MsgBox(0, "Complete", "Operation complete.")
EndFunc

Func CLOSEClicked()
  Exit
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

We have a large number of scripts using the RunAsSet function. The uncompiled copies of these scripts are stored on a secure network drive, but we'd like to have the ability to encrypt the RunAsSet passwords anyway, just so that they don't appear as the actual password in the files. Granted, anybody with AutoIt (who had access to the drive, of course) could just unencrypt them. But that's really beside the point. The point is, the password used changes at least once a year. Rather than manually changing the password in every file, I've written a script to do the change automatically. However, I can only get it to run on the files in the current directory, even if I specify a different directory. Anyone know what's wrong with my script? (Sorry it's not documented.)

FileFindNextFile() returns only file names, NO path.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

FileFindNextFile() returns only file names, NO path.

Cheers

Kurt

Any suggestions on what to use instead?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Any suggestions on what to use instead?

nothing, just put $path in front of $filename !!

$fullpath = $path & "\" & $filename

FileDelete($filename)

FileDelete($fullpath)

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

nothing, just put $path in front of $filename !!

$fullpath = $path & "\" & $filename

FileDelete($filename)

FileDelete($fullpath)

But wouldn't I still run into the same problem, because FileFindNextFile would drop the path? And then run in the current directory?

One of my co-workers was wondering if I should use FileChangeDir($path). Would that change where FileFindNextFile($filename) searches?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

But wouldn't I still run into the same problem, because FileFindNextFile would drop the path? And then run in the current directory?

One of my co-workers was wondering if I should use FileChangeDir($path). Would that change where FileFindNextFile($filename) searches?

Wouldn't it be easier to just try it ?

To play it save yoiu could replace the FileDelete() for a MSGBOX or ConsoleWrite showing the file to be deleted ....

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

But wouldn't I still run into the same problem, because FileFindNextFile would drop the path? And then run in the current directory?

One of my co-workers was wondering if I should use FileChangeDir($path). Would that change where FileFindNextFile($filename) searches?

what do you mean by "runs in the current directory"??

As long as you use fully qualified file names (c:\temp\file.txt) for FileDelete,FileWriteLine, etc. it does not matter in which directory your script runs.


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Ok, maybe I'm not explaining my problem clearly. Say I have a couple of AutoIt scripts on my Desktop, and some more in C:\_Scripts. If I have the script on the Desktop, and select C:\_Scripts as the $path, the script changes the passwords in the files on my Desktop. If I have this script saved in the C:\_Scripts and select the Desktop for the $path, the script changes the passwords in all the files in C:\_Scripts.

Share this post


Link to post
Share on other sites

Ok, maybe I'm not explaining my problem clearly. Say I have a couple of AutoIt scripts on my Desktop, and some more in C:\_Scripts. If I have the script on the Desktop, and select C:\_Scripts as the $path, the script changes the passwords in the files on my Desktop. If I have this script saved in the C:\_Scripts and select the Desktop for the $path, the script changes the passwords in all the files in C:\_Scripts.

not if you do what I told you to do!


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

not if you do what I told you to do!

Ok, so maybe I'm not following. (Forgive me for being a little slow to catch on.) Should it look something like this then?

Func ProceedOldUnencrypted()
    $filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)
    
    While 1
        $filename = FileFindNextFile($file) 
        $fullpath = $path & "\" & $filename
        If @error Then ExitLoop
        
        If GUICtrlRead($NewPassword) = "" Then
            $retval1 = _ReplaceStringInFile($fullpath, '"' & GUICtrlRead($OldPassword) & '"', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($fullpath, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($fullpath)
                        FileDelete($fullpath)
                        FileWriteLine($fullpath, "#include <String.au3>")
                        FileWriteLine($fullpath, $text)
                    EndIf
            EndIf
        Else
            $retval1 = _ReplaceStringInFile($fullpath, '"' & GUICtrlRead($OldPassword) & '"', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($NewPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($fullpath, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($fullpath)
                        FileDelete($fullpath)
                        FileWriteLine($fullpath, "#include <String.au3>")
                        FileWriteLine($fullpath, $text)
                    EndIf
            EndIf
        EndIf
    WEnd
    
    FileClose($fullpath) 
    
    MsgBox(0, "Complete", "Operation complete.")
EndFuncoÝ÷ Ø-+)j»ZrÛ¢ºÞrÖ®¶­s`b33c¶fÆWFÒuT7G&Å&VBb33c·FfײgV÷C²b3#²¢æS2gV÷C° b33c¶fÆRÒfÆTfæDf'7DfÆRb33c¶fÆWF  vÆR b33c¶fÆVæÖRÒfÆTfæDæWDfÆRb33c¶fÆR b33c¶gVÆÇFÒb33c·FfײgV÷C²b3#²gV÷C²fײb33c¶fÆVæÖ

Share this post


Link to post
Share on other sites

Ok, so maybe I'm not following. (Forgive me for being a little slow to catch on.) Should it look something like this then?

Is this part actually correct?

$filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)
    
    While 1
        $filename = FileFindNextFile($file) 
        $fullpath = $path & "\" & $filename
looks good. However, MAKE A COPY OF YOUR FILES BEFORE YOU TEST IT, or do what JdeB told you. Use

MsgBox() to print the filename ($fullpath). Then you will see which files are about to be changed/deleted.


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

looks good. However, MAKE A COPY OF YOUR FILES BEFORE YOU TEST IT, or do what JdeB told you. Use

MsgBox() to print the filename ($fullpath). Then you will see which files are about to be changed/deleted.

Thanks so much for your help on this, guys! Now it's half working. It's running on the files in the directory specified, but it just goes into an endless loop.

Here's how it looks now. If I remove the references to $fullpath, it stops after searching all the files (in the wrong directory of course). Put the $fullpath back in, and it's an endless loop in the correct directory.

Func ProceedOldUnencrypted()
    $filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)

    While 1
        $filename = FileFindNextFile($file) 
        $fullpath = GUICtrlRead($path) & "\" & $filename 

        If @error Then ExitLoop
        
        If GUICtrlRead($NewPassword) = "" Then
            $retval1 = _ReplaceStringInFile($fullpath, '"' & GUICtrlRead($OldPassword) & '"', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($fullpath, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($fullpath)
                        FileDelete($fullpath)
                        FileWriteLine($fullpath, "#include <String.au3>")
                        FileWriteLine($fullpath, $text)
                    EndIf
            EndIf
        Else
            $retval1 = _ReplaceStringInFile($fullpath, '"' & GUICtrlRead($OldPassword) & '"', '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($NewPassword), "p", 1) & '", "p", 1)')
            If $retval1 <> -1 Then
                $retval2 = _ReplaceStringInFile($fullpath, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($fullpath)
                        FileDelete($fullpath)
                        FileWriteLine($fullpath, "#include <String.au3>")
                        FileWriteLine($fullpath, $text)
                    EndIf
            EndIf
        EndIf
    WEnd
    
    FileClose($filename) 
    
    MsgBox(0, "Complete", "Operation complete.")
EndFunc

Share this post


Link to post
Share on other sites

you need the error checking on the line directly after the FileFindNextFile

While 1
        $filename = FileFindNextFile($file) 
         If @error Then ExitLoop
        $fullpath = GUICtrlRead($path) & "\" & $filename

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Have you thought about doing this slightly differently? maybe along the lines of:

keep the password in a file on the server (use _StringEncrypt to encrypt the password)

Then in your scripts have a function that retrieves the password from the server and decrypts on the fly, it would still be insecure insomuch as you would have a password in your script to do the string un-encrypt but you could workaround that too(#1). This would obviously negate the need to constantly change your scripts and have your password kept in cleartext in a thousand places that could potentially be a security threat.

I'm actually planning on working on something like this myself, but it'll be a while as I just started with a new employer.

Pebbles

#1 - depending on what you have your scripts do, if they are scheduled scripts then you could compile the scripts with obfuscation and make them non decompile-able, this would add to the overall security, while simplifying your need to change the main password i ALL your scripts. If they are tools used by your techs then you could design it to use a username password type feature before doing the read and decrypt of the password.

Share this post


Link to post
Share on other sites

That is possibly an option, although may be difficult with our current setup. It would certainly save us a lot of time when our password changes. I'll have to look into that. Thanks for the suggestion!

Share this post


Link to post
Share on other sites

Ok, I've tried adding some more functions, and now I've got more questions. :) Trying to allow the changed scripts to be recompiled. But now none of my scripts are getting the "#include <String.au3>" inserted, and it isn't compiling any of them. Not getting any errors, either. Any suggestions?

Changes I made to the script after I originally got it working:

Replaced

If $retval1 <> -1 ThenoÝ÷ Û­«­¢+Ù%9½ÐÀÌØíÉÑÙ°Äô´ÄQ¡oÝ÷ Ø]yÖ®¶­sdbæ÷Bb33c·&WGfÃÒFVè6ýدz
Ö®¶­sdbuT7G&Å&VBb33c´6ö×ÆRÒb33c´uTô4T4´TBFVâ6ÆÂgV÷C´6ö×ÆRgV÷C²oÝ÷ Ù«­¢+ÙÕ¹Aɽ=±¹ÉåÁÑ9ÝU¸ ¤($ÀÌØí¥±ÁÑ ôU%
ÑɱI ÀÌØíÁÑ ¤µÀìÅÕ½ÐìÀäÈ쨹ÔÌÅÕ½Ðì(ÀÌØí¥±ô¥±¥¹¥ÉÍÑ¥± ÀÌØí¥±ÁÑ ¤((]¡¥±Ä(ÀÌØí¥±¹µô¥±¥¹9áÑ¥± ÀÌØí¥±¤($%%ÉɽÈQ¡¸á¥Ñ1½½À(ÀÌØíÕ±±ÁÑ ôU%
ÑɱI ÀÌØíÁÑ ¤µÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØí¥±¹µ(($%%U%
ÑɱI ÀÌØí9ÝAÍÍݽɤôÅÕ½ÐìÅÕ½ÐìQ¡¸($$$ÀÌØíÉÑÙ°Äô}IÁ±MÑÉ¥¹%¹¥± ÀÌØíÕ±±ÁÑ °Ìäí}MÑÉ¥¹¹ÉåÁÐ À°ÅÕ½ÐìÌäìµÀì}MÑÉ¥¹¹ÉåÁРıU%
ÑɱI ÀÌØí=±AÍÍݽɤ°ÅÕ½ÐíÀÅÕ½Ðì°Ä¤µÀìÌäìÅÕ½Ðì°ÅÕ½ÐíÀÅÕ½Ðì°Ä¤Ìäì°ÌäìÅÕ½ÐìÌäìµÀìU%
ÑɱI ÀÌØí=±AÍÍݽɤµÀìÌäìÅÕ½ÐìÌäì¤($$%%9½ÐÀÌØíÉÑÙ°Äô´ÄQ¡¸($$$%%9½ÐÀÌØíÉÑÙ°ÄôÀQ¡¸($$$$$ÀÌØíÉÑÙ°Èô}IÁ±MÑÉ¥¹%¹¥± ÀÌØíÕ±±ÁÑ °ÅÕ½Ð쥹±Õ±ÐíMÑÉ¥¹¹ÔÌÐìÅÕ½Ðì°ÅÕ½Ð쥹±Õ±ÐíMÑÉ¥¹¹ÔÌÐìÅÕ½Ðì¤($$$$$%%ÀÌØíÉÑÙ°ÈôÀQ¡¸($$$$$$$ÀÌØíÑáÐô¥±I ÀÌØíÕ±±ÁÑ ¤($$$$$$%¥±±Ñ ÀÌØíÕ±±ÁÑ ¤($$$$$$%¥±]É¥Ñ1¥¹ ÀÌØíÕ±±ÁÑ °ÅÕ½Ð쥹±Õ±ÐíMÑÉ¥¹¹ÔÌÐìÅÕ½Ðì¤($$$$$$%¥±]É¥Ñ1¥¹ ÀÌØíÕ±±ÁÑ °ÀÌØíÑáФ($$$$$%¹%($$$$%%U%
ÑɱI ÀÌØí
½µÁ¥±¤ôÀÌØíU%}
!
-Q¡¸
±° ÅÕ½Ðí
½µÁ¥±ÅÕ½Ðì¤($$$%¹%($$%¹%($%±Í($$$ÀÌØíÉÑÙ°Äô}IÁ±MÑÉ¥¹%¹¥± ÀÌØíÕ±±ÁÑ °Ìäí}MÑÉ¥¹¹ÉåÁÐ À°ÅÕ½ÐìÌäìµÀì}MÑÉ¥¹¹ÉåÁРıU%
ÑɱI ÀÌØí=±AÍÍݽɤ°ÅÕ½ÐíÀÅÕ½Ðì°Ä¤µÀìÌäìÅÕ½Ðì°ÅÕ½ÐíÀÅÕ½Ðì°Ä¤Ìäì°ÌäìÅÕ½ÐìÌäìµÀìU%
ÑɱI ÀÌØí9ÝAÍÍݽɤµÀìÌäìÅÕ½ÐìÌäì¤($$%%9½ÐÀÌØíÉÑÙ°Äô´ÄQ¡¸($$$%%9½ÐÀÌØíÉÑÙ°ÄôÀQ¡¸($$$$$ÀÌØíÉÑÙ°Èô}IÁ±MÑÉ¥¹%¹¥± ÀÌØíÕ±±ÁÑ °ÅÕ½Ð쥹±Õ±ÐíMÑÉ¥¹¹ÔÌÐìÅÕ½Ðì°ÅÕ½Ð쥹±Õ±ÐíMÑÉ¥¹¹ÔÌÐìÅÕ½Ðì¤($$$$$%%ÀÌØíÉÑÙ°ÈôÀQ¡¸($$$$$$$ÀÌØíÑáÐô¥±I ÀÌØíÕ±±ÁÑ ¤($$$$$$%¥±±Ñ ÀÌØíÕ±±ÁÑ ¤($$$$$$%¥±]É¥Ñ1¥¹ ÀÌØíÕ±±ÁÑ °ÅÕ½Ð쥹±Õ±ÐíMÑÉ¥¹¹ÔÌÐìÅÕ½Ðì¤($$$$$$%¥±]É¥Ñ1¥¹ ÀÌØíÕ±±ÁÑ °ÀÌØíÑáФ($$$$$%¹%($$$$%%U%
ÑɱI ÀÌØí
½µÁ¥±¤ôÀÌØíU%}
!
-Q¡¸
±° ÅÕ½Ðí
½µÁ¥±ÅÕ½Ðì¤($$$%¹%($$%¹%($%¹%(%]¹($(%¥±
±½Í ÀÌØí¥±¹µ¤($(%5Í    ½à À°ÅÕ½Ðí
½µÁ±ÑÅÕ½Ðì°ÅÕ½Ðí=ÁÉÑ¥½¸½µÁ±Ñ¸ÅÕ½Ðì¤)¹Õ¹

Share this post


Link to post
Share on other sites

Ok, I've tried adding some more functions, and now I've got more questions. :) Trying to allow the changed scripts to be recompiled. But now none of my scripts are getting the "#include <String.au3>" inserted, and it isn't compiling any of them. Not getting any errors, either. Any suggestions?

Changes I made to the script after I originally got it working:

O.K., but what's the problem now???


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

O.K., but what's the problem now???

I said, now none of my scripts are getting the "#include <String.au3>" inserted, and it isn't compiling any of them. It is still changing the passwords. I made the changes from <> to Not = because it was inserting "#include <String.au3>" in every script. Which form (<> or Not =) is correct, or are they equal?

And do I have the Call Compile() in the wrong place?

Share this post


Link to post
Share on other sites

I got it! I changed my script to the following, and now it works correctly:

Func ProceedOldEncryptNewUn()
    $filepath = GUICtrlRead($path) & "\*.au3"
    $file = FileFindFirstFile($filepath)

    While 1
        $filename = FileFindNextFile($file) 
        If @error Then ExitLoop
        $fullpath = GUICtrlRead($path) & "\" & $filename 

        If GUICtrlRead($NewPassword) = "" Then
            $retval1 = _ReplaceStringInFile($fullpath, '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)', '"' & GUICtrlRead($OldPassword) & '"')
            If $retval1 = -1 Then ExitLoop
            If Not $retval1 = 0 Then
                $retval2 = _ReplaceStringInFile($fullpath, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($fullpath)
                        FileDelete($fullpath)
                        FileWriteLine($fullpath, "#include <String.au3>")
                        FileWriteLine($fullpath, $text)
                    EndIf
                If GUICtrlRead($Compile) = $GUI_CHECKED Then Call("Compile")
            EndIf
        Else
            $retval1 = _ReplaceStringInFile($fullpath, '_StringEncrypt(0, "' & _StringEncrypt(1,GUICtrlRead($OldPassword), "p", 1) & '", "p", 1)', '"' & GUICtrlRead($NewPassword) & '"')
            If $retval1 = -1 Then ExitLoop
            If Not $retval1 = 0 Then
                $retval2 = _ReplaceStringInFile($fullpath, "#include <String.au3>", "#include <String.au3>")
                    If $retval2 = 0 Then
                        $text = FileRead($fullpath)
                        FileDelete($fullpath)
                        FileWriteLine($fullpath, "#include <String.au3>")
                        FileWriteLine($fullpath, $text)
                    EndIf
                If GUICtrlRead($Compile) = $GUI_CHECKED Then Call("Compile")
            EndIf
        EndIf
    WEnd
    
    FileClose($filename) 
    
    MsgBox(0, "Complete", "Operation complete.")
EndFunc

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