How to substitute a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Docfxit
Posts: 29
Joined: 12 Nov 2015 12:42

How to substitute a variable

#1 Post by Docfxit » 10 Mar 2019 13:13

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

Squashman
Expert
Posts: 4106
Joined: 23 Dec 2011 13:59

Re: How to substitute a variable

#2 Post by Squashman » 10 Mar 2019 13:22

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"

Docfxit
Posts: 29
Joined: 12 Nov 2015 12:42

Re: How to substitute a variable

#3 Post by Docfxit » 10 Mar 2019 13:52

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

Post Reply