environment:
web: asp.net for c#
db: sql server 2008
IIS: 7.5
caramels 發表在 痞客邦 留言(0) 人氣(287)

自己寫的ADO.NET class
使用C#
還蠻實用的
操作與講解都寫在
caramels 發表在 痞客邦 留言(0) 人氣(590)
本方法使用AjaxPro2
Step1
在web.config裡加入
<system.web>
<httpHandlers>
<add verb="POST,GET" path="Ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
</system.web>
caramels 發表在 痞客邦 留言(0) 人氣(214)
using System.Reflection;
using System.ComponentModel;
PropertyInfo property = (typeof(控制項的類別)).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehList = (EventHandlerList)property.GetValue(控制項的ID, null);
此時ehList就如控制項裡base.Events的角色,可以讀取此控制項目前載入的事件
caramels 發表在 痞客邦 留言(0) 人氣(96)
1.使用CMD (不好用,且編譯在網站後無法使用)
using System.Diagnostics;
public string GetMac(string IP)
{
string str1 = String.Empty;
try
{
string str2 = string.Empty;
str2 = RunCmd("nbtstat -A " + IP);
if (str2.ToLower().IndexOf("mac address", 0) > -1)
{
str2 = str2.Trim();
str1 = str2.Substring(str2.ToLower().IndexOf("mac address", 0), 31);
str1 = str1.Remove(0, 14);
str1 = str1.ToUpper();
}
else
str1 = "";
}
catch
{
Response.Write("<Script>alert('抓不到')</Script>");
str1 = "";
}
return str1;
}
public string RunCmd(string command)
{
//實例一個Process類,啟動一個獨立進程
System.Diagnostics.Process p = new System.Diagnostics.Process();
string result = "";
//Process類有一個StartInfo屬性,這個是ProcessStartInfo類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:
p.StartInfo.FileName = "cmd.exe"; //設定程序名
p.StartInfo.Arguments = "/c " + command; //設定程式執行參數
p.StartInfo.UseShellExecute = false; //關閉Shell的使用
p.StartInfo.RedirectStandardInput = true; //重定向標準輸入
p.StartInfo.RedirectStandardOutput = true; //重定向標準輸出
p.StartInfo.RedirectStandardError = false; //重定向錯誤輸出
p.StartInfo.CreateNoWindow = true; //設置不顯示窗口
p.Start(); //啟動
//p.StandardInput.WriteLine(command); //也可以用這種方式輸入要執行的命令
//p.StandardInput.WriteLine("exit"); //不過要記得加上Exit要不然下一行程式執行的時候會當機
//p.WaitForExit(1);
//int Timeout=2;
//while( Timeout > 0 && !p.HasExited)
//{
// System.Threading.Thread.Sleep(1000);
// Timeout -= 1;
//}
try
{
result = p.StandardOutput.ReadToEnd();
}
catch
{
result = "";
}
if (!p.HasExited)
{
p.Kill();
}
//强制关闭进程->無法成功
//for (int i = 0; i < System.Diagnostics.Process.GetCurrentProcess().Modules.Count; i++)
//{
// if (System.Diagnostics.Process.GetCurrentProcess().Modules[i].FileName.ToLower().IndexOf("cmd", 0) > -1)
// {
// string exeName = System.Diagnostics.Process.GetCurrentProcess().Modules[i].FileName;
// string[] exeArray = exeName.Split('\\');
// RunCmd("taskkill /im " + exeArray[exeArray.Length - 1] + " /f ");
// }
//}
p.Dispose();
p.Close();
return result; //從輸出流取得命令執行結果
}
caramels 發表在 痞客邦 留言(0) 人氣(1,455)