Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wanna invoke cmd file from dll.I know it is possible. can anyone tell me the code. am using Visual studio 2008
Posted
Comments
Richard MacCutchan 27-Jan-13 9:07am    
So you are using Visual studio 2008, but what computer language are you using?
bharath_ben 27-Jan-13 11:01am    
visual basic!

1 solution

The Process Class has properties that you can set. Review documentation to see if you want to set any of them.
Imports System.Diagnostics


Dim myProcess As New Process
Try
    myProcess.StartInfo.FileName = Environment.GetFolderPath( _
        Environment.SpecialFolder.System) & _
        "\cmd.exe"
    myProcess.Start()
Catch ex As Exception
    MsgBox(String.Concat(ex.Message, vbNewLine, vbNewLine, _
         "Unable to Start: cmd.exe"), _
         MsgBoxStyle.Critical, "Starting CMD.EXE")
End Try
 
Share this answer
 
v7
Comments
bharath_ben 27-Jan-13 11:19am    
It doesnt work! Am using visual studio 2008 and my project in VB!
Mike Meinz 27-Jan-13 12:12pm    
Please explain in more detail.
Do you get an error message when you run your program? if so, what?
Do you get a compile error? If so, what?

I added "Imports System.Diagnostics" to the Solution in case you hadn't looked at the Visual Basic Help to determine that you needed to import that namespace.
bharath_ben 27-Jan-13 19:15pm    
try doesnt work.. and declaration expected for myProcess.
Mike Meinz 27-Jan-13 19:21pm    
Your statement doesn't fully answer my questions. I'll offer some more suggestions here.

This is the declaration for myProcess:
Dim myProcess As New Process

Just in case, cmd.exe is not in the program search PATH on your computer, change the statement that sets the filename to this line of code:
myProcess.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) & "\cmd.exe"

Have you included the following?
Imports System.Diagnostics

Post your code so I can see what it looks like.
I have been using that code since VB .NET 2003 up to and including VB .NET 2012.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900