顯示具有 command 標籤的文章。 顯示所有文章
顯示具有 command 標籤的文章。 顯示所有文章

2024年10月8日 星期二

使用command line 建立一個IIS web site

@SET /P A_ans=please type the Account for the Identity=

@SET /P P_ans=please type the password for the Identity=

powershell Expand-Archive "%~dp0Web.zip" -DestinationPath "%~dp0Web"

robocopy "%~dp0Web" "D:\temp" /E


REM add application pool

%WINDIR%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='NewAppPool',autoStart='True',managedPipelineMode='Integrated']" /commit:apphost

%WINDIR%\system32\inetsrv\appcmd.exe set config /section:applicationPools /[name='NewAppPool'].processModel.identityType:SpecificUser /[name='NewAppPool'].processModel.userName:%A_ans% /[name='NewAppPool'].processModel.password:%P_ans% 


REM add app

%WINDIR%\system32\inetsrv\appcmd.exe add app /site.name:"Default Web Site" /path:/NewWeb /physicalPath:"D:\temp\Web" /applicationPool:NewAppPool


2019年11月21日 星期四

2019年4月25日 星期四

C# 執行vbs語法

Thread executionThread = new Thread(new ParameterizedThreadStart(RunPrograms));
                    ProcessStartInfo startInfo = new ProcessStartInfo(ProgramPath);
                    startInfo.Arguments = ProgramArguments;
                    startInfo.UseShellExecute = false;
                    startInfo.RedirectStandardInput = false;
                    ExecutionInstance executionInstance = new ExecutionInstance(startInfo, FilePath);
                    executionThread.Start(executionInstance);
                    Log.WriteToLog("Info", "Added program to execute \"{0}\" argument \"{1}\".", ProgramPath, ProgramArguments);

public static void RunPrograms(object source)
        {
            try
            {
                bool success = false;
                int retries = 100;

                ExecutionInstance executionInstance = (ExecutionInstance)source;
                FileStream fileStream = null;

                while (!success)
                {
                    try
                    {
                        fileStream = File.Open(executionInstance.FilePath, FileMode.Open, FileAccess.Read, FileShare.None);
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        Log.WriteToLog("Error", "Unhandled exception occurred while waiting for \"{0}\" to become available. Type: {1} Message: {2}", executionInstance.FilePath, ex.GetType().FullName, ex.Message);
                        Thread.Sleep(1000);
                        if (--retries == 0)
                        {
                            Log.WriteToLog("Error", "Exception occurred while opening the file. File: {0} Message: {1}", executionInstance.FilePath, ex.Message);
                            break;
                        }
                    }
                }

                fileStream.Close();

                try
                {
                    Log.WriteToLog("Info", "Running program in response to event for {2}: {0}{1}.", executionInstance.StartInfo.FileName, (executionInstance.StartInfo.Arguments != "" ? " " + executionInstance.StartInfo.Arguments : ""), executionInstance.FilePath);
                    Process executionProcess = Process.Start(executionInstance.StartInfo);
                    executionProcess.WaitForExit();
                    executionProcess.Close();

                    string path = Path.GetDirectoryName(executionInstance.FilePath);
                    string[] filePaths = Directory.GetFiles(path);

                    string file = Path.GetFileName(executionInstance.FilePath);

                }
                catch (Exception ex)
                {
                    Log.WriteToLog("Error", "Exception occurred while running {0}. Type: {1} Message: {2}", (executionInstance.StartInfo != null ? "\"" + executionInstance.StartInfo.FileName + "\"" : ""), ex.GetType().FullName, ex.Message);
                }
            }
            catch (Exception ex)
            {
                Log.WriteToLog("Error", "Exception occurred. Type: {0} Message: {1}", ex.GetType().FullName, ex.Message);
            }
        }