Sign in to follow this  
Followers 0
Meerecat

Registering with Windows Default program

46 posts in this topic

Hello

I have completed my first proper program with the help of a few people on here (special thanks to MHz).

Basically it encrypts a file and adds .crypt as an extension, then decrypts a file and removes the .crypt extension.

I would like to make a couple of improvements and am not sure if they are even possible.

1. I would like the script to register .crypt as an extension in Windows default programs, with my File Guard as the registered program. So if you try to open a .crypt file it opens my program.

2. If 1 is possible, I would like the encrypted file name to be populated into the decrypt file dialogue (if you run the program you should understand what I mean).

3. I would like to be able to right click any file and have an option in the Windows context menu called 'Encrypt with File Guard'. This would then open my program.

4. If 3 is possible, I would like the file name to be populated into the encrypt file dialogue (if you run the program you should understand what I mean).

5. If someone tries to open a .crypt file who doesn't have a copy of my program, I would like a message box displayed. I suspect this is impossible as if they don't have my script I can't process a command on their computer. However since I am new to AutoIT it doesn't hurt to ask.

Many thanks for any help or suggestions. If none of the above is possible then I'm sorry for your wasted time in reading this :huh2:

Meerecat File Guard.au3


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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

2. if 1 is possible(id like to know that to) then im pretty sure you can

3. it would only work well the script is running

4. read 3

5. basically what your asking is if you can have the extension .crypt for your program only, which i don't think is possible because it would(not sure but i think it would) require some modifying the windows OS.

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

1 - Yes you can register your own file type, you'll need to do a registry write, the main keys are located at "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts". You'll probably need to look at what other file types are registered there and format your regwrite to look the same.

2 - Use command line parameters in your script and you can read the file name from the system when it opens the file.

3 - It can be done, not sure the procedure, but you should be able to find that information on the forum here

4 - See #2

5 - Not possible


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi Meerecat,

Can it be done? Let's tackle it one at a time.

1. Yes, if you search the forums, there are dozens of threads about setting file type associations

2. Yes, search the help-file for command line parameters

3. Yes, file associations again, may be of some pertinence

4. This is fun ;) easily done by using command line parameters again

5. :huh2: a bit tricky. Cannot be done exactly as you stated, but an easy workaround is available, rather than encrypting the file and adding the crypt extension, encrypt the file, and pack it in an executable file so that the encrypted files are *.exe rather than *.crypt.

In such a case, you wouldn't need 1-4 (well you might need Command line parameters depending on whether you implement the full decryptor in the executable or just some type of calling/alert program)

So pick your route, research/take a jab at it, post back if you get stuck or need more info.

Hope this helps :alien:

-smartee

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for the replies guys.

I've fallen at the first hurdle though :huh2:

I've started off with the file extension. I found an example of regwrite:

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

It appears to create the registry keys, but when I click on a .crypt file Windows doesn't know what to do with it.

Here are the keys it creates:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.crypt]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.crypt\OpenWithList]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.crypt\OpenWithProgids]
"Cyrpt File"=hex(0):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.crypt]
@="Cyrpt File"

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Crypt File]

[HKEY_CLASSES_ROOT\Crypt File\shell]

[HKEY_CLASSES_ROOT\Crypt File\shell\open]

[HKEY_CLASSES_ROOT\Crypt File\shell\open\command]
@="C:\\Program Files (x86)\\Meerecat File Guard\\Meerecat File Guard.exe"

Have I done something wrong?

Many Thanks

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.

Share this post


Link to post
Share on other sites

You have a typo in the below code :huh2:

