Results 1 to 6 of 6

Thread: How do I call a program ? Create Button

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    How do I call a program ? Create Button

    I am trying to write a program to browse to a WSP file and then run the STSADM to make it easier to add solutions to our sharepoint site. The STSADMN is located in c:\program files\common files\microsoft shared\web server extensions\14\bin\stsadmn.exe.

    So I need to point to this EXE and run this command:

    Code:
    stsadm -o addsolution -filename "filename that was selected"
    This currently has to run in powershell.

    After that completes I need it to run this:

    HTML Code:
    stsadm -o deploysolution -name "selected WSP" -url http://sharepoint -allowgacdeployment -immediate
    I am just not sure how to call powershell and then run this command. and of course a messagebox.show "Completed". All I have right now is a form that browses to a WSP

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog fDialog = new OpenFileDialog();
                fDialog.Title = "Open WSP File";
                fDialog.Filter = "WSP Files|*.wsp";
                fDialog.InitialDirectory = @"C:\";
                if(fDialog.ShowDialog() == DialogResult.OK) 
                {
    
                MessageBox.Show(fDialog.FileName.ToString());
    
                }
    
    
    
    
            }
        }
    }
    Any help appreciated while I'm a noob at C# but loving it!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do I call a program ? Create Button

    To execute a file you call Process.Start. When executing a program with commandline argument, you must separate the file name and the commandline arguments into two Strings. You can call Process.Start and simply pass those two Strings or, if you need more control, create a ProcessStartInfo object and configure it as required before passing it to Process.Start.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: How do I call a program ? Create Button

    can you give me an example from what I want from above? I need to call powershell, then run two different commands and I do NOT want to see a powershell window. I just want a messagebox showing me it completed. I have tried this code but the notepad doesn't work.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //Browse WSP
                OpenFileDialog fDialog = new OpenFileDialog();
                fDialog.Title = "Open WSP File";
                fDialog.Filter = "WSP Files|*.wsp";
                fDialog.InitialDirectory = @"C:\";
                if(fDialog.ShowDialog() == DialogResult.OK) 
                {
                //Dialog Box
                MessageBox.Show(fDialog.FileName.ToString());
    
                }
    
    
    
    
            }
    
            class ProcessStart
                {
    
                static void Main(string[] args)
                {
                Process notePad = new Process();
                notePad.StartInfo.FileName   = "notepad.exe";
                 notePad.StartInfo.Arguments = "ProcessStart.cs";
    
                 notePad.Start();
    }
    
    
    
    
            }
        }
    }
    It says I have more than one entry point defined?
    Last edited by sentinelace; Mar 7th, 2012 at 04:57 PM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: How do I call a program ? Create Button

    bump

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: How do I call a program ? Create Button

    I am able to call poweshell but now do I prompt and say "Enter WSP file name", then excute the stsadm command?

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    namespace callprogram
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = "powershell.exe";
                p.Start();
                p.WaitForExit();
                string output = p.StandardOutput.ReadToEnd();
                return;
     
            }
        }
    }

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: How do I call a program ? Create Button

    It seems I need to write the commands in a PS1 script and then call the script. Maybe that would be easier?

    A powershell script like this:

    Code:
    Add-SPSolution c:\bin\CustomerSiteSearch.wsp
    Install-SPSolution -Identity CustomerSiteSearch.wsp -AllWebApplications -GACDeployment
    Enable-SPFeature CustomerSiteSearch_feature1 -url http://sharepoint/ –force
    But even if I call this script, it needs to use the string WSP that is selected. Ideas?
    Last edited by sentinelace; Mar 28th, 2012 at 10:51 AM.

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