@manhng

Welcome to my blog!

Command Prompt Help List

July 28, 2021 09:34

Command Prompt Help List (edit)

Execute Command Prompt commands from C# - CODE-AI

Các chương trình Command Prompt trong Windows

C:\Windows\System32\cmd.exe
C:\Program Files\dotnet\dotnet.exe

Xóa files?

DEL /F /Q /S  "C:\Log\*.*" > NUL

Xóa folders & sub-folders?

RMDIR /Q /S "C:\Log"

Xóa tất cả trong thư mục 2nd

for /d %x in (2nd\*) do @rd /s /q "%x"

Tạo cấu trúc thư mục từ một thư mục khác

xcopy "G:\Perf-Log\1st" "G:\Perf-Log\3rd" /t /e

Copy struct folder without files

xcopy "G:\Perf-Log\1st" "G:\Perf-Log\3rd" /t /e

Kiểm tra trên máy tính Windows đã cài đặt phiên bản .NET Framework phiên bản nào?

Determine which .NET Framework versions are installed | Microsoft Docs

dir /b %windir%\Microsoft.NET\Framework\v*
dir /b /ad /o-n %systemroot%\Microsoft.NET\Framework\v?.*
reg query "HKLM\SOFTWARE\Microsoft\Net Framework Setup\NDP" /s

Kiểm tra trên máy tính Windows đã cài đặt phiên bản .NET Core phiên bản nào?

Determine which .NET Framework versions are installed | Microsoft Docs

dotnet --info
dotnet --list-sdks
dotnet --list-runtimes

CLI Program

June 23, 2021 10:33

CLI Program (edit)

Execute Command Prompt commands from C# - CODE-AI

  • C# code to call .exe program: Không để .exe ở sau lời gọi chương trình CLI
  • C# code to call .exe program: Có 2 cách để thực hiện, xem thêm 2 ví dụ ở dưới
  • C# code to call .exe program: Cần lưu ý vài điểm sau:
    • WorkingDirectory là folder chứa chương trình chạy, ví dụ C:\VPN\NetExtender\
    • FolderPath là folder chứa chương trình chạy, ví dụ C:\VPN\NetExtender\
    • Ở code dưới thì filePath là đường dẫn chương trình chạy, ví dụ C:\VPN\NetExtender\NECLI.exe

Example 1:

private static string CallNECLI(string param)
{
try
{
string filePath = string.Concat(Path.Combine(FolderPath, "NECLI"), ".exe");
if (!System.IO.File.Exists(filePath))
{
string str = $"File '{filePath}' does not exits";
Debug.WriteLine(str);
return str;
}

string command = string.Format("/c {0} {1}", "NECLI", param);
Debug.WriteLine(command);

var processInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", command)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
WorkingDirectory = FolderPath
};

System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.Diagnostics.Process p = System.Diagnostics.Process.Start(processInfo);
p.OutputDataReceived += (s, a) => sb.AppendLine(a.Data);
p.BeginOutputReadLine();
p.WaitForExit();

return sb.ToString();
}
catch (System.Exception ex)
{
Debug.WriteLine($"CallNECLI error, detail: {ex}");
throw;
}
}

Example 2:

 static void Main(string[] args)
{

string path = @"C:\VPN\NetExtender"; //Program: NECLI.exe

string command = @"NECLI connect -s ""server_name"" -u ""user_name"" -p ""pass_word"" -d ""domain_name""";

Process process = new Process();
process.StartInfo = new ProcessStartInfo
{
WorkingDirectory = path,
FileName = "cmd.exe",
CreateNoWindow = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardInput = true,
RedirectStandardOutput = true
};
process.Start();
process.StandardInput.WriteLine(command);
process.StandardInput.Flush();
process.StandardInput.Close();

string result = process.StandardOutput.ReadToEnd();

process.WaitForExit();

Console.WriteLine(result);

Console.ReadLine();
}

What is CLI (w3schools.com)

