asp.net 调用本地程序 调用执行exe应用程序

来源:互联网 发布:软件在线升级 编辑:程序博客网 时间:2024/05/18 03:13

asp.net 调用本地程序 调用执行exe应用程序

在asp.net中执行应用程序有两种方法,面分别用这两种方法执行Windows中的记事本程序notepad.exe:
1、调用win32函数ShellExecute。

调用win32函数ShellExecute。

添加引用Imports System.Runtime.InteropServices

声明函数:

<DllImport("shell32.dll")> _
Private Shared Function ShellExecute(hwnd As IntPtr, lpOperation As String, lpFile As String, lpParameters As String, lpDirectory As String, nShowCmd As Int32) As IntPtr
End Function

 

调用:

ShellExecute(IntPtr.Zero, "open", "c:/windows/notepad.exe", Nothing, Nothing, 1)

 


2、用.NET Framework中的Process类。

 

添加引用

Imports System.Diagnostics

 

调用:

Dim process As New Process()process.StartInfo.FileName = "c:/windows/notepad.exe"  '注意文件名必须加后缀。            process.Start()

 

=============================================

注意:在asp.net2.0中运行以上两种方法写的程序都可以得到想要的结果。但是在asp.net1.1或更早的版本却不能得到想要的结果

============================================


这是微软为了安全原因禁掉了程序的运行,你需要做以下两步才能正常运行:
1、在桌面右键单击:我的电脑--管理--服务和应用程序--服务--IIS Admin--属性--登陆--本地系统帐户-选“允许与桌面交互”--确定
重新启动“IIS Admin”服务。
2、打开目录“C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/CONFIG”中的machine.config文件,
找到“processModel”项,原来这项中有一个属性是userName="machine",将machine改为“system”,保存文件。