Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,312 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,532 people online right now. Registration is fast and FREE... Join Now!




run a .bat file

 
Reply to this topicStart new topic

run a .bat file

TADS
15 Oct, 2008 - 05:02 AM
Post #1

New D.I.C Head
Group Icon

Joined: 9 Aug, 2008
Posts: 20


My Contributions
im having problems running a .bat file from vb.net 2005 this is the code im using

CODE

Dim startInfo As System.Diagnostics.ProcessStartInfo
        Dim pStart As New System.Diagnostics.Process

        startInfo = New System.Diagnostics.ProcessStartInfo("C:\my.bat")

        pStart.StartInfo = startInfo
        pStart.Start(startInfo)
        pStart.WaitForExit()



now if i leave waitforexit in it errors if i comment it out a dos window will flash up and go again but it has not run my bat file...

this is what the error says in Details.. {"No process is associated with this object."}

not sure why this is

thanks for reading

Kev
User is offlineProfile CardPM
+Quote Post

TADS
RE: Run A .bat File
15 Oct, 2008 - 05:42 AM
Post #2

New D.I.C Head
Group Icon

Joined: 9 Aug, 2008
Posts: 20


My Contributions
i have tryed using

CODE


shell ("mydir\my.bat")


still wont run any .bat but runs any .exe
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Run A .bat File
15 Oct, 2008 - 05:59 AM
Post #3

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
vb

System.Diagnostics.Process.Start("notepad")


Make sure that you do not put the .exe at the end.
User is offlineProfile CardPM
+Quote Post

TADS
RE: Run A .bat File
15 Oct, 2008 - 06:49 AM
Post #4

New D.I.C Head
Group Icon

Joined: 9 Aug, 2008
Posts: 20


My Contributions
this will not work as it opens the .exe... i have an exe and a .bat in the same dir this is what is inside my .bat

mktex car000.tga car000.tex

then when i run the .bat it runs the exe with the above command so it converts my tga car template to a .tex to run in game (aslong as the car000.tga is in the same file!!

Kev
User is offlineProfile CardPM
+Quote Post

magicmonkey
RE: Run A .bat File
15 Oct, 2008 - 07:07 AM
Post #5

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 418



Thanked: 68 times
My Contributions
You are calling a shared/static member of process.start, the one you are calling returns a new process. Simply remove the startinfo parm from the .start.

vb

Dim startInfo As System.Diagnostics.ProcessStartInfo
Dim pStart As New System.Diagnostics.Process

startInfo = New System.Diagnostics.ProcessStartInfo("C:\my.bat")

pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit()

User is online!Profile CardPM
+Quote Post

TADS
RE: Run A .bat File
15 Oct, 2008 - 08:06 AM
Post #6

New D.I.C Head
Group Icon

Joined: 9 Aug, 2008
Posts: 20


My Contributions
thanks for replies but it still just flashes up and off again i have made a short video to help explain my problem

video link

Kev
User is offlineProfile CardPM
+Quote Post

magicmonkey
RE: Run A .bat File
15 Oct, 2008 - 10:12 AM
Post #7

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 418



Thanked: 68 times
My Contributions
vb

Dim pStart As New System.Diagnostics.Process
pStart.StartInfo.FileName = "C:\my.bat"
pStart.StartInfo.WorkingDirectory = "C:\" 'Set to where ever the files you want to convert are
pStart.Start()
pStart.WaitForExit()


My guess is that you need to change the working directory in the startinfo, the batch is not finding any files in the default working directory which is were the exe is compiled to.
User is online!Profile CardPM
+Quote Post

TADS
RE: Run A .bat File
15 Oct, 2008 - 10:42 AM
Post #8

New D.I.C Head
Group Icon

Joined: 9 Aug, 2008
Posts: 20


My Contributions
thanks for the reply..

i got it working just using "shell" i didnt do anything different it just started working smile.gif

but i will try what you just put as its m,ore vb.net way then vb

Kev




User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:52AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month