Sign in to follow this  
Followers 0
A_Noobie_User

Using variables with autoit

5 posts in this topic

Hello all. Lots of interesting reading, and tips here.

Now lets get to the nitty-gritty. This is driving me insane. I am trying to read a "variable" from an .ini file. That part is easy. Now what I want to do is pass the "variable" on to a command line. That way I can execute it. I have spent quite a few hours trying diffrent combos of everything, and I have only found one way to make it work. The problem is: it requires useing "start.exe" which is not included with XP. I had an old ghost image of Win2k laying around, so I got my copy of start.exe from there. I dont want to have to use start.exe if I dont have to.

Here is the script I am running:

$var0 = IniRead("d:\Temp1\myfile.ini", "path", "filepath", "NotFound")

MsgBox(4096, "Result", $var0)

run("start """ $var0 &)

The script above works perfectly. I am having no problems reading the "variable" from the .ini file. All the .ini file supplies is the "$var = d:\windows\notepad". I have the message box come up, and it says "d:\windows\notepad.exe". That part is working fine.

Now here are examples of many tries to use the "variable", in diffrent combos. None of these work. Could a kind soul go through some of these diffrent things I have tried and make them work. I would really like to use "explorer.exe" to pass the "variable" to.

Run(@COMSPEC & ' /c explorer.exe $var0')

Run(@COMSPEC & ' /c "explorer.exe" "$var0"')

Run(@COMSPEC & " /c &var0")

Run(@ComSpec & ' /C explorer.exe $var0', '', @SW_HIDE)

When I run some of these, explorer gives an error message "$var0" is not a file or folder name. I will also get errors form autoit, about syntex errors.

Many great thanks to the people that support these forums, and help out a n00bie like myself.

Share this post


Link to post
Share on other sites



try:

Run(@COMSPEC & ' /c explorer.exe ' & $var0)

or

Run(@COMSPEC & " /c explorer.exe " & $var0)

or with version 3.0.103

opt("ExpandVarStrings",1)
Run(@COMSPEC & " /c explorer.exe $var0$")

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

If the given file is an executable you don't need any prefix.

$var0 = IniRead("d:\Temp1\myfile.ini", "path", "filepath", "NotFound")
MsgBox(4096, "Result", $var0)
If $var0 <> "NotFound" Then Run($var0)

If it's not an executable try this:

$var0 = IniRead("d:\Temp1\myfile.ini", "path", "filepath", "NotFound")
MsgBox(4096, "Result", $var0)
If $var0 <> "NotFound" Then Run(@ComSpec & ' /c Start "" "' & $var0 & '"')

Share this post


Link to post
Share on other sites

i think your problem lies in how you set up your .ini file and how you are using IniRead().

change your script to:

$var0 = IniRead("d:\Temp1\myfile.ini", "SectionName", "Key", "NotFound")
MsgBox(4096, "Result", $var0)
RunWait(@ComSpec & " /c " & $var0, "", @SW_HIDE)

and change myfile.ini to:

[SectionName]
Key=d:\windows\notepad

of course you can change SectionName and Key to whatever you want, but if you use path and filepath in IniRead(), you need to also use that in your .ini file like so:

[path]
filepath=d:\windows\notepad

note that you could just use filepath=notepad if you are running something like notepad or calc.

if you just want to just run a .exe, you can just use Run() without anything else:

;Run("Notepad.exe", "", @SW_MAXIMIZE)
Run($var0)

haha, i just got this all typed out and then i hit preview and noticed there are already two replies. oh well. i'll post this anyways. i think my comment about your .ini file still holds true.

Share this post


Link to post
Share on other sites

Thanks a million for all the replies. What stinks is I have to go to work soon. I will not have time to try these suggestions out till tomorrow night. The examples look good. There is a lot of new info here to digest.

Thanks again for all your help.

To clear up any confusion on my .ini file.

[path]

filepath=d:\windows\notepad.exe

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