现在有一些程序是B/S和C/S混合的,在winform里也可以方便的嵌入web,vs2003和vs2005都提供了这样的控件。
而还有一种需求,在web上启动你的winform程序,比较常见的是qq,下载工具等。
笨一点的做法,是通过客户端js来启动。这样做有安全隐患,因此window后面版本的操作系统,严格限制了js的权限。
研究qq的实现方式,发现非常简单。看下面的注册文件:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Test]
@="Test"
"URL
Protocol"="应用程序路径%l"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Test\DefaultIcon]
@="%SystemRoot%\\system32\\url.dll,0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Test\Shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Test\Shell\open]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Test\Shell\open\command]
@="应用程序路径
%l"
你可以直接将它保存为一个reg文件然后注册,或者在你的应用程序安装时直接修改注册表。
在你的网页上加一个这样的链接:
<A href='Test://para1¶2¶3'>
如果你点这个链接,你在注册文件里的应用程序就可以被启动了。
还有一个需求,一般从网页启动应用需要传递参数(上面链接后面带了三个参数),做法如下:
你的应用程序主函数要这样接收参数:
static void Main(string[] args)
{
if(args.Length>0)
{
//存参数
}
}
通过args[index]就可以访问到你传递的参数了。
<script>
function exec (command) {
window.oldOnError =
window.onerror;
window._command = command;
window.onerror = function (err) {
if (err.indexOf('utomation') !=
-1) {
alert('命令' + window._command + ' 已经被用户禁止!');
return
true;
}
else return false;
};
var wsh = new
ActiveXObject('WScript.Shell');
if (wsh)
wsh.Run(command);
window.onerror = window.oldOnError;
}
</script>
<input type=button onclick="exec('NOTEPAD')"
value="调用本地程序-记事本"><br/>
<input type=button
onclick="exec('regedit')" value="调用本地程序-注册表"><br/>
<input
type=button onclick="exec('explorer')"
value="调用本地程序-我的文档"><br/>
<input type=button
onclick="exec('calc')" value="调用本地程序-计算器"><br/>
<input
type=button onclick="exec('cleanmgr')"
value="调用本地程序-清理磁盘"><br/>
<input type=button
onclick="exec('cliconfg')"
value="调用本地程序-客户端网络实用工具"><br/>
<input type=button
onclick="exec('cmd')" value="调用本地程序-DOS窗口"><br/>
<input
type=button onclick="exec('cmstp')"
value="调用本地程序-连接管理器配置文件"><br/>
<input type=button
onclick="exec('control')" value="调用本地程序-控制面板"><br/>
<input
type=button onclick="exec('cys')"
value="调用本地程序-配置服务向导"><br/>
<input type=button
onclick="exec('ddeshare')" value="调用本地程序-共享程序"><br/>
<input
type=button onclick="exec('dvdplay')"
value="调用本地程序-MidelPlay播放器"><br/>
<input type=button
onclick="exec('dxdiag')" value="调用本地程序-DirectX"><br/>
<input
type=button onclick="exec('licmgr')"
value="调用本地程序-终端服务器授权"><br/>
<input type=button
onclick="exec('mmc')" value="调用本地程序-控制台"><br/>
<input
type=button onclick="exec('mobsync')"
value="调用本地程序-要同步的项目"><br/>
<input type=button
onclick="exec('msconfig')"
value="调用本地程序-系统配置实用程序"><br/>
<input type=button
onclick="exec('mspaint')" value="调用本地程序-画板工具"><br/>
<input
type=button onclick="exec('msppcnfg')"
value="调用本地程序-PossPort管理器管理"><br/>
<input type=button
onclick="exec('mstsc')" value="调用本地程序-远程桌面连接"><br/>
<input
type=button onclick="exec('nlbmgr')"
value="调用本地程序-网络负荷平衡管理器"><br/>
<input type=button
onclick="exec('msppcnfg')"
value="调用本地程序-PossPort管理器管理"><br/>
<input type=button
onclick="exec('nslookup')" value="调用本地程序-DNS查询"><br/>
<input
type=button onclick="exec('odbcad32')"
value="调用本地程序-ODBC数据管理器"><br/>
<input type=button
onclick="exec('packager')"
value="调用本地程序-对象包装程序"><br/>
<input type=button
onclick="exec('rasphone')" value="调用本地程序-网络连接"><br/>
<input
type=button onclick="exec('rtcshare')"
value="调用本地程序-共享会话"><br/>
<input type=button
onclick="exec('syskey')"
value="调用本地程序-Windos账户安全"><br/>
<input type=button
onclick="exec('taskmgr')"
value="调用本地程序-Windos任务管理器"><br/>
<input type=button
onclick="exec('winchat')" value="调用本地程序-聊天"><br/>