如何在没有.net的机器上运行C#程序?

dogdogdog 2002-12-19 07:01:39
我用C#编了个很简单的程序,使用了WebBrowser控件。
在安装了VS.net的机器上都可以运行。
但是在没有安装VS.net的机器上,即使安装了dotnetfx.exe也无法运行。
显示找不到AxInteropSHDoc文件。
可是dll就在同一个目录下啊。
请问该怎么办?
...全文
119 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
TheAres 2002-12-26
  • 打赏
  • 举报
回复
把全部的代码贴上来,或者发到cxli@qingdaonews.com,说不定会帮上什么忙.
dogdogdog 2002-12-26
  • 打赏
  • 举报
回复
全部代码如下:

//Main.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace WebClick
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtUrl;
private System.Windows.Forms.Label lblUrl;
private System.Windows.Forms.Label lblNumber;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.NumericUpDown numVisit;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public frmMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtUrl = new System.Windows.Forms.TextBox();
this.lblUrl = new System.Windows.Forms.Label();
this.numVisit = new System.Windows.Forms.NumericUpDown();
this.lblNumber = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numVisit)).BeginInit();
this.SuspendLayout();
//
// txtUrl
//
this.txtUrl.Location = new System.Drawing.Point(80, 40);
this.txtUrl.Name = "txtUrl";
this.txtUrl.Size = new System.Drawing.Size(312, 21);
this.txtUrl.TabIndex = 0;
this.txtUrl.Text = "";
//
// lblUrl
//
this.lblUrl.Location = new System.Drawing.Point(32, 40);
this.lblUrl.Name = "lblUrl";
this.lblUrl.Size = new System.Drawing.Size(32, 23);
this.lblUrl.TabIndex = 1;
this.lblUrl.Text = "Url";
//
// numVisit
//
this.numVisit.Location = new System.Drawing.Point(80, 96);
this.numVisit.Name = "numVisit";
this.numVisit.Size = new System.Drawing.Size(56, 21);
this.numVisit.TabIndex = 2;
//
// lblNumber
//
this.lblNumber.Location = new System.Drawing.Point(24, 96);
this.lblNumber.Name = "lblNumber";
this.lblNumber.Size = new System.Drawing.Size(48, 16);
this.lblNumber.TabIndex = 3;
this.lblNumber.Text = "Number";
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(304, 160);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 4;
this.btnOK.Text = "确定";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(408, 206);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnOK,
this.lblNumber,
this.numVisit,
this.lblUrl,
this.txtUrl});
this.Name = "frmMain";
this.Text = "设置";
this.Load += new System.EventHandler(this.frmMain_Load);
((System.ComponentModel.ISupportInitialize)(this.numVisit)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}

private void btnOK_Click(object sender, System.EventArgs e)
{
if(txtUrl.Text !="")
{
for(int i=0;i<numVisit.Value;i++)
VisitWeb(txtUrl.Text );
}
}


private void VisitWeb(string sUrl)
{
//建立一个线程访问网页
frmWeb frmweb=new frmWeb();
frmweb.Url =sUrl ;
ThreadStart myWeb=new ThreadStart(frmweb.Show);
Thread myVisit = new Thread(myWeb);
myVisit.Start();
}

private void frmMain_Load(object sender, System.EventArgs e)
{

}
}
}

//frmWeb:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//using System.Threading;

namespace WebClick
{
/// <summary>
/// frmWeb 的摘要说明。
/// </summary>
public class frmWeb : System.Windows.Forms.Form
{
private AxSHDocVw.AxWebBrowser axWebBrowser1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public string Url;

public frmWeb()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmWeb));
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
this.SuspendLayout();
//
// axWebBrowser1
//
this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(292, 266);
this.axWebBrowser1.TabIndex = 0;
//
// frmWeb
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.axWebBrowser1});
this.Name = "frmWeb";
this.Text = "frmWeb";
this.Load += new System.EventHandler(this.frmWeb_Load);
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
this.ResumeLayout(false);

}
#endregion

private void frmWeb_Load(object sender, System.EventArgs e)
{
Object refmissing = System.Reflection.Missing.Value;

axWebBrowser1.Navigate(Url,ref refmissing,ref refmissing,ref refmissing,ref refmissing);
}
}
}
yarshray 2002-12-25
  • 打赏
  • 举报
回复
http://www.aspcool.com/lanmu/browse1.asp?ID=995&bbsuser=csharp
dogdogdog 2002-12-25
  • 打赏
  • 举报
回复
确实在同一目录下
hfayga 2002-12-25
  • 打赏
  • 举报
回复
1.要看编译成的EXE的属性是不是中间语言,如果是,要安装Frame
2.要把引用的dll与EXE放在同一个目录(也可配置)
TheAres 2002-12-24
  • 打赏
  • 举报
回复
不需要.
你把bin目录下的文件dir一下,列上来,看看Interop.SHDocVw.dll和AxInterop.SHDocVw.dll是否在那个目录下.
dogdogdog 2002-12-23
  • 打赏
  • 举报
回复
dll和exe已经在同一个目录下了。

是否需要注册这两个dll?
TheAres 2002-12-21
  • 打赏
  • 举报
回复
要把.Net IDE将Com控件转换的那两个dll一起带上才可以,要和exe文件在一个目录.

关于这两个文件的作用和如何转换来的,看看微软中国上面的文章:
http://chs.gotdotnet.com/quickstart/winforms/doc/WinFormsAxHosting.aspx
echevil 2002-12-21
  • 打赏
  • 举报
回复
是一个COM控件吧,必须注册了才能用的。
echevil 2002-12-21
  • 打赏
  • 举报
