Jump to content

Registering with Windows Default program


Recommended Posts

But if it has been enterd by the parameter you need to set that data into the control so Add the line I gave you right after you create the control. If the user clicks the button and browses to a file then you reset it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Developers

But I do have that line there already. Or am I misunderstanding?

The button opens a file open dialogue so the user can choose the file, if it hasn't been added by the Command Line parameter.

Thanks again.

Lee

Ok then just update this line in your first snippet:

$InFileInput = GUICtrlCreateInput($file, 32, 40, 161, 21)

Your second snippet is wrong as that mixed the Control handle and the control value

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

hi Meerecat,

Here's that example I promised 15 minutes ago :huh2:

#RequireAdmin
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

If Not @Compiled Then
    MsgBox(64, @ScriptName, "This script needs to be compiled to run properly. Exiting..")
    Exit
EndIf

Global $sProgramFullPath = @ScriptFullPath
Global $sMyFileType[2] = [".crypt", "Crypted File"]

$Form1 = GUICreate("Demo 1", 361, 98)
$Checkbox1 = GUICtrlCreateCheckbox("Open " & $sMyFileType[0] & " files with this program", 12, 12, 229, 17)
$Input1 = GUICtrlCreateInput("", 12, 36, 337, 21)
$Button1 = GUICtrlCreateButton("Browse", 288, 60, 61, 25)

