Jump to content

File Register using AutoIt


Recommended Posts

Before I say anything, I have read the FAQ and have been trying my best to use what is in the FAQ to Register a file type with notepad, but I can't seem to pull it off.

I have been racking my brain over this for several hours now. I know I am not a good programmer, I have only taken a few basic classes (which were many years ago) and when I compare the programs I have been making for my job (to automate our 6 month updates), to many in these forums, I'm a simple drooling baby in comparison. I have done well so far to pull everything off for our 200+ computers but this part has me stumped and pulling my hair out. I need a program make a file extension register with notepad so that when someone were to click on the "example.cfg" file it would open up in notepad. If someone could honestly help me out here with this, I would be very grateful.

I will post what I currently have, and I am very sure I have plenty of errors within it, but if i could get any amount of help with this, again, I would be very grateful.

#include "FileRegister.au3"
;================================================
;
; Description: FileRegister($ext, $cmd, $verb [, $def [, $icon = "" [, $desc = "" ]]])
;     Registers a file type in Explorer
;
; Parameter(s): $ext -  File Extension without period eg. "zip"
;  $cmd -  Program path with arguments eg. '"C:\test\testprog.exe" "%1"'
;    (%1 is 1st argument, %2 is 2nd, etc.)
;  $verb - Name of action to perform on file
;    eg. "Open with ProgramName" or "Extract Files"
;  $def -  Action is the default action for this filetype
;    (1 for true 0 for false)
;    If the file is not already associated, this will be the default.
;  $icon - Default icon for filetype including resource # if needed
;    eg. "C:\test\testprog.exe,0" or "C:\test\filetype.ico"
;  $desc - File Description eg. "Zip File" or "ProgramName Document"
;
;================================================

FileRegister("cfg", '"' & "C:\Windows\System32\notepad.exe" & '" "%1"', "Open in Notepad", 1, "C:\Windows\System32\notepad.exe" & ',0', "CFG Program File")

Now I also have another part in which I tried to combine with what is above, but I was getting nothing.

;$cmdline[0] is the number of parameters passed
If $cmdline[0] <> 0 Then
$filename = $cmdline[1]
;Do something with the file here
MsgBox(0, "UXYFixer", 'The file name passed to the command line is "' & $filename & '"')
Else
; We did not get any command line parameters.
; If this is a command line only program, you would want to
; alert the user that the command line parameters were incorrect.
; If this is a GUI program (like a notepad program), you would
; want to simply continue from here without opening a file.
MsgBox(0, "UXYFixer", 'Command line parameters incorrect.' & @CRLF & 'Command line usage: "' & @ScriptName & '" "file to process"')
EndIf

Much of this is over my head, but I am trying to make sense of it.

~Thank you

Link to comment
Share on other sites

There are several threads about this already on the forum, do a search for it and I'm sure you'll find one or 2.

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

Link to comment
Share on other sites

Look in my signature for _ShellFile.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

To my simple understand after rereading your _ShellFile code multiple times, it seems to create a GUI in which a user would input what they was changed and whatnot, but that isn't what I am trying to do. I am trying to automate the process so there is no user interface whatsoever. I have to deploy this script and run them simultaneously on 200+ computers and let them do the work so that I do not have to go to each one individually. If I am wrong about your program, please correct me, but my understanding of moderate to advanced scripts is small. I probably shouldn't be touching this stuff to be honest, I feel really stupid sometimes, but so far everything else I have needed to be automated I have pulled off with little issue. This is the first I have come across where I am ramming my head against a brick wall, hoping that maybe I can make a crack.

Link to comment
Share on other sites

corekazuki,

I'm sure that you know this but thought that I would mention it anyway. If you want to change the app/prog/verb associated with a file extention you can do this within Windows. Note that all files having whatever extension you are working with are affected.

For the case you specified you can associate ext ".cfg" with Notepad and specify "open" as the verb (might be the default anyway).

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

corekazuki,

Given that you need to deploy a solution across 200+ machines you need to know the following:

- what OS they are running