For .NET Core: Command Line Interface (CLI)

CLI stands for:

  • Command Line Interface
  • Command Line Interpreter
  • Command Line Input

Deploy IIS

October 16, 2018 08:56

Deploy IIS (edit)

https://www.c-sharpcorner.com/search/IIS

https://docs.microsoft.com/en-us/iis/manage/creating-websites/select-a-provisioning-option

1) The IIS Admin Service

NET START IISADMIN
NET STOP IISADMIN

2) World Wide Web Publishing Service

NET START  W3SVC
NET STOP W3SVC

Deployment of a Website on IIS

Application Pools on IIS 6.0

Deploying ASP.NET Websites on IIS 7.0

How To Deploy a Web App in IIS

Recycle Application Pool(s) in IIS 7 Server Using C# Code

Windows XP IIS Manager v1.7

Programmatically Manage IIS

Use C# to manage IIS

Beginner's Guide: Exploring IIS 6.0 With ASP.NET

Windows Service Management

Controlling installed services via ServiceController in WinForms

Using NET STOP and NET START commands to force IIS services to re-read the registry

https://support.microsoft.com/en-ie/help/236166/using-net-stop-and-net-start-commands-to-force-iis-services-to-re-read

Common IIS-related services

Service Name Display Name
Iisadmin IIS Admin Service
Msftpsvc FTP Publishing Service
Nntpsvc Microsoft NNTP Service
Smtpsvc Microsoft SMTP Service
W3svc World Wide Web Publishing Service

(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Kevin Zollman, Microsoft Corporation.

https://tecadmin.net/restart-iis-via-command-line/

3) Add Website

https://blogs.msdn.microsoft.com/rakkimk/2007/06/08/iis7-sample-code-for-addingdeleting-a-website-programmatically-c-example/

You can add a website using Add method that is present in the Sites collection of ServerManager. Below is the code snippet which creates an application Pool, and then creates a site, also enables the FREB and commit the changes to the IIS7 configuration file:

ServerManager serverMgr = new ServerManager();
Site mySite = serverMgr.Sites.Add("MySiteName", "C:\\inetpub\\wwwroot", 8080);
serverMgr.ApplicationPools.Add("MyAppPool");
mySite.ApplicationDefaults.ApplicationPoolName = "MyAppPool";
mySite.TraceFailedRequestsLogging.Enabled = true;
mySite.TraceFailedRequestsLogging.Directory = "C:\\inetpub\\customfolder\\site";
serverMgr.CommitChanges();

Now, let's try to delete the same website created. As you know earlier, in IIS7, you need to give an unique name for each website (which was not the case in IIS 6.0).

Site site = serverMgr.Sites["MySiteName"]; // you can pass the site name or the site ID

serverMgr.Sites.Remove(site);

serverMgr.CommitChanges();

4) Command Lines

https://www.codeproject.com/Articles/545019/ParsedCommandLine

Cmd

October 6, 2017 00:43

Command Line (edit)

Tham khảo:

Command to list all files in a folder as well as sub-folders in windows

The below post gives the solution for your scenario.

dir /s /b /o:gn

/S Displays files in specified directory and all subdirectories.

/B Uses bare format (no heading information or summary).

/O List by files in sorted order.

Then in :gn, g sorts by folders and then files, and n puts those files in alphabetical order.

Copy file to file

copy /y "PATH_TO_FILE" "D:\BACKUP\ONGAME-360\FILE_NAME"

xCopy folder to folder

xcopy /s "C:\inetpub\wwwroot\Sites\Site1\*.*" "D:\Sites\Site1\"

xCopy folder structure

xcopy C:\Your Folder C:\New Folder /t /e

http://techbrij.com/notes/windows-run-commands.php

Lấy danh sách thư mục (folder) và thư mục con (sub-folder)

dir /s /b /o:n /ad > folders.txt
dir /s /b /o:gn > files.txt

Categories

Recent posts