; If reg value exists, check the checkbox
RegRead("HKCR\" & $sMyFileType[1] & "\shell\open\command\", "")
If (@error = 0) Then
    GUICtrlSetState($Checkbox1, $GUI_CHECKED)
EndIf

; Get command line and set value of $Input1
If ($CmdLine[0] > 0) Then
    GUICtrlSetData($Input1, $CmdLine[1])
EndIf

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            If (GUICtrlRead($Checkbox1) = 1) Then
                _OpenWithSet()
            Else
                _OpenWithSet(0)
            EndIf
    EndSwitch
WEnd

Func _OpenWithSet($iFlag = 1)
    If $iFlag Then
        RegWrite("HKCR\" & $sMyFileType[0] & "\", "", "REG_SZ", $sMyFileType[1])
        RegWrite("HKCR\" & $sMyFileType[1] & "\shell\open\command\", "", "REG_SZ", """" & $sProgramFullPath & """ ""%1""")
    Else
        RegDelete("HKCR\" & $sMyFileType[0])
        RegDelete("HKCR\" & $sMyFileType[1])
    EndIf
EndFunc   ;==>_OpenWithSet

Hope this helps ;)

-smartee

Link to comment
Share on other sites

I see. So I was saying either use the file passed through from the command line, or use default. But I was overwriting this with my input code further down because this variable was the same. That makes sense.

Thank you all very much :huh2:

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

hi Meerecat,

Here's that example I promised 15 minutes ago :huh2:

#RequireAdmin
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

If Not @Compiled Then
    MsgBox(64, @ScriptName, "This script needs to be compiled to run properly. Exiting..")
    Exit
EndIf

Global $sProgramFullPath = @ScriptFullPath
Global $sMyFileType[2] = [".crypt", "Crypted File"]

$Form1 = GUICreate("Demo 1", 361, 98)
$Checkbox1 = GUICtrlCreateCheckbox("Open " & $sMyFileType[0] & " files with this program", 12, 12, 229, 17)
$Input1 = GUICtrlCreateInput("", 12, 36, 337, 21)
$Button1 = GUICtrlCreateButton("Browse", 288, 60, 61, 25)

; If reg value exists, check the checkbox
RegRead("HKCR\" & $sMyFileType[1] & "\shell\open\command\", "")
If (@error = 0) Then
    GUICtrlSetState($Checkbox1, $GUI_CHECKED)
EndIf

; Get command line and set value of $Input1
If ($CmdLine[0] > 0) Then
    GUICtrlSetData($Input1, $CmdLine[1])
EndIf

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            If (GUICtrlRead($Checkbox1) = 1) Then
                _OpenWithSet()
            Else
                _OpenWithSet(0)
            EndIf
    EndSwitch
WEnd

Func _OpenWithSet($iFlag = 1)
    If $iFlag Then
        RegWrite("HKCR\" & $sMyFileType[0] & "\", "", "REG_SZ", $sMyFileType[1])
        RegWrite("HKCR\" & $sMyFileType[1] & "\shell\open\command\", "", "REG_SZ", """" & $sProgramFullPath & """ ""%1""")
    Else
        RegDelete("HKCR\" & $sMyFileType[0])
        RegDelete("HKCR\" & $sMyFileType[1])
    EndIf
EndFunc   ;==>_OpenWithSet

Hope this helps ;)

-smartee

Hello Smartee

Many thanks for this.

So this program would write the registry keys to associate the .crypt extension with my program?

In a similar way to:

RegWrite('HKCR\.crypt\', '', 'REG_SZ', 'Crypt')
RegWrite('HKCR\Crypt\shell\open\command\', '', 'REG_SZ', 'C:\Program Files (x86)\Meerecat File Guard\Meerecat File Guard.exe')

But with a GUI. Is that right?

It also answers my next question which was how does my program receive the correct command line parameters without the user actually having to run from a command line.

Now to intergrate these into my main program.

I just want to thank you all again for your help. Not only are you helping me solve my problems for this specific program, but I am learning things I can adapt for future programs as well. So thanks again.

Lee

Edited by Meerecat

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

When you are using command line parameters it will work in a drag and drop situation as well so all you have to do is drag a file either onto the app itself or onto a shortcut to that app. The reistry should handle the situation where the user just double clicks a file.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

When you are using command line parameters it will work in a drag and drop situation as well so all you have to do is drag a file either onto the app itself or onto a shortcut to that app. The reistry should handle the situation where the user just double clicks a file.

Just tried that, it's pretty cool :huh2:

Thank you

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

Sorry, I'm back again :huh2:

Running into a bit of an issue with this while incorporating it in my program.

After registering .jimmy as an extension in the registry, this works:

#RequireAdmin
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Demo 1", 361, 98)
$Input1 = GUICtrlCreateInput("", 12, 36, 337, 21)
$Input2 = GUICtrlCreateInput("", 12, 66, 337, 21)
$Button1 = GUICtrlCreateButton("Browse", 288, 60, 61, 25)

If ($CmdLine[0] > 0) Then
    GUICtrlSetData($Input1, $CmdLine[1])
    GUICtrlSetData($Input2, $CmdLine[1])
EndIf
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
        $file = FileOpenDialog("Input File", "", "All files (*.*;)")
        If $file <> "" Then
        GUICtrlSetData($Input1, $file)
        GUICtrlSetData($Input2, $file)
        EndIf

    EndSwitch
WEnd

Running a jimmy file opens the above script and automatically fills out the input boxes.

In my script though, this gui is called from another one as a function. In this instance, running a jimmy file opens the first gui, when the input fields are on the 2nd gui so are not filled out.

Here is an example:

#RequireAdmin
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_main()

Func _main()
    GUIDelete()
    $Form1 = GUICreate("Meerecat File Guard", 528, 242)
    GUISetBkColor(0xFFFFFF)
    ;$Pic1 = GUICtrlCreatePic($IMG_DIR & '\meerecat.jpg', 8, 45, 113, 150)
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 191, 8, 145, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Meerecat IT Services  ©2011", 376, 224, 145, 17)
    GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
    ;$Pic2 = GUICtrlCreatePic($IMG_DIR & 'meerecat.jpg', 408, 45, 113, 150)
    $encrypt = GUICtrlCreateButton("Encrypt File", 163, 54, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $decrypt = GUICtrlCreateButton("Decrypt File", 163, 95, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $help = GUICtrlCreateButton("Help", 163, 136, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $exit = GUICtrlCreateButton("Exit", 163, 176, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $encrypt
                Exit
            Case $decrypt
                _decrypt()
            Case $help
                ShellExecute("http://www.meerecat-itservices.co.uk/contact-us")
            Case $exit
                Exit

        EndSwitch
    WEnd
EndFunc   ;==>_main

Func _decrypt()
$Form1 = GUICreate("Demo 1", 361, 98)
$Input1 = GUICtrlCreateInput("", 12, 36, 337, 21)
$Input2 = GUICtrlCreateInput("", 12, 66, 337, 21)
$Button1 = GUICtrlCreateButton("Browse", 288, 60, 61, 25)
If ($CmdLine[0] > 0) Then
    GUICtrlSetData($Input1, $CmdLine[1])
    GUICtrlSetData($Input2, $CmdLine[1])
EndIf
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    Case $Button1
                $file = FileOpenDialog("Input File", "", "All files (*.*;)")
                If $file <> "" Then
                    GUICtrlSetData($Input1, $file)
                    GUICtrlSetData($Input2, $file)
                EndIf

    EndSwitch
WEnd
EndFunc

I think I understand why it isn't working. The script runs from top to bottom, so it launches the _main function first. I just don't know how to correct it.

Many thanks

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

Your example filled out the inputs fine when I ran it:

Here's what I did:

  • Compiled your example
  • Dragged a file onto the compiled executable
  • Clicked Decrypt
And there the file-path stared at me as Input text.

Did you follow this same procedure?

Link to comment
Share on other sites

Ahhhhhhh I see. Because it started on the initial gui I didn't think it had worked. Any way to have it start straight on the decrypt gui if a file has been added via the CommandLine parameter?

Also I can't get it to work at all in my main program:

Func _decrypt()
    GUIDelete()
    $hWnd = GUICreate("Meerecat File Guard", 528, 242)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreatePic("meerecat.jpg", 8, 45, 113, 150)
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 191, 8, 145, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Meerecat IT Services  ©2011", 376, 224, 145, 17)
    GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
    $back = GUICtrlCreateButton("Back", 411, 112, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $InFileLabel = GUICtrlCreateLabel("Input File", 150, 48, 47, 17)
    $InFileInput = GUICtrlCreateInput("", 150, 64, 180, 21)
    $OutFileLabel = GUICtrlCreateLabel("Output File", 150, 96, 55, 17)
    $OutFileInput = GUICtrlCreateInput("", 150, 112, 180, 21)
    $InFileButton = GUICtrlCreateButton(". . .", 336, 64, 30, 25)
    $OutFileButton = GUICtrlCreateButton(". . .", 336, 112, 30, 25)
    $PasswordLabel = GUICtrlCreateLabel("Encryption Password", 150, 144, 103, 17)
    $PasswordInput = GUICtrlCreateInput("", 150, 160, 180, 21)
    $EncryptButton = GUICtrlCreateButton("Decrypt", 411, 64, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

    If ($CmdLine[0] > 0) Then ;Used to prefill input areas when running a .crypt file
        GUICtrlSetData($InFileInput, $CmdLine[1])
        GUICtrlSetData($OutFileInput, $CmdLine[1])
    EndIf

    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $back
                _main()
            Case $InFileButton
                $file = FileOpenDialog("Input File", "", "All files (*.*;)")
                If $file <> "" Then GUICtrlSetData($InFileInput, $file)
                GUICtrlSetData($OutFileInput, StringTrimRight($file, $TrimLength))
            Case $OutFileButton
                $file = FileSaveDialog("Output file", "", "Any file (*.*;)")
                If $file <> "" Then GUICtrlSetData($OutFileInput, $file)

            Case $EncryptButton
                $infile = GUICtrlRead($InFileInput)
                If Not FileExists($infile) Then
                    MsgBox(16, "Error", "Input file doesn't exists!")
                    ContinueLoop
                EndIf


                $outfile = GUICtrlRead($OutFileInput)
                If $outfile = "" Then
                    MsgBox(16, "Error", "Please input a output file")
                    ContinueLoop
                EndIf


                $password = GUICtrlRead($PasswordInput)
                If $password = "" Then
                    MsgBox(16, "Error", "Please input a password")
                    ContinueLoop
                EndIf

                AdlibRegister("Update", 333)
                $success = _Crypt_DecryptFile($infile, $outfile, $password, $CALG_RC4)
                If $success Then
                    MsgBox(0, "Success", "Operation succeeded")
                Else
                    Switch @error
                        Case 1
                            MsgBox(16, "Fail", "Failed to create key")
                        Case 2
                            MsgBox(16, "Fail", "Couldn't open source file")
                        Case 3
                            MsgBox(16, "Fail", "Couldn't open destination file")
                        Case 4 Or 5
                            MsgBox(16, "Fail", "Encryption error")
                    EndSwitch
                EndIf

                AdlibUnRegister("Update")
                WinSetTitle($hWnd, "", "File Decrypter")
        EndSwitch
    WEnd
EndFunc   ;==>_decrypt

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

..Any way to have it start straight on the decrypt gui if a file has been added via the CommandLine parameter?..

Yup, just run your Decrypt function if $CmdLine[0]>0

Also, wrt to your main program, your function worked fine once again once i commented out everything that didn't have to do with the Inputs.

Link to comment
Share on other sites

Yup, just run your Decrypt function if $CmdLine[0]>0

Also, wrt to your main program, your function worked fine once again once i commented out everything that didn't have to do with the Inputs.

In that case does that mean there's something else in my main program causing it to break?

If I drag a .crypt file onto the exe then press decrypt the path is filled out. If I double click a .crypt file it opens my program but does not fill out the input's though.

Here is my full code, and I appreciate your help. Many thanks :huh2:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=meerecat head.ico
#AutoIt3Wrapper_Outfile=Meerecat File Guard.exe
#AutoIt3Wrapper_Res_Description=Protect your files from prying eyes before sending them with Meerecat File Guard
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_LegalCopyright=Meerecat IT Services 2011
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Obfuscator=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

;Special thanks to Smartee, Mat and MHz on the AutoIt forum
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>

Global $Increase = 0
Global $Extension = '.crypt'
Global $TrimLength = StringLen($Extension)
Global $hWnd
Global $IMG_DIR = @AppDataDir & '\Meerecat\FileGuard'

RegWrite('HKCR\.crypt\', '', 'REG_SZ', 'Crypt')
RegWrite('HKCR\Crypt\shell\open\command\', '', 'REG_SZ', @ProgramFilesDir & '\Meerecat File Guard\Meerecat File Guard.exe')

$prog = @ProgramFilesDir & '\Meerecat File Guard\Meerecat File Guard.exe'
$text = 'Encrypt with Meerecat File Guard'

RegWrite("HKEY_CLASSES_ROOT\*\shell")
RegWrite("HKEY_CLASSES_ROOT\*\shell\" & $text)
RegWrite("HKEY_CLASSES_ROOT\*\shell\" & $text & "\command")
RegWrite("HKEY_CLASSES_ROOT\*\shell\" & $text & "\command", "", "REG_SZ", $prog & " %1")


If Not FileExists($IMG_DIR) Then DirCreate($IMG_DIR)
If FileExists($IMG_DIR & '\meerecat.jpg') = 0 Then FileInstall('meerecat.jpg', $IMG_DIR & '\meerecat.jpg')

_main()

Func _main()
    GUIDelete()
    $Form1 = GUICreate("Meerecat File Guard", 528, 242)
    GUISetBkColor(0xFFFFFF)
    $Pic1 = GUICtrlCreatePic($IMG_DIR & '\meerecat.jpg', 8, 45, 113, 150)
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 191, 8, 145, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Meerecat IT Services  ©2011", 376, 224, 145, 17)
    GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
    $Pic2 = GUICtrlCreatePic($IMG_DIR & 'meerecat.jpg', 408, 45, 113, 150)
    $encrypt = GUICtrlCreateButton("Encrypt File", 163, 54, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $decrypt = GUICtrlCreateButton("Decrypt File", 163, 95, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $help = GUICtrlCreateButton("Help", 163, 136, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $exit = GUICtrlCreateButton("Exit", 163, 176, 200, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $encrypt
                _encrypt()
            Case $decrypt
                _decrypt()
            Case $help
                ShellExecute("http://www.meerecat-itservices.co.uk/contact-us")
            Case $exit
                Exit

        EndSwitch
    WEnd
EndFunc   ;==>_main

Func _encrypt()
    GUIDelete()
    $hWnd = GUICreate("Meerecat File Guard", 528, 242)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreatePic("meerecat.jpg", 8, 45, 113, 150)
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 191, 8, 145, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Meerecat IT Services  ©2011", 376, 224, 145, 17)
    GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
    $back = GUICtrlCreateButton("Back", 411, 112, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $InFileLabel = GUICtrlCreateLabel("Input File", 150, 48, 47, 17)
    $InFileInput = GUICtrlCreateInput("", 150, 64, 180, 21)
    $OutFileLabel = GUICtrlCreateLabel("Output File", 150, 96, 55, 17)
    $OutFileInput = GUICtrlCreateInput("", 150, 112, 180, 21)
    $InFileButton = GUICtrlCreateButton(". . .", 336, 64, 30, 25)
    $OutFileButton = GUICtrlCreateButton(". . .", 336, 112, 30, 25)
    $PasswordLabel = GUICtrlCreateLabel("Encryption Password", 150, 144, 103, 17)
    $PasswordInput = GUICtrlCreateInput("", 150, 160, 180, 21)
    $EncryptButton = GUICtrlCreateButton("Encrypt", 411, 64, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)



    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $back
                _main()
            Case $InFileButton
                $file = FileOpenDialog("Input File", "", "All files (*.*;)")
                If $file <> "" Then
                    GUICtrlSetData($InFileInput, $file)
                    GUICtrlSetData($OutFileInput, $file & $Extension)
                EndIf
            Case $OutFileButton
                $file = FileSaveDialog("Output file", "", "Any file (*.*;)")
                If $file <> "" Then GUICtrlSetData($OutFileInput, $file)

            Case $EncryptButton
                $infile = GUICtrlRead($InFileInput)
                If Not FileExists($infile) Then
                    MsgBox(16, "Error", "Input file doesn't exists!")
                    ContinueLoop
                EndIf


                $outfile = GUICtrlRead($OutFileInput)
                If $outfile = "" Then
                    MsgBox(16, "Error", "Please input a output file")
                    ContinueLoop
                EndIf


                $password = GUICtrlRead($PasswordInput)
                If $password = "" Then
                    MsgBox(16, "Error", "Please input a password")
                    ContinueLoop
                EndIf

                AdlibRegister("Update", 333)
                $success = _Crypt_EncryptFile($infile, $outfile, $password, $CALG_RC4)
                If $success Then
                    MsgBox(0, "Success", "Operation succeeded")
                Else
                    Switch @error
                        Case 1
                            MsgBox(16, "Fail", "Failed to create key")
                        Case 2
                            MsgBox(16, "Fail", "Couldn't open source file")
                        Case 3
                            MsgBox(16, "Fail", "Couldn't open destination file")
                        Case 4 Or 5
                            MsgBox(16, "Fail", "Encryption error")
                    EndSwitch
                EndIf

                AdlibUnRegister("Update")
                WinSetTitle($hWnd, "", "File Encrypter")
        EndSwitch
    WEnd
EndFunc   ;==>_encrypt
Func _decrypt()
    GUIDelete()
    $hWnd = GUICreate("Meerecat File Guard", 528, 242)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreatePic("meerecat.jpg", 8, 45, 113, 150)
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 191, 8, 145, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Meerecat IT Services  ©2011", 376, 224, 145, 17)
    GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
    $back = GUICtrlCreateButton("Back", 411, 112, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $InFileLabel = GUICtrlCreateLabel("Input File", 150, 48, 47, 17)
    $InFileInput = GUICtrlCreateInput("", 150, 64, 180, 21)
    $OutFileLabel = GUICtrlCreateLabel("Output File", 150, 96, 55, 17)
    $OutFileInput = GUICtrlCreateInput("", 150, 112, 180, 21)
    $InFileButton = GUICtrlCreateButton(". . .", 336, 64, 30, 25)
    $OutFileButton = GUICtrlCreateButton(". . .", 336, 112, 30, 25)
    $PasswordLabel = GUICtrlCreateLabel("Encryption Password", 150, 144, 103, 17)
    $PasswordInput = GUICtrlCreateInput("", 150, 160, 180, 21)
    $EncryptButton = GUICtrlCreateButton("Decrypt", 411, 64, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

    If ($CmdLine[0] > 0) Then ;Used to prefill input areas when running a .crypt file
        GUICtrlSetData($InFileInput, $CmdLine[1])
        GUICtrlSetData($OutFileInput, $CmdLine[1])
    EndIf

    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $back
                _main()
            Case $InFileButton
                $file = FileOpenDialog("Input File", "", "All files (*.*;)")
                If $file <> "" Then GUICtrlSetData($InFileInput, $file)
                GUICtrlSetData($OutFileInput, StringTrimRight($file, $TrimLength))
            Case $OutFileButton
                $file = FileSaveDialog("Output file", "", "Any file (*.*;)")
                If $file <> "" Then GUICtrlSetData($OutFileInput, $file)

            Case $EncryptButton
                $infile = GUICtrlRead($InFileInput)
                If Not FileExists($infile) Then
                    MsgBox(16, "Error", "Input file doesn't exists!")
                    ContinueLoop
                EndIf


                $outfile = GUICtrlRead($OutFileInput)
                If $outfile = "" Then
                    MsgBox(16, "Error", "Please input a output file")
                    ContinueLoop
                EndIf


                $password = GUICtrlRead($PasswordInput)
                If $password = "" Then
                    MsgBox(16, "Error", "Please input a password")
                    ContinueLoop
                EndIf

                AdlibRegister("Update", 333)
                $success = _Crypt_DecryptFile($infile, $outfile, $password, $CALG_RC4)
                If $success Then
                    MsgBox(0, "Success", "Operation succeeded")
                Else
                    Switch @error
                        Case 1
                            MsgBox(16, "Fail", "Failed to create key")
                        Case 2
                            MsgBox(16, "Fail", "Couldn't open source file")
                        Case 3
                            MsgBox(16, "Fail", "Couldn't open destination file")
                        Case 4 Or 5
                            MsgBox(16, "Fail", "Encryption error")
                    EndSwitch
                EndIf

                AdlibUnRegister("Update")
                WinSetTitle($hWnd, "", "File Decrypter")
        EndSwitch
    WEnd
EndFunc   ;==>_decrypt

Func Update()
    Switch Mod($Increase, 4)
        Case 0
            WinSetTitle($hWnd, "", "Processing... |")
        Case 1
            WinSetTitle($hWnd, "", "Processing... /")
        Case 2
            WinSetTitle($hWnd, "", "Processing... —")
        Case 3
            WinSetTitle($hWnd, "", "Processing... \")
    EndSwitch

    $Increase += 1
EndFunc   ;==>Update

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

Oh :huh2: its your regwrite it needs to specify that your program accepts a parameter.

Instead of:

RegWrite('HKCR\Crypt\shell\open\command\', '', 'REG_SZ', @ProgramFilesDir & '\Meerecat File Guard\Meerecat File Guard.exe')

Use:

RegWrite('HKCR\Crypt\shell\open\command\', '', 'REG_SZ', @ProgramFilesDir & '\Meerecat File Guard\Meerecat File Guard.exe "%1"')

;)

Anything else? :alien:

EDIT: Typo

Edited by smartee
Link to comment
Share on other sites

Oh :huh2: its your regwrite it needs to specify that your program accepts a parameter.

Instead of:

RegWrite('HKCR\Crypt\shell\open\command\', '', 'REG_SZ', @ProgramFilesDir & '\Meerecat File Guard\Meerecat File Guard.exe')

Use:

RegWrite('HKCR\Crypt\shell\open\command\', '', 'REG_SZ', @ProgramFilesDir & '\Meerecat File Guard\Meerecat File Guard.exe "%1"')

;)

Anything else? :alien:

EDIT: Typo

I LOVEEEEEE SMARTEE :ph34r:

Seriously, thank you so much. Off now to make it do the same for importing files ready for encryption.

I'll try not to come back for a while ;-)

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

Something to think about.

1) .crypt is used in other applications, so you might need to check registry for its existence first, and maybe add it.

Thanks, I'll think of a different extension :huh2:

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

T'was a pleasure :huh2:

Feel free to post back whenever you run into difficulty :ph34r:

Good luck and happy coding ;)

-smartee

You know those difficulties you mentioned...(hides behind couch while typing) :alien:

Func _decrypt()
    ;GUIDelete()
    $hWnd = GUICreate("Meerecat File Guard", 528, 242)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreatePic("meerecat.jpg", 8, 45, 113, 150)
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 191, 8, 145, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Meerecat IT Services  ©2011", 376, 224, 145, 17)
    GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
    $back = GUICtrlCreateButton("Back", 411, 112, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $InFileLabel = GUICtrlCreateLabel("Input File", 150, 48, 47, 17)
    $InFileInput = GUICtrlCreateInput("", 150, 64, 180, 21)
    $OutFileLabel = GUICtrlCreateLabel("Output File", 150, 96, 55, 17)
    $OutFileInput = GUICtrlCreateInput("", 150, 112, 180, 21)
    $InFileButton = GUICtrlCreateButton(". . .", 336, 64, 30, 25)
    $OutFileButton = GUICtrlCreateButton(". . .", 336, 112, 30, 25)
    $PasswordLabel = GUICtrlCreateLabel("Encryption Password", 150, 144, 103, 17)
    $PasswordInput = GUICtrlCreateInput("", 150, 160, 180, 21)
    $EncryptButton = GUICtrlCreateButton("Decrypt", 411, 64, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

    If ($CmdLine[0] > 0) Then ;Used to prefill input areas when running a .crypt file
        GUICtrlSetData($InFileInput, $CmdLine[1])
        GUICtrlSetData($OutFileInput, $CmdLine[1], StringTrimRight($CmdLine, $TrimLength))
    EndIf

    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $back
                _main()
            Case $InFileButton
                $file = FileOpenDialog("Input File", "", "All files (*.*;)")
                If $file <> "" Then GUICtrlSetData($InFileInput, $file)
                GUICtrlSetData($OutFileInput, StringTrimRight($file, $TrimLength))
            Case $OutFileButton
                $file = FileSaveDialog("Output file", "", "Any file (*.*;)")
                If $file <> "" Then GUICtrlSetData($OutFileInput, $file)

            Case $EncryptButton
                $infile = GUICtrlRead($InFileInput)
                If Not FileExists($infile) Then
                    MsgBox(16, "Error", "Input file doesn't exists!")
                    ContinueLoop
                EndIf


                $outfile = GUICtrlRead($OutFileInput)
                If $outfile = "" Then
                    MsgBox(16, "Error", "Please input a output file")
                    ContinueLoop
                EndIf


                $password = GUICtrlRead($PasswordInput)
                If $password = "" Then
                    MsgBox(16, "Error", "Please input a password")
                    ContinueLoop
                EndIf

                AdlibRegister("Update", 333)
                $success = _Crypt_DecryptFile($infile, $outfile, $password, $CALG_RC4)
                If $success Then
                    MsgBox(0, "Success", "Operation succeeded")
                Else
                    Switch @error
                        Case 1
                            MsgBox(16, "Fail", "Failed to create key")
                        Case 2
                            MsgBox(16, "Fail", "Couldn't open source file")
                        Case 3
                            MsgBox(16, "Fail", "Couldn't open destination file")
                        Case 4 Or 5
                            MsgBox(16, "Fail", "Encryption error")
                    EndSwitch
                EndIf

                AdlibUnRegister("Update")
                WinSetTitle($hWnd, "", "File Decrypter")
        EndSwitch
    WEnd
EndFunc   ;==>_decrypt

If I use the InFileButton to choose the file, it strips the .crypt bit off in the OutFileInput. I have added the $TrimLength to the $OutFileInput in the command line parameter (like below) but it fails miserably.

If ($CmdLine[0] > 0) Then ;Used to prefill input areas when running a .crypt file
        GUICtrlSetData($InFileInput, $CmdLine[1])
        GUICtrlSetData($OutFileInput, $CmdLine[1], StringTrimRight($CmdLine, $TrimLength))

Any ideas?

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

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