Jump to content
Sign in to follow this  

Help with reading variable from ini-file

Recommended Posts



I'm a complete beginner with AutoIt, but that doesn't stop me from trying to create a time saving script! :mellow:

The script's purpose is to change permissions on folders, with the SETACL.EXE tool. I use AutoIt to get some answers from the user, for example WHICH folders to change permissions on, and which template of permissions that I want to apply.

Now on to the problem:

The SETACL.EXE tool takes parameters, like this: "SetACL.exe -on "C:\clue" -ot file -actn ace -ace "n:ewg;p:full;i:so,sc;m:set;w:dacl""

Since the permissions will be different from folder to folder, I can't hard-code the permissions in the script, so I've chosen to read the permissions from ini-files instead. I'm aware of the fact that I need to double-quote etc, but no matter what I do, I am unable to read the $PATH variable from the ini as anything else than plain text. Am I doing something wrong?

SETACL.exe just complains that it cannot find the path $path...

I get my $PATH from a simple $path = FileSelectFolder in the script, and that part works. The script works perfectly if the permissions are hard-coded. But with this ini.....

TPGPERMS=""-on & $path & -ot file -actn ace -ace ""n:ewg;p:full;i:so,sc;m:set;w:dacl""

...it just won't work.

Here's the "action" part of the script.

$perms = IniRead(@ScriptDir & "\tpg.ini", "permissions", "TPGPERMS", "")


ShellExecuteWait(@ScriptDir & "\SETACL.EXE", $perms)

What am I doing wrong?

..and one more thing!

Even with the permissions hard-coded in the script, I'm having troubles if the $path contains spaces. What would the proper quoting be?

Let me know if you need more details! :(

Thanks in advance.

Share this post

Link to post
Share on other sites

Welcome to the forums Dnelre.

The follow code will work with little modification to the ini and the script.

Opt ("ExpandVarStrings", 1)
$path = "C:\Nowhere\"

$str = "-on $path$ -ot file -actn ace -ace ""n:ewg;p:full;i:so,sc;m:set;w:dacl"

MsgBox (0, "", $str)

As you can probably see i've set the script to parse $var_name$ in strings as variables. Similar to going "string..." & $var_name & "...string".

I'm wondering if your logic is correct though. How are you generating this ini? Is it done manually? Is there a way to do it using AutoIt alone? Is it really neccessary. Maybe if we had some idea to what your end result was we could assist a little more.



And sorry for my rude reply before. I was in a rush not to burn the house down... :mellow:

Edited by BrettF

Share this post

Link to post
Share on other sites

Welcome to the forum Dnelre,

This may help you.

; get value for $path variable
$path = FileSelectFolder('dialog text', '')
;if $path variable value is different to "" then process
If $path <> "" Then
    ; read command from ini file
    $perms = IniRead(@ScriptDir & "\tpg.ini", "permissions", "TPGPERMS", "")
    ; replace literal string $path with value of $path variable
    $perms = StringReplace($perms, '$path', $path)
    ; execute the command
    ShellExecuteWait('"' & @ScriptDir & '\SETACL.EXE"', $perms)



do the ini like this

TPGPERMS=-on "$path" -ot file -actn ace -ace "n:ewg;p:full;i:so,sc;m:set;w:dacl"
Edited by MHz

Share this post

Link to post
Share on other sites

my script code

#include <Crypt.au3>

$encryption = FileReadLine ( "users.txt" , 1 )
$key = FileReadLine ( "users.txt" , 2 )
$filename = FileReadLine ( "users.txt" , 3 )
$outname = FileReadLine ( "users.txt" , 4 )

$sSourceFile = $filename
$sDestinationFile = $outname
$vCryptKey = $key
$iALG_ID = $encryption
_Crypt_EncryptFile($sSourceFile, $sDestinationFile, $vCryptKey, $iALG_ID)



not working what i am doing wrong ??? please help

Edited by verma123

Share this post

Link to post
Share on other sites

Not working is a bit vague!

You should always check the return value and macros @error and @extended when you don't get the expected result!

My UDFs and Tutorials:


Active Directory (NEW 2017-04-18 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version - Download - General Help & Support

ADO - Wiki


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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.