Пример #1
0
 private void ExecuteScript(string contents)
 {
     CtxTrace.TraceInformation();
     try {
         string dir      = CreateWorkingDirectory(cfnFolder);
         string fileName = Path.Combine(dir, "user-data.cmd");
         File.WriteAllText(fileName, contents);
         ScriptUtilities.ExecuteProcess("cmd.exe", "/c " + fileName, dir);
     } catch (Exception e) {
         CtxTrace.TraceError(e);
     }
 }
Пример #2
0
        private void ExecutePowerShellScript(string contents)
        {
            CtxTrace.TraceInformation();
            string oldPolicy = null;

            try {
                oldPolicy = ScriptUtilities.SetPowerShellExectionPolicy("Unrestricted");
                string dir      = CreateWorkingDirectory(cfnFolder);
                string fileName = Path.Combine(dir, "user-data.ps1");
                File.WriteAllText(fileName, contents);
                ScriptUtilities.ExecuteProcess("powershell.exe", String.Format("-F {0}", fileName), dir);
            } catch (Exception e) {
                CtxTrace.TraceError(e);
            } finally {
                if (oldPolicy != null)
                {
                    ScriptUtilities.SetPowerShellExectionPolicy(oldPolicy);
                }
            }
        }