回复
会不会是WebBrowser控件的问题?我怎么没见到这个控件?
NET程序员的开发利器.NET Reflector 一、 简介   程序集,作为.NET时代的动态链接库,蕴藏了太多的软件秘密。为此,Visual Studio内置的ILDASM成为最初挖掘程序集的上佳工具。但自从Reflector出现后,ILDASM相形见拙。因为,Reflector能提供更多的程序集信息,而且是免费的工具。   如今,在Visual Studio.NET中编译源代码(无论是VB还是C#)时,编译器都会将高级源代码翻译成MSIL,即“微软中间语言”,而不是特定的机器指令。具有更多安全性、版本控制、共享能力与其它相关元数据的中间语言(IL),是包在一个或多个DLL或可执行文件中的。   基于ILDASM检查程序集中的IL有时很有用,但它要求我们熟悉MSIL。通常,比起IL,大多数开发人员对像C#或Visual Basic这样的高级程序设计语言更为熟悉。   Reflector的出现使.NET程序员眼前豁然开朗,因为这个免费工具可以将.NET程序集中的中间语言反编译成C#或者Visual Basic代码。除了能将IL转换为C#或Visual Basic以外,Reflector还能够提供程序集中类及其成员的概要信息、提供查看程序集中IL的能力以及提供对第三方插件的支持。   二、 下载与运行Reflector   Reflector是由微软员工Lutz Roeder编写的免费程序。这个软件经常更新,你可以在http://www.aisto.com/roeder/dotnet下载最新的版本。在本文成文之时,Reflector的最新版本为5.0.35.0,仅有1M大小。只要双击下载后的Reflector.exe文件即可运行Reflector。   默认情况下,Reflector会打开一组公共程序集(mscorlib、System、System.Data、System.Drawing等等)。每个打开的程序集都列在Reflector的主窗口中。单击程序集旁边的+图标可以展开树结构并展示程序集的命名空间。每个命名空间旁边都有一个相关的+图标,单击这个图标将显示这个命名空间内的类。除此以外,还可以展开每个类,显示类的成员:事件、字段、方法与属性。   要想查看其它程序集(包括我们自己创建的程序集)的细节,你可以使用菜单命令“File→Open”。然后,浏览到想要查看的程序集。只要选择了有效的.NET程序集,这个程序集就可以在Reflector的主窗口中与其它默认程序集共同显示。要想从Reflector的主窗口中删除程序集,只需右击程序集并选择“Close”。   三、 使用Reflector反汇编程序集   提供基本的程序集是Reflector唾手可得的功能,然而,Reflector真正的威力体现在它的反汇编能力。只要浏览到类级的成员,就可以通过Tools菜单中的Disassembler项(或在该项上单击右键)反汇编此成员。这将打开第二个窗格,以C#、Visual Basic、Delphi或者IL显示反汇编后的内容。图2以C#语言展示了对SmtpClient类中Abort方法的反汇编结果。   有了Reflector的反编译功能,要研究.NET框架基类库就容易多了。我们完全可以在没有源代码的情况下研究我们所创建或者正在使用的程序集相应源代码。   不用太担心,你自己的.NET应用程序还有其它受保护措施。但是,想阻止别人查看.NET程序集的IL(继而反编译成C#或者Visual Basic)是不可能的,但你可以使用“混淆”技术使IL变得混乱。目前,市场上有许多.NET混淆产品,比如:PreEmptive Solution的Dotfuscator、WiseOwl的Dmeanor以及Remotesoft的.NET Obfuscator等。   四、 Reflecator的其它功能   除了作为对象浏览器与反汇编器之外,Reflector还可以显示类与其成员的调用与被调用图、提供单键访问Google或MSDN搜索的能力并提供了允许第三方开发人员为Reflector创建插件的框架。   要查看调用或被调用图,只需要在树视图中选择一个成员,访问Tools菜单,选择Call Graph或Callee Graph选项即可。Call Graph会列出所选项所调用的成员,而Callee Graph列出调用所选项的成员。   通过使用插件,Reflector的功能可以得到进一步扩展。目前有能显示程序集依赖图、自动加载当前运行中的程序集、输出整个程序集的反汇编内容以及在Visual Studio中作为Reflector的宿主等的插件。还有更多插件都列在http://www.codeplex.com/reflectoraddins中。在此,我极力推荐有兴趣的读者前去一看。   不出乎所料,的确存在一个Reflector.VisualStudio插件。有了这个插件,就可以让Reflector集成在Visual Studio环境中,进而取代以前那个有些“拙漏”的对象浏览器。   首先,我们需要在机器上准备Reflector的最新版,然后从http://www.testdriven.NET/reflector下载最新版本的Reflector.VisualStudio插件。据说安装了此插件之后,Reflector能够与Visual Studio完美融合。但遗憾的是,本人试下载此软件并安装(仅能得到TestDriven.NET-2.8.2130 RTM个人测试版本,时间7/30/2007,大小3.3M)后,没有大发现—仅是在VS2005中添加“Go to Reflector”和一个帮助菜单项。点击“Go to Reflector”菜单项仅是从VS2005内部启动Reflector而已。   有了Reflector.VisualStudio插件(正版,下面是根据在线资料介绍),Reflector可以寄在Visual Studio中Reflector不仅是一个对象浏览器、反汇编器,包裹在同一个程序中的所有功能还可以寄于Visual Studio中。   五、 小结   还记得Spy++吗?在Win32时代,这个软件对于我们分析一个陌生软件的设计思路可谓立下汗马功劳。在如今的.NET时代,Reflector又成为每个严肃的.NET开发人员工具箱中必不可少的精髓工具之一。怎么样,请赶紧试锋吧。

111,095

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