Jump to content
Sign in to follow this  
camilla

Run Batch file command from autoit script

Recommended Posts

camilla

hello everyone, i need your help to run this command from an autoit script.it

----------------------------------------------------------

@echo off

assoc .db=MyAppendage

FTYPE MyAppendage="%%1"%%*

cls

exit

----------------------------------------------------------

thank you in advance

Share this post


Link to post
Share on other sites
Danyfirex

You should wait for help. ¬¬ don't bump your post before 24 hour.

Share this post


Link to post
Share on other sites
EKY32

Hey title="Run Batch file command from autoit script: post #1"> camilla,

Please try this:

FileWrite(@TempDir & "\cmd.bat", "@echo off" & @CRLF & "assoc .db=MyAppendage" & @CRLF & 'FTYPE MyAppendage="%%1"%%*' & @CRLF & "cls" & @CRLF & "exit")
Run(@TempDir & "\cmd.bat")

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Share this post


Link to post
Share on other sites
camilla

 

EKY32

 thank you it works, but the cmd.bat still exist in tempdir

i want the script to run the bat command directly without any other files

thank you

Share this post


Link to post
Share on other sites
EKY32

Yes, try this:

FileWrite(@TempDir & "\cmd.bat", "@echo off" & @CRLF & "assoc .db=MyAppendage" & @CRLF & 'FTYPE MyAppendage="%%1"%%*' & @CRLF & "cls" & @CRLF & "del %temp%\cmd.bat" & @CRLF & "exit")
Run(@TempDir & "\cmd.bat")

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Share this post


Link to post
Share on other sites
EKY32

And please, can I ask what does your code do?

Is it for refreshing the icon cache or something?


[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Share this post


Link to post
Share on other sites
camilla

i tried it it works fine,but the script creates a cmd.bat in @tempDir and hte dos window prompt for a second.

i want the bat command to be run from autoit script without creating that cmd.bat and without dos window prompt

yes it is for refreshing the icon cache and to run some files dirctly throught therir original file type

Share this post


Link to post
Share on other sites
EKY32

I think this code refreshes the icon cache:

DllCall("user32.dll", "lresult", "SendMessageTimeout", "hwnd", 65535, "uint", 26, "wparam", 42, "lparam", 0, "uint", 2, "uint", 10000, "dword*", "success")

And you can use the Run command to run files directly through their original file type.

Run(@ComSpec & " /c " & 'c:\photo.jpg', "", @SW_HIDE)

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Share this post


Link to post
Share on other sites
camilla

exactly i need this code

--------------------------------------------------------

Run(@ComSpec & " /c " & 'c:photo.jpg', "", @SW_HIDE)
 
-------------------------------------------------------------------------
 

but instead "c:photo.jpg" i need to run the commands [

assoc .db=MyAppendage

FTYPE MyAppendage="%%1"%%*]

Share this post


Link to post
Share on other sites
BrewManNH

So, what's the question? Just change the Run command to run the program you want it to run, you already know what the command is, you'll need 2 run commands though, one for Assoc and one for Ftype, but it's not that hard to do. 

BTW, you will probably need to use #RequireAdmin if you're doing this under Vista+


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
camilla

i want to run that command without dos prompt

i mean run directly from the autoit script  as an autoit script not a batch script

Share this post


Link to post
Share on other sites
EKY32

Run and _RunDOS does not support multi-line commands as far as i know, so that's why we saved the commands to a bat file to temp folder.

then I gave you an alternative code for both your commands >here.

I think nothing can be done more.


[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Share this post


Link to post
Share on other sites
careca

It seems like i don't have either assoc or ftype exe's in my win 7... so i couldn't test it... but this is how i'd do it.

ShellExecute('assoc', '.db1=MyAppendage')
ShellExecute('FTYPE', 'MyAppendage="%%1"%%*]')

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
BrewManNH

I already told you how to do that, take your batch commands, stick them into a run function and you're done.

#RequireAdmin
Run("Assoc .db=MyAppendage", "", @SW_HIDE)
Run("Ftype MyAppendage="%%1"", "", @SW_HIDE)

Or something similar to that. Personally I'd remove the @SW_HIDE so you can see what error you might get, if any, until you know it's working.

  • Like 1

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
EKY32

I already told you how to do that, take your batch commands, stick them into a run function and you're done.

#RequireAdmin
Run("Assoc .db=MyAppendage", "", @SW_HIDE)
Run("Ftype MyAppendage="%%1"", "", @SW_HIDE)

Or something similar to that. Personally I'd remove the @SW_HIDE so you can see what error you might get, if any, until you know it's working.

 

excuse me, as he is a new member, single quotes should be used:

#RequireAdmin 
Run("Assoc .db=MyAppendage", "", @SW_HIDE)
Run("Ftype MyAppendage='%%1'", "", @SW_HIDE)

But it never worked for me in this way, Win 7.

and this:

ShellExecute('assoc', '.db1=MyAppendage')
ShellExecute('FTYPE', 'MyAppendage="%%1"%%*]')

reported an error.

Edited by EKY32

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Share this post


Link to post
Share on other sites
camilla

 

danwilli

thank you

 

careca

thank you

 

thank you it works as i want it now

 

It seems like i don't have either assoc or ftype exe's in my win 7... so i couldn't test it... but this is how i'd do it.

 

i will test it and see in win7 32&64

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  

×