Meerecat Posted June 9, 2011 Share Posted June 9, 2011 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 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. Link to comment Share on other sites More sharing options...
pieeater Posted June 10, 2011 Share Posted June 10, 2011 (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 June 10, 2011 by pieeater [spoiler]My UDFs: Login UDF[/spoiler] Link to comment Share on other sites More sharing options...
BrewManNH Posted June 10, 2011 Share Posted June 10, 2011 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 GudeHow 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 Link to comment Share on other sites More sharing options...
smartee Posted June 10, 2011 Share Posted June 10, 2011 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 associations2. Yes, search the help-file for command line parameters3. Yes, file associations again, may be of some pertinence 4. This is fun easily done by using command line parameters again5. 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 -smartee Link to comment Share on other sites More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 (edited) Thanks for the replies guys. I've fallen at the first hurdle though 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 June 10, 2011 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 More sharing options...
smartee Posted June 10, 2011 Share Posted June 10, 2011 You have a typo in the below code 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') Link to comment Share on other sites More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 You have a typo in the below code 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. Link to comment Share on other sites More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 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 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 More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 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. Link to comment Share on other sites More sharing options...
Mat Posted June 10, 2011 Share Posted June 10, 2011 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 Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 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. Link to comment Share on other sites More sharing options...
Mat Posted June 10, 2011 Share Posted June 10, 2011 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?" AutoIt Project Listing Link to comment Share on other sites More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 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. Link to comment Share on other sites More sharing options...
GEOSoft Posted June 10, 2011 Share Posted June 10, 2011 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!" Link to comment Share on other sites More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 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. Link to comment Share on other sites More sharing options...
smartee Posted June 10, 2011 Share Posted June 10, 2011 He meant you need to add that line. I will whip up a quick example for you in a minute. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 10, 2011 Developers Share Posted June 10, 2011 What should the click of the button do? 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 More sharing options...
Meerecat Posted June 10, 2011 Author Share Posted June 10, 2011 (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 June 10, 2011 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 More sharing options...
BrewManNH Posted June 10, 2011 Share Posted June 10, 2011 (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 thatThis 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 June 10, 2011 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 GudeHow 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 Link to comment Share on other sites More sharing options...
Mat Posted June 10, 2011 Share Posted June 10, 2011 Makes life so much easier with examples #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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now