Jump to content

Help with reading variable from ini-file


Dnelre
 Share

Recommended Posts

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.

Link to comment
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.

Cheers,

Brett

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

Edited by BrettF
Link to comment
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)
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
Link to comment
Share on other sites

  • 2 years later...
  • 2 weeks later...

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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