RegWrite('HKCR\.crypt\', '', 'REG_SZ', 'Cyrpt File')<==typo, should be Crypt
RegWrite('HKCR\Crypt File\shell\open\command\', '', 'REG_SZ', 'C:\Program Files (x86)\Meerecat File Guard\Meerecat File Guard.exe')

Share this post


Link to post
Share on other sites

You have a typo in the below code :huh2:

RegWrite('HKCR\.crypt\', '', 'REG_SZ', 'Cyrpt File')<==typo, should be Crypt
RegWrite('HKCR\Crypt File\shell\open\command\', '', 'REG_SZ', 'C:\Program Files (x86)\Meerecat File Guard\Meerecat File Guard.exe')
Perfect, thank you. 1 down, 4 to go ;)

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.

Share this post


Link to post
Share on other sites

Woo Hoo

1 and 3 now done. They were easy. I suspect 2 and 4 are going to be more challenging.

As for 5, not sure yet if I want to do this, though if I do your suggestion is great, thanks Smartee :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.

Share this post


Link to post
Share on other sites

Ahhhh my head is going to explode. Unless I am misreading this, I would run the program with certain parameters from a command line, which will insert the correct file name into the encrypt / decrypt input fields of my script.

Does that mean the user would have to use these same parameters to run the program correctly? Really struggling with this bit. Can anybody help get me started, or should I just accept this bit of the project is above my level for now?

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.

Share this post


Link to post
Share on other sites

Ahhhh my head is going to explode. Unless I am misreading this, I would run the program with certain parameters from a command line, which will insert the correct file name into the encrypt / decrypt input fields of my script.

Does that mean the user would have to use these same parameters to run the program correctly? Really struggling with this bit. Can anybody help get me started, or should I just accept this bit of the project is above my level for now?

Thanks

To get windows to open with the file name you use this as the run line. %1 is replaced by the file name.

MyProram.exe "%1"

Then in the program, you use $CmdLine as usual.

In order to make command line parameters optional you check the count of parameters:

$sTheFile = "" ; Default to no file specified
If $CmdLine[0] > 0 Then $sTheFile = $CmdLine[1] ; But if the user specifies a command line then use that

Mat's untested code warranty: In theory, practive and theory are the same. In practice they are not. Code above is untested but should work in theory :huh2:

Mat

Share this post


Link to post
Share on other sites

So I need a command line arguement to have the file name automatically put here:

Case $InFileButton
                $file = FileOpenDialog("Input File", "", "All files (*.*;)")
                If $file <> "" Then
                    GUICtrlSetData($InFileInput, $file)
                    GUICtrlSetData($OutFileInput, $file & $Extension)

Is that even possible?

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.

Share this post


Link to post
Share on other sites

Yes it is possible. Have a variable like I showed you above with $sTheFile, which is empty by default or the command line parameter if it is supplied, and then you can check if it's empty or not.

Try it. Write a small sample and test the theory, come back with a reproducer if it's possible, and don't ask questions like "Is it possible?" ask "I tried this <code example>, how should I do it?" :huh2:

Share this post


Link to post
Share on other sites

Hello again

I've knocked up a quick test program. I've tried:

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



$file = "" ; Default to no file specified
If $CmdLine[0] > 0 Then $file = $CmdLine[1] ; But if the user specifies a command line then use that


GUICreate("", 369, 112)
$InFileInput = GUICtrlCreateInput("", 32, 40, 161, 21)
$InFileButton = GUICtrlCreateButton("Button1", 208, 40, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then GUICtrlSetData($InFileInput, $file)

    EndSwitch
WEnd

AND

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



$InFileInput = "" ; Default to no file specified
If $CmdLine[0] > 0 Then $InFileInput = $CmdLine[1] ; But if the user specifies a command line then use that


GUICreate("", 369, 112)
$InFileInput = GUICtrlCreateInput("", 32, 40, 161, 21)
$InFileButton = GUICtrlCreateButton("Button1", 208, 40, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then GUICtrlSetData($InFileInput, $file)

    EndSwitch
WEnd

Then I've tried running from a command line

test.exe test.txt

and

test.exe "test.txt"

Neither of these options fill the input field with test.txt when my program starts. Where have I gone wrong?


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.

Share this post


Link to post
Share on other sites

You forgot the GUICtrlSetData($InFileInput, $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!"

Share this post


Link to post
Share on other sites

What do you mean? Do I need to remove that line?

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.

Share this post


Link to post
Share on other sites

He meant you need to add that line.

I will whip up a quick example for you in a minute.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

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

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.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

This line reads the command line parameter:

If $CmdLine[0] > 0 Then $InFileInput = $CmdLine[1] ; But if the user specifies a command line then use that

This line overwrites that value with the control ID

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

You need to change the second line's variable name, or the one that reads the command line parameter, and you need to use the command line parameter's variable in place of the "" in your GUICtrlCreateInput like this

$inputparameter = ""

If $CmdLine[0] > 0 Then $inputparameter = $CmdLine[1] ; But if the user specifies a command line then use that

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

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Makes life so much easier with examples :huh2:

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



$file = "" ; Default to no file specified
If $CmdLine[0] > 0 Then $file = $CmdLine[1] ; But if the user specifies a command line then use that


GUICreate("", 369, 112)
$InFileInput = GUICtrlCreateInput($file, 32, 40, 161, 21)
$InFileButton = GUICtrlCreateButton("Button1", 208, 40, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then GUICtrlSetData($InFileInput, $file)
    EndSwitch
WEnd

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