CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2004
    Posts
    30

    Smile how to execute an .exe in c#

    Hi,

    I'm a newbie to c#, i'm writing an app. in asp.net using C#. One of the things that i want to do is execute a command. In particular, there is a file on a network share that i want to execute, "somefile.exe" . How do i write code in C# to execute that file?

    Thanks

    Sharon

  2. #2
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762
    Process.Start("My.exe");

  3. #3
    Join Date
    Jan 2004
    Posts
    30
    Hi,

    Thanks for the response. I'm getting a server error message when I run the app,

    Code:
    "Logon failure: unknown user name or bad password"
    
    Exception Details: System.ComponentModel.Win32Exception: Logon failure: unknown user name or bad password
    I'm assuming since the file is on a network share, i'll need to authenticate myself when I try to execute the file. Can someone please tell me how to do this?

    Thanks

    Sharon

  4. #4
    Join Date
    Jul 2003
    Location
    Springfield
    Posts
    190
    if passing arguments to the process is what you need then maybe this example will help you:
    Code:
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
    
    namespace MyProcessSample
    {
        /// <summary>
        /// Shell for the sample.
        /// </summary>
        public class MyProcess
        {
           
            /// <summary>
            /// Opens the Internet Explorer application.
            /// </summary>
            public void OpenApplication(string myFavoritesPath)
            {
                // Start Internet Explorer. Defaults to the home page.
                Process.Start("IExplore.exe");
                        
                // Display the contents of the favorites folder in the browser.
                Process.Start(myFavoritesPath);
     
            }
            
            /// <summary>
            /// Opens urls and .html documents using Internet Explorer.
            /// </summary>
            public void OpenWithArguments()
            {
                // url's are not considered documents. They can only be opened
                // by passing them as arguments.
                Process.Start("IExplore.exe", "www.northwindtraders.com");
                
                // Start a Web page using a browser associated with .html and .asp files.
                Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
                Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
            }
            
            /// <summary>
            /// Uses the ProcessStartInfo class to start new processes, both in a minimized 
            /// mode.
            /// </summary>
            public void OpenWithStartInfo()
            {
                
                ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                
                Process.Start(startInfo);
                
                startInfo.Arguments = "www.northwindtraders.com";
                
                Process.Start(startInfo);
                
            }
    
            public static void Main()
            {
              // Get the path that stores favorite links.
              string myFavoritesPath = 
              Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
                    
              MyProcess myProcess = new MyProcess();
             
              myProcess.OpenApplication(myFavoritesPath);
              myProcess.OpenWithArguments();
              myProcess.OpenWithStartInfo();
            }    
        }
    }
    Mr. Burns

  5. #5
    Join Date
    Jan 2004
    Posts
    30
    Hi,

    Thanks for the response. But i'm looking for a way to authenticate the application when it goes and accesses a file using process.start method (since the file is on a windows share).
    The app. will be running on a network and it will require login name and password in order to access the file, which is why i'm receiving the server error message. i'm still stumped as how to do this as i'm looking at the StartInfo of the process class and the FileName property but it doesn't have fields to specify login and password to access file...

    Thanks in advance.

    Sharon

  6. #6
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    how about creating a connection to that network first, and then you can simply lauch that file... if a connection is created, no need to authenticate again...
    Regards,
    Alexei

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured