Page 1 of 1

How to substitute a variable

Posted: 10 Mar 2019 13:13
by Docfxit
The set variables are not being substituted where they are supposed to. This is my code:

Code: Select all

Set MachineName ="Docfxit"
Set UserName="IISUser"
CD \Program Files\fileacl
FILEACL C:\HostingSpaces\Docfxit /D "%MachineName%\IWAM_%MachineName%":WwAWaWePDO /D "%MachineName%\%UserName%":WwAWaWePDO /S "%MachineName%\ASPNET":RrRaRep /S "CREATOR OWNER":U/RrRaRepWwAWaWePXDDcO/RrRaRepWwAWaWePXDDcO /S "NT AUTHORITY\SYSTEM":RrRaRepWwAWaWePXDDcO /S "BUILTIN\Users":RrRaRepWwAX/RrRaRepX /S "%MachineName%\Administrator":RrRaRepWwAWaWePXDDcO /S "BUILTIN\Administrators":RrRaRepWwAWaWePXDDcO /PROTECT
cmd
When I run it you will see %MachineName% doesn't get substituted. This is the output of the code above:

Code: Select all

C:\Dnload\Webserver>Set MachineName =Docfxit
C:\Dnload\Webserver>Set UserName=IISUser
C:\Dnload\Webserver>CD \Program Files\fileacl
C:\Program Files\fileacl>FILEACL C:\HostingSpaces\Docfxit /D "\IWAM_":WwAWaWePDO
 /D "\IISUser":WwAWaWePDO /S "\ASPNET":RrRaRep /S "CREATOR OWNER":U/RrRaRepWwAWa
WePXDDcO/RrRaRepWwAWaWePXDDcO /S "NT AUTHORITY\SYSTEM":RrRaRepWwAWaWePXDDcO /S "
BUILTIN\Users":RrRaRepWwAX/RrRaRepX /S "\Administrator":RrRaRepWwAWaWePXDDcO /S
"BUILTIN\Administrators":RrRaRepWwAWaWePXDDcO /PROTECT

 no SID for trustee \IWAM_
I did run this with elevated "Run as Administrator ".

Thanks,
Docfxit

Re: How to substitute a variable

Posted: 10 Mar 2019 13:22
by Squashman
Do not put spaces on either side of the equals symbol. If a space is on the left of the equals symbol it becomes part of the variable name: %var %.
If it is on the right it becomes part of the value.

Also do not assign quotes to variables but do you use them to protect special characters and from trailing spaces being assigned to the variable.

Best practices.

Code: Select all

Set "MachineName=Docfxit"
Set "UserName=IISUser"

Re: How to substitute a variable

Posted: 10 Mar 2019 13:52
by Docfxit
Really nice of you to reply so quickly.
That did fix the problem and It's really nice of you to explain how it works.

I am now getting this output:

Code: Select all

C:\Dnload\Webserver>Set "MachineName=Docfxit"
C:\Dnload\Webserver>Set "UserName=IISUser"
C:\Dnload\Webserver>CD \Program Files\fileacl
C:\Program Files\fileacl>FILEACL C:\HostingSpaces\Docfxit /D "Docfxit\IWAM_Docfx
it":WwAWaWePDO /D "Docfxit\IISUser":WwAWaWePDO /S "Docfxit\ASPNET":RrRaRep /S "C
REATOR OWNER":U/RrRaRepWwAWaWePXDDcO/RrRaRepWwAWaWePXDDcO /S "NT AUTHORITY\SYSTE
M":RrRaRepWwAWaWePXDDcO /S "BUILTIN\Users":RrRaRepWwAX/RrRaRepX /S "Docfxit\Admi
nistrator":RrRaRepWwAWaWePXDDcO /S "BUILTIN\Administrators":RrRaRepWwAWaWePXDDcO
 /PROTECT

 no SID for trustee Docfxit\IWAM_Docfxit
Now I need to find someone that knows what is wrong with the permissions I'm trying to set for IIS.

Thanks,
Docfxit