0

I'm trying to add an application start task to unlock the ipSecurity section of the ApplicationHost.config file in my project. I have an cmd file located in /startup/startup.cmd. This is the contents of the file:

@echo off
@echo Installing "IPv4 Address and Domain Restrictions" feature 
powershell -ExecutionPolicy Unrestricted -command "Install-WindowsFeature Web-IP-Security"
@echo Unlocking configuration for "IPv4 Address and Domain Restrictions" feature 
%windir%\system32\inetsrv\AppCmd.exe unlock config -section:system.webServer/security/ipSecurity

I've added this to application_start in Global.asax to run it:

var rootPath = HostingEnvironment.ApplicationPhysicalPath;
var startupFilePath = String.Format("{0}startup\\startup.cmd", rootPath);
System.Diagnostics.Process.Start(startupFilePath);

When I tried to load my site I got the error The specified executable is not a valid application for this OS platform. How do I resolve this?

Erica Stockwell-Alpert
  • 4,624
  • 10
  • 63
  • 130
  • 1
    You need to tell `Process` that you want to run a batch file. See https://stackoverflow.com/questions/2382683/how-do-i-use-processstartinfo-to-run-a-batch-file – Cᴏʀʏ Aug 17 '17 at 20:44
  • I added UseShellExecute = true but it still didn't work. I also tried adding Verb = "runas" and got an "access denied" error – Erica Stockwell-Alpert Aug 17 '17 at 20:51

0 Answers0