ASP.NET 使用 WScript.Shell 執行命令 (Client)

<%@ Page Language="VB" AutoEventWireup="true" ValidateRequest="false" AspCompat="true" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>範例內容 Client WScript.Shell 對象</title>
</head>
<body>
<form id="form1" runat="server">
<hr />
<table border="3" cellpadding="2" cellspacing="0" width="90%">
<tr>
<td align="center" bgcolor="#000046">
<font color="#FF0000">範例內容 Client WScript.Shell 對象</font>
</td>
</tr>
<tr>
<td width="100%">
試著點選下列命令:
<p style="text-indent: 24; margin-left: 20; margin-right: 20">
<a href="ShellRun://開啟您電腦中的檔案總管" onclick="return ShellRun(1);">開啟檔案總管</a></p>
<p style="text-indent: 24; margin-left: 20; margin-right: 20">
<a href="ShellRun://開啟記事本" onclick="return ShellRun(2);">開啟記事本</a>載入 C:.bat</p>
<p style="text-indent: 24; margin-left: 20; margin-right: 20">
<a href="ShellRun://開啟 DOS 視窗" onclick="return ShellRun(3);">開啟 DOS 視窗</a>顯示環境變數</p>
<p style="text-indent: 24; margin-left: 20; margin-right: 20">
</td>
</tr>

<script language="VBScript">
<!--
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

Function ShellRun(ByVal ind)
Select Case ind
Case 1
WshShell.Run "explorer"
Case 2
WshShell.Run "notepad.exe c:\autoexec.bat"
Case 3
WshShell.Run "command /k Set"
End Select

ShellRun = False ' 抑制載入標準超連結

End Function
-->
</script>

</table>
</form>
</body>
</html>

相關資源 : http://www.microsoft.com/taiwan/technet/scriptcenter/resources/qanda/oct05/hey1031.mspx

沒有留言: