×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

我试了一下,好像可以啊,可能是我没理解问题。

private void Button1_Click(object sender, System.EventArgs e)
{
this.TextBox1.Text = TestConsole();
}

private string TestConsole()
{
Process p = new Process();
p.StartInfo.Arguments = "abc";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "e:\\MyConsoleApp.exe";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}

MyConsoleApp source code:
using System;

namespace MyConsoleApp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string ret = "hello ";
if (args.Length > 0)
ret += args[0];
Console.WriteLine(ret);
}
}
}

localhost 调试,默认 security。
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / .net高手看过来
    现在用asp.net开发网站,想用网页上的摁钮触发服务器上的可执行文件,执行文件转换功能。用到vb.net里执行可执行文件的新增功能process。
    但是这个可执行命令proecess.start("convert.exe","agument=xxx")只能在生成vb.net的windows application才能正常运行;在web application里,convert.exe在内存里呆一会就结束了,根本没用干他该干的事。执行其他的可执行文件如ping,cmd,dir就行,notepad,winword就挂在内存里没用任何反应。我该怎么办?
    xiexie
    • 有没有权限问题?转换可能涉及到文件读写吧
      • 转换是在服务器本地运行的,不会吧?
        • ^^^
          • help!!!
          • 哼哼不是dot net高手么
            • I'm not 高手 and I never got your problem yet. I'll try it later. I like to meet new problem.
              • 不许破坏俺们心目中的偶像形象
                • man, I can't get a position for myself. It's been six months. :-(
                  • 别泄气,你水平比我高,找工作是时间问题
                  • donot like talk like that. do not count month, it does not mean too much and 6 is still very small number. You know the current market.
                    • Thank you guys, 菠菜core and 天津の包子.
      • Please checking the rights for User: "ASPNET". Make sure this account has the proper previliages.
        • 好主意,多谢,去试试
        • I give the aspnet user the administrator previliages. But still fail. :<
    • The reason you can not see the gui of notepad and winword is because your webapp is running under different user other then the one you logged in. try this
      run Component Services under Control Panel\Administrative Tools, expand Component Services --> Computers -->My Computer --> COM+ Applications, find your web app, it should looks like IIS - {Default Web Site//Root/....} .Right click it,choose properties, then Identity tab, change Account to Interactive.

      after that, restart your IIS server and try again.
      • 高手呀,这种方法您是怎么知道的?总算不像以前在内存里跳一下就出来了,可是在内存里呆着,什么都不干。也许干了,没什么结果。如果换成notepad的话,就在内存里没反应。我的命令行打开了相应程序,但是没有进一步。
        • UP. I got the same outcoming.
        • show your code, the process part
          • no problem
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim myProcess As Process = New Process

            ' set the file name and the command line args
            myProcess.StartInfo.FileName = "notepad.exe"
            myProcess.StartInfo.Arguments = "e:\ew.txt"
            ' start the process in a window
            myProcess.StartInfo.WindowStyle = ProcessWindowStyle.normal
            myProcess.StartInfo.CreateNoWindow = False
            myProcess.Start()

            ' if the process doesn't complete within
            ' 600 seconds, kill it
            myProcess.WaitForExit(600000)
            If Not myProcess.HasExited Then
            myProcess.Kill()
            End If

            ' display exit time and exit code
            TextBox1.Text = myProcess.ExitCode
            TextBox2.Text = myProcess.ExitTime

            myProcess.Close()


            End Sub
            • the code seems OK. when you run it as a web app, can you see the gui?
              • I think it is correct too. The Notepad.exe only appears in memory ,no gui at all. Do you have experience to run windows application in asp.net?
                • 我没有试过直接在Asp.net的code里运行,我是用一个assembly来处理这些东东,然后asp或asp.net再调用该assembly。
      • under COM+Applications, I got
        IIS IN-Process Applications : right-click properties, identity is not available
        IIS Out-of-Process Applications :........................................, set to interactive user..

        This is the only one the Identity can be set to interavtive user.

        But I still didn't get Notepad UI.

        What's wrong?
        • up
          • check your Virtual Directory Properties, the Application Protection should choose High.
    • 救命!或者指教去什么地方问
      • I don't see there is anything to do with dotnet. call windows application from asp.net. That's shit! why not make your windows application windows service, and keep it in memory all the time?
        • :-)
          I searched on google. They guys wanna do same but failed. ASP.NET handled by IIS, Desktop is unreachable on this point.
          • It's true...... I can't believe it............
        • In fact tha application is only a command line the convert some data files. I think someone may need to trigger some executable file when they want to exchange some data into another file format.
          • I remind that my colleages once talked about that if you call unmanaged code from .net, there are some bothering security issues. error might be raised.
            • It doesn't matter. We can use other way to protect. But how to realize it is emergency
        • When you run any thing based on asp,the asp code will be using some windows application. If any mission is unavailable to the asp server, I have to make some windows application to work on it. No shit,there.
          • Actually I was in the same situation before. I have learned that's really a bad idea. I use a tool to make the windows application running as a windows service. It works great.
            • windows services has its own issues.
            • So you have experience about it. Could you tell me how? Thanks.
              • 1. Create a windows service application. 2. Call the command line file converting application from the windows service application.
                3. I suppose you generate some file in asp.net application to be converted. So listen to the file changes in the folder in your windows service application. When the windows service application learn there is a file created, call the command line application to do the work.

                Windows Service usually running in administrator account, so there is no security problem.
      • 贼心不死,接着顶
    • checking the convert.exe's source code, make sue catch the run time error exceptions. Then let's go back to solve it.
      • We buy a third party software. We don't have the source code. :(
        • Complain to them
        • It must be some exception when you run the convert in IIS. The problem is you can't catch the exception the process is raised
          when you want to run it. ask them for a new version that can give you the error message.
        • 虽然我不太同意MIKE老狼关于windows services 的观点,但他的解决方案(#1474110)还是很好的,你可以试试。
    • 我试了一下,好像可以啊,可能是我没理解问题。
      private void Button1_Click(object sender, System.EventArgs e)
      {
      this.TextBox1.Text = TestConsole();
      }

      private string TestConsole()
      {
      Process p = new Process();
      p.StartInfo.Arguments = "abc";
      p.StartInfo.UseShellExecute = false;
      p.StartInfo.RedirectStandardOutput = true;
      p.StartInfo.FileName = "e:\\MyConsoleApp.exe";
      p.Start();
      string output = p.StandardOutput.ReadToEnd();
      p.WaitForExit();
      return output;
      }

      MyConsoleApp source code:
      using System;

      namespace MyConsoleApp
      {
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main(string[] args)
      {
      string ret = "hello ";
      if (args.Length > 0)
      ret += args[0];
      Console.WriteLine(ret);
      }
      }
      }

      localhost 调试,默认 security。
      • 你这个情况有一点点不一样,最简单的就是用notepad试。
        • 启动 notepad 的 user account 是 ASPNET,所以看是肯定看不到的。但是不晓得是否真的执行完毕了。另外,搂主的转换程序一定要 UI 么?
          比如只有 cmd 就不干活,但可以这么用:
          private string TestConsole()
          {
          Process p = new Process();
          p.StartInfo.Arguments = "/c dir"; // !!
          p.StartInfo.UseShellExecute = false;
          p.EnableRaisingEvents = false;
          p.StartInfo.RedirectStandardOutput = true;
          // p.StartInfo.FileName = "e:\\MyConsoleApp.exe";
          p.StartInfo.FileName = "cmd.exe";
          p.Start();
          string output = p.StandardOutput.ReadToEnd();
          p.WaitForExit();
          return output;
          }
          • #1473554
          • 我这么试过,什么设置都不变,一点问题也没有。但这个转换程序非要打开一次ppt才行,把权限设置好前,连ppt都不能打开,现在可以了,但是就死在这一步了,其实也不用我在ppt里干什么,都应该是自动,也不知怎么就不动。
    • 用Impersonation
      就是说在执行那段代码的时候相当于把当前线程的拥有者模仿为另外一个有高权限的用户。
      • up
        • Up我干什么?
      • 在machine.config里那个?好像在某论坛被人否了
    • I guess it is because notepad need to read input from standard input(keyboard), so it will block there after you start it. Ping is not a interactive application, so it is OK.
      • no at all. 我现在就是什么都不用干,就是打开一下powerpoint,再关上,都是自动的,就不行
      • Why don't you use MS Office COM interface? It should work.
        • 高人,您说到点子上了,已经解决了
    • 解决方案,不看后悔,长知识呀
      本文发表在 rolia.net 枫下论坛To work around this, we should bind office applications with an interactive
      user account, please follow these steps:

      1. Log on to the computer as the Administrator and install (or reinstall)
      Office using a complete install. For system robustness, it is recommended
      that you copy the contents of the Office CD-ROM to a local drive and install
      Office from this location.
      2. Start the Office application that you intend to automate. This forces the
      application to register itself.
      3. After the application is running, press ALT+F11 to load the Microsoft
      Visual Basic for Applications (VBA) editor. This forces VBA to initialize
      itself.
      4. Close the applications, including VBA.
      5. Click Start, click Run, and then type DCOMCNFG. Select the application
      that you want to automate. The application names are listed below:

      Microsoft PowerPoint - Microsoft PowerPoint Presentation

      Click Properties to open the property dialog box for this application.

      6. Click the Security tab. Verify that Use Default Access Permissions and
      Use Default Launch Permissions are selected.
      7. Click the Identity tab and then select The Interactive User.
      8. Click OK to close the property dialog box and return to the main
      applications list dialog box.
      9. In the DCOM Configuration dialog box, click the Default Security tab.
      10. Click Edit Defaults for access permissions. Verify that the following
      users are listed in the access permissions, or add the users if they are not
      listed:
      SYSTEM
      INTERACTIVE
      Everyone
      Administrators
      IUSR_<machinename>*
      IWAM_<machinename>*

      * These accounts only exist if Internet Information Server (IIS) is
      installed on the computer.

      11. Make sure that each user is allowed access and click OK.
      12. Click Edit Defaults for launch permissions. Verify that the following
      users are listed in the launch permissions, or add the users if they are not
      listed:
      SYSTEM
      INTERACTIVE
      Everyone
      Administrators
      IUSR_<machinename>*
      IWAM_<machinename>*

      * These accounts exist only if IIS is installed on the computer.

      13. Make sure that each user is allowed access, and then click OK.
      14. Click OK to close DCOMCNFG.
      15. Start REGEDIT and verify that the following keys and string values exist
      for the Office application that you want to automate:

      Microsoft PowerPoint:
      Key: HKEY_CLASSES_ROOT\AppID\POWERPNT.EXE
      AppID: {64818D10-4F9B-11CF-86EA-00AA00B929E8}

      If these keys do not exist, please create it.

      16. Restart the system. This is required.

      After the reboot, PFCL should work!更多精彩文章及讨论,请光临枫下论坛 rolia.net
      • nice
        • 真不知道windows还有这么高级的应用,以前以为windows都知道的差不多了呢。这东西怎么学的?