參考網誌
https://shunnien.github.io/2017/06/01/webconfig-httpErros-and-customErrors/
2019年7月9日 星期二
2019年6月28日 星期五
[CMD] windows 批次刪除特定日期區間的檔案
資料來源 https://blog.darkthread.net/blog/forfiles/
#取得日期
for /F "tokens=1-4 delims=/ " %%a IN ("%date%") DO (
set _year=%%a
set _month=%%b
set _day=%%c
set _week=%%d
set _today=%%a%%b%%c
)
#顯示年,例:2019
echo %_year%
#顯示月,例:03
echo %_month%
#顯示日,例:30
echo %_day%
#顯示星期幾,例:週二
echo %_week%
#顯示今天日期,例:20150330
echo %_today%
#取得日期
for /F "tokens=1-4 delims=/ " %%a IN ("%date%") DO (
set _year=%%a
set _month=%%b
set _day=%%c
set _week=%%d
set _today=%%a%%b%%c
)
#顯示年,例:2019
echo %_year%
#顯示月,例:03
echo %_month%
#顯示日,例:30
echo %_day%
#顯示星期幾,例:週二
echo %_week%
#顯示今天日期,例:20150330
echo %_today%
2019年5月21日 星期二
2019年4月30日 星期二
2019年4月25日 星期四
SQL 查詢預存程序內有包含特定關鍵字
SELECT distinct sys.sysobjects.name, sys.sysobjects.type, sys.syscomments.text
FROM sys.sysobjects INNER JOIN syscomments
ON sys.sysobjects.id = sys.syscomments.id
WHERE sys.syscomments.text LIKE '%BSA_InsSuspiciousActivity%'
--AND sys.sysobjects.type = 'P'
ORDER BY sys.sysobjects.NAME
FROM sys.sysobjects INNER JOIN syscomments
ON sys.sysobjects.id = sys.syscomments.id
WHERE sys.syscomments.text LIKE '%BSA_InsSuspiciousActivity%'
--AND sys.sysobjects.type = 'P'
ORDER BY sys.sysobjects.NAME
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);
}
}
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);
}
}
用C# 執行command語法
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = ProgramPath;
p.StartInfo.WorkingDirectory = @"D:\";
p.StartInfo.Arguments = ProgramArguments + FilePath;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
//Log.WriteToLog("Info", "filename=" + p.StartInfo.FileName + ", Arguments=" + p.StartInfo.Arguments);
Log.WriteToLog("Info", "Added program to execute \"{0}\" argument \"{1}\".", p.StartInfo.FileName, p.StartInfo.Arguments);
p.Start();
using (StreamReader myStreamReader = p.StandardOutput)
{
string result = myStreamReader.ReadToEnd();
p.WaitForExit();
p.Close();
Log.WriteToLog("Info", "relation import finished!");
}
p.StartInfo.FileName = ProgramPath;
p.StartInfo.WorkingDirectory = @"D:\";
p.StartInfo.Arguments = ProgramArguments + FilePath;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
//Log.WriteToLog("Info", "filename=" + p.StartInfo.FileName + ", Arguments=" + p.StartInfo.Arguments);
Log.WriteToLog("Info", "Added program to execute \"{0}\" argument \"{1}\".", p.StartInfo.FileName, p.StartInfo.Arguments);
p.Start();
using (StreamReader myStreamReader = p.StandardOutput)
{
string result = myStreamReader.ReadToEnd();
p.WaitForExit();
p.Close();
Log.WriteToLog("Info", "relation import finished!");
}
訂閱:
文章 (Atom)