方法1.(測試不可行,不知道原因)
try { dynamic shell = AutomationFactory.CreateObject("WScript.shell"); shell.Run(@"C:\Windows\system32\mspaint.exe"); //執行檔路徑 } catch (Exception ex) { Console.Write(ex.Message); }
方法2.(測試可行)
(步驟1) .aspx內,寫Javascript,使用ActiveX去開啟Client端的檔案。
<script language="javascript" type="text/javascript">
function runEXE(path) {
var WshShell = new ActiveXObject("Wscript.Shell");
WshShell.Run(path); // 執行檔案路徑
WshShell.Quit;
}
</script>
(步驟2) .cs內,呼叫html的Javascript Function並帶入路徑參數。
//第一個參數:Javascript Function Name, 第二個參數: Javascript Function的參數.
HtmlPage.Window.Invoke("runEXE", @"C:\Windows\system32\mspaint.exe");
方法2等於還是借助Javascript的ActiveXObject去實現使用者需求。不是Silverlight的功能,也不是.NET的功能。
文章標籤
全站熱搜