vcant Posted September 15, 2003 Posted September 15, 2003 anyone know how do i execute an external program from VS.NET code (VB.NET, C#).
b0r3d Posted September 15, 2003 Posted September 15, 2003 In VB.NET it's really rather simple.Shell("C:\cat.txt")or to run a system command:shell("regedit")Good luck with your programming!
fwm Posted October 25, 2003 Posted October 25, 2003 C#Process.Start("app.exe");Remember to use the System.Diagnostics namespace for it to work, or else justSystem.Diagnostics.Process.Start("app.exe");That goes for VB.NET also, which is prefered instead of the Shell action, because the other way gives you much more control, and you can set specific actions for your execution!
antcheah Posted November 3, 2003 Posted November 3, 2003 Man i just wanna thanx you guys...have been looking for a way to execute defragmenter with vb.netbeen looking for weeks... now i knowShell("defrag C:")is that simple...to execure a programps: do you guys know how to execure a program from a specific directory?antcheah
b0r3d Posted November 4, 2003 Posted November 4, 2003 the same way will work. Just put the path in there.shell("C:\program\program.exe")
antcheah Posted November 9, 2003 Posted November 9, 2003 How about assigning a variable ???likeDIM X as string = "defrag C:"X = """ & X & """shell(X)it does not seem to work if i set a variable to assign a value to the shelli would have to type hard code it for it to work...any alternative?ps: if assign X to a label would get"defrag C:"antcheah
IceBoxQS Posted November 24, 2003 Posted November 24, 2003 I hope someone can help.I am trying to do about the same thing but I can't get the exe file to work if I put any switches after it.For example:shell("netstat.exe -ano > c:\temp.txt")This just flashes the command window and I get no output file on my c drive.I have also tried: shell("netstat.exe -ano > ""c:\temp.txt""")I tried this because in the help section they say the path can be lost if you don't double quote the path. Anyhow it didn't help any.I've tried a number of other methods like tossing the string in a variable like the guy above and then putting the variable in the shell function. But that doesn't work either.The only way I can get it to work is if I use:shell("netstat.exe")I have also tried these different ways using Process.StartAnd putting the switches in for the arguements. Anyhow that is where I'm at and I'm just spinning my wheels currently. Does anyone know how to get the switches to work after an exe in vb .net? Update:Well I still haven't figured out how to do it in VB.net. But I can call on a batch file from vb.net, which then fires: netstat -ano > c:\netstat.txtIt worked that way but that is round about and ugly. Anyone have something more sound? Please!
will_orangerocket Posted November 26, 2003 Posted November 26, 2003 Folks, don't use Shell in .NET. Use what has already been suggested, Process.Start. I couldn't even get Shell to work in my build of Visual Studio for whatever reason but Process.Start worked great. Obviously, Microsoft wants us to get away from the Shell command. I'm more than happy to oblige.
siwik75 Posted December 10, 2003 Posted December 10, 2003 Usefull infos! But I have a question:let's assume you want to run telnet toward a serverand send over commands and retrieve the output produced.Is there a way to accomplish this task?thank you all and have worthy developing!Simone ITALY
fwm Posted December 17, 2003 Posted December 17, 2003 How about assigning a variable ???likeDIM X as string = "defrag C:"X = """ & X & """shell(X)it does not seem to work if i set a variable to assign a value to the shelli would have to type hard code it for it to work...any alternative?ps: if assign X to a label would get"defrag C:"antcheahAs I said, you should use the System.Diagnostics namespace, and the class Process will take care of that for you.Like an example:using System.Diagnostics;private void startProcess(string Path, string fileName){Process install = new Process();install.StartInfo.WorkingDirectory = path;install.StartInfo.FileName = fileName;install.Start();}And then in your code you execute like this:startProcess("C:\", "file.exe");Above was just to show the options, you could do it like this:Process.Start("C:\file.exe");You see the potential?
fwm Posted December 17, 2003 Posted December 17, 2003 Folks, don't use Shell in .NET. Use what has already been suggested, Process.Start. I couldn't even get Shell to work in my build of Visual Studio for whatever reason but Process.Start worked great. Obviously, Microsoft wants us to get away from the Shell command. I'm more than happy to oblige.That's probably because you tried in C#, the Shell command is VB(.NET) only!
/\/\o\/\/ Posted December 15, 2004 Posted December 15, 2004 ls,below an example with redirection and parameters(arguments)the output streams are redirected to a string that you can use in your program.gr /\/\o\/\/PS. for a batch file the trick is to use the FOR command to get the uotput from a vbscript to a variable for /f %%i in ('cscript //nologo bin\GetFysicalNode.vbs %source%') do set Server=%%i--------------------------------------------- Dim objProcess As New Process()' Start the Command and redirect the output objProcess.StartInfo.UseShellExecute = False objProcess.StartInfo.RedirectStandardOutput = True objProcess.StartInfo.CreateNoWindow = True objProcess.StartInfo.RedirectStandardError = True objProcess.StartInfo.FileName() = "Cluster" objProcess.StartInfo.Arguments() = "/Cluster:" & strMachineName & " res /priv" objProcess.Start() strOutput = objProcess.StandardOutput.ReadToEnd() strError = objProcess.StandardError.ReadToEnd() objProcess.WaitForExit()
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now