Sign in to follow this  
Followers 0
Dnelre

Help with reading variable from ini-file

6 posts in this topic

Hello.

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

[permissions]
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", "")

and

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



#2 ·  Posted (edited)

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.

Cheers,

Brett

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

#3 ·  Posted (edited)

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)
EndIf

:mellow:

Edit:

do the ini like this

[permissions]
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

Thanks mate for this its works flawlessly :D

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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)

users.txt

$CALG_RC4
"123456"
"data.txt"
"data2.txt"

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:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
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  
Followers 0