- is the extension that you want to use in use at any of the PC's.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Corekazuki,

Yes, you've appeared to have misunderstood the UDF. What you were looking at was the example and not the UDF itself.

How you use it is pretty simple. Place the UDF (_ShellFile.au3) in the folder where your script is and then call the function like so >>

_ShellFile_Install("Open with myProgram", "fileextension") ; Associate the current program with the filetype .fileextension
_ShellFile_Install("Open with ImageEdit", "fileextension", "ImageEdit", "C:Program FilesImageEditImageEdit.exe") ; Associate the program ImageEdit.exe with the filetype .fileextension
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@kylomas

I know all of these computers (unfortunately) by heart. All but 20 are using windows 7, the 20 odd balls are using windows vista. About 40 or so of them are running windows 7 32bit, and the rest are running windows 7 64 bit (all of this ridiculousness is because my boss is cheap and doesn't care about consistency). The extension will be on all of them, thus why I will be running the script on all of the computers.

@guinness

Thank you for clearing that up for me. So to my understanding I do not need to edit the "_ShellFile.au3" at all and only have to place that file within the same folder as the script with either of these two lines of code >>

_ShellFile_Install("Open with myProgram", "fileextension") ; Associate the current program with the filetype .fileextension
_ShellFile_Install("Open with ImageEdit", "fileextension", "ImageEdit", "C:Program FilesImageEditImageEdit.exe") ; Associate the program ImageEdit.exe with the filetype .fileextension

I just need to edit one of these lines of code and use it within a script to perform the task that I need done?

Link to comment
Share on other sites

Thank you for clearing that up for me. So to my understanding I do not need to edit the "_ShellFile.au3" at all and only have to place that file within the same folder as the script with either of these two lines of code >>

Correct.

I just need to edit one of these lines of code and use it within a script to perform the task that I need done?

Correct, but from what I can gather the second example is probably what you're looking for. Also have a look at the header in the UDF as it explains clearly how to use too.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

corekazuki,

One last thing and I'll quit beating this up.

The extension will be on all of them

The extension is NOT in use by anything else?

I found this interesting discussion on MS TechNet regarding automating file extensions that may interest you.

http://technet.microsoft.com/en-us/library/ee692639.aspx

Good Luck,

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

@guinness

Thank You very much for dumbing it down for me. After a few trial and errors I finally got it to work. Now I just have one final question. Is it at all possible to run this as an exe? I would like to not have to install autoit on every computer here, but if I absolutely have to, I will create a script to automate it.

This is what I have as my final script that I have tested and works on a computer with autoit.

#include "_ShellFile.au3"
_ShellFile_Install("Open with Notepad", "cfg", "Notepad", "C:\Windows\System32\Notepad.exe")

@kylomas

The only reason I am doing this is because the file extension in the program we are using is pulled as script for a video game level. We need it to open in notepad by default so that we can easily edit the script. To my knowledge the cfg file extension isn't used by any other program, so setting it to open by default as notepad should be 100% safe. Thank you for your concern though, I understand why you bring up that issue.

Link to comment
Share on other sites

As long have you have an include for the Shellfile script from guinness then just compile as X86 exe and give it a try and all should be well.

Obviously if you have issues with x64 a x64 version will be necessary

Edited by Chimaera
Link to comment
Share on other sites

To add what Chimaera said, look in the Help file under the section 'Compiling Scripts with Aut2Exe' & also since you're new here I would suggest just to have a look at the Forum rules in case you decide to become a frequent visitor.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Okay, through some final trial and error I pulled off what I needed to. I knew how to compile a script into exe but my worry was that it wouldn't run on a computer without autoit because part of the script included an "#include" (haha) of an au3 file. I guess when autoit compiles a script into exe if it includes an "#include" (hahaha) it pulls the script from the included file as well so that the exe can be stand alone. I tested it and it worked perfectly stand alone on a computer without autoit. Thank you all for your help, now I don't feel like I wasted 8 work hours yesterday. =] Now I go back to the other 10 scripts I have to finish my touch ups before we roll out a massive update on every computer.

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