473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

System.Diagnostics.Process.Start

I'm using a queue to hold a series of strings that are complete command line
arguments to start the silent/unattended installation of various pieces of
software. Here is some sample code.

1 Dim myProcess as New Process
2 myProcess.EnableRaiseEvents = True
3 myProcess.StartInfo.Filename = myQ.Dequeue ' The string value in this
instance is "c:\windowsXP-KB824146-x86-ENU.exe /u /n /z"
4 Do Until (myProcess.HasExited = True)
5 Loop

6 AutoLogon() ' Sets various registry keys.
7 RunOnce() ' Sets some more registry keys.
8 Shell("shutdown.exe -r -f -t 05") ' Forces a reboot of the system in 5
seconds.

The problem is that on line 4 it throws an exception "No Process is
associated with this object".

The other problem is that if I take out the do loop entirely the .exe fires
off and begins installation but the program doesn't wait for it to finish.
It immediately move on to 6, 7, and worst of all 8. Then the system reboots
mid-installation.

Is there a good way to make the thing wait until the installation is done
before continuing on? I piddled with Process.ExitCode as well with no luck.
Thanks in advance. =)

Nov 20 '05 #1
5 8023
I don't see myProcess.Start() anywhere. Looks like that's what you need.
Would be good also to throw in some Sleep() call inside loop.

HTH
Alex

"Ty Moffett" <tm******@solarc.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
I'm using a queue to hold a series of strings that are complete command line arguments to start the silent/unattended installation of various pieces of
software. Here is some sample code.

1 Dim myProcess as New Process
2 myProcess.EnableRaiseEvents = True
3 myProcess.StartInfo.Filename = myQ.Dequeue ' The string value in this
instance is "c:\windowsXP-KB824146-x86-ENU.exe /u /n /z"
4 Do Until (myProcess.HasExited = True)
5 Loop

6 AutoLogon() ' Sets various registry keys.
7 RunOnce() ' Sets some more registry keys.
8 Shell("shutdown.exe -r -f -t 05") ' Forces a reboot of the system in 5 seconds.

The problem is that on line 4 it throws an exception "No Process is
associated with this object".

The other problem is that if I take out the do loop entirely the .exe fires off and begins installation but the program doesn't wait for it to finish.
It immediately move on to 6, 7, and worst of all 8. Then the system reboots mid-installation.

Is there a good way to make the thing wait until the installation is done
before continuing on? I piddled with Process.ExitCode as well with no luck.

Thanks in advance. =)

Nov 20 '05 #2
Hi Ty,

Still going for it. ;-)

If you have the filename and the arguments mixed,
myProcess.StartInfo.Filename = myQ.Dequeue

where it's "c:\windowsXP-KB824146-x86-ENU.exe /u /n /z",
it will look for a file called
"windowsXP-KB824146-x86-ENU.exe /u /n /z"
which it won't find, of course.

You need to separate the args out and have
myProcess.StartInfo.Filename = <just the file path>
myProcess.StartInfo.Arguments = <the arguments>

(as well as the Process.Start that Alex mentioned).

Regards,
Fergus
Nov 20 '05 #3
In article <eN**************@TK2MSFTNGP12.phx.gbl>, Ty Moffett wrote:
I'm using a queue to hold a series of strings that are complete command line
arguments to start the silent/unattended installation of various pieces of
software. Here is some sample code.

1 Dim myProcess as New Process
2 myProcess.EnableRaiseEvents = True
3 myProcess.StartInfo.Filename = myQ.Dequeue ' The string value in this
instance is "c:\windowsXP-KB824146-x86-ENU.exe /u /n /z"
4 Do Until (myProcess.HasExited = True)
5 Loop

6 AutoLogon() ' Sets various registry keys.
7 RunOnce() ' Sets some more registry keys.
8 Shell("shutdown.exe -r -f -t 05") ' Forces a reboot of the system in 5
seconds.

The problem is that on line 4 it throws an exception "No Process is
associated with this object".

The other problem is that if I take out the do loop entirely the .exe fires
off and begins installation but the program doesn't wait for it to finish.
It immediately move on to 6, 7, and worst of all 8. Then the system reboots
mid-installation.

Is there a good way to make the thing wait until the installation is done
before continuing on? I piddled with Process.ExitCode as well with no luck.
Thanks in advance. =)


Here is a stupid little example....

Option Strict On
Option Explicit On

Imports System.Collections
Imports System.Diagnostics

Module Module1

Private Class Command
Public Sub New(ByVal cmd As String, ByVal args As String)
Me.cmd = cmd
Me.args = args
End Sub

Public cmd As String
Public args As String
End Class

Sub Main()
Dim cmds() As Command = {New Command("cmd", "/c dir c:\windows
/p"), New Command("cmd", "/k echo hello, world")}
Dim q As New Queue(cmds)
Dim cmd As Command
Dim p As Process

Do While q.Count > 0
cmd = DirectCast(q.Dequeue(), Command)
p = Process.Start(cmd.cmd, cmd.args)
p.WaitForExit()
Loop
End Sub

End Module

HTH
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #4
Thank you both Gentlemen. I'll take yor advise and see what I can do.
Thanks again!

"Fergus Cooney" <fi*****@post.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Ty,

Still going for it. ;-)

If you have the filename and the arguments mixed,
myProcess.StartInfo.Filename = myQ.Dequeue

where it's "c:\windowsXP-KB824146-x86-ENU.exe /u /n /z",
it will look for a file called
"windowsXP-KB824146-x86-ENU.exe /u /n /z"
which it won't find, of course.

You need to separate the args out and have
myProcess.StartInfo.Filename = <just the file path>
myProcess.StartInfo.Arguments = <the arguments>

(as well as the Process.Start that Alex mentioned).

Regards,
Fergus

Nov 20 '05 #5
Ok, I'm now trying to use enumerator to put what is still in my queue into
the streamwriter so i can write it back to disk. I'm confused...this error
makes no sense to me. I'm sure I'm doing something dumb.

Do While myQ.GetEnumerator.MoveNext

sw = myQ.GetEnumerator.Current 'This line gets an exception: Enumeration
has not started. Call MoveNext.

Loop
Here is the main() code without the subroutines.

' Run the program

' read the first command from the queue

' run the command

' remove the item from the queue

' set automatic login information

' reboot

' rerun the program until the queue is empty

Module HandsOff

Public Sub main()

Dim fs As New FileStream("c:\HandsOff.txt", FileMode.OpenOrCreate,
FileAccess.ReadWrite)

Dim sr As New StreamReader(fs)

Dim sw As New StreamWriter(fs)

Dim line As String

line = sr.ReadLine()

Dim myQ As New Queue

Do Until line = Nothing

myQ.Enqueue(line)

line = sr.ReadLine

Loop

' Displays the properties and values of the Queue.

Console.WriteLine("myQ")

Console.WriteLine(ControlChars.Tab + "Count: {0}", myQ.Count)

Console.Write(ControlChars.Tab + "Values:")

PrintValues(myQ)

If myQ.Count > 0 Then

Dim myProcess As New Process

myProcess.EnableRaisingEvents = True

myProcess.StartInfo.FileName = myQ.Dequeue

myProcess.StartInfo.Arguments = myQ.Dequeue

'Write the remaining Queue members to the text file.

Do While myQ.GetEnumerator.MoveNext

sw = myQ.GetEnumerator.Current

Loop

'Start the process.

myProcess.Start()

Do Until (myProcess.HasExited = True)

Loop

'Registry hacks to enable automatic logon upon reboot

AutoLogon()

'Registry hacks to enable this program to start upon logon.

RunOnce()

'Reboot the computer.

Shell("shutdown.exe -r -f -t 05")

End If

'Registry hacks to disable automatic logon upon reboot.

UndoAutoLogon()

End Sub


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: toby | last post by:
Can any one help? I'm trying to use System.Diagnostics.Process.Start to open legacy MS access aplications (ade and mdb files) and vb 6 .exe's using asp.net. There is something confusing going on?!?...
0
by: Daniel Reber | last post by:
I am trying to start a process from a windows service but when the process starts the command window that the process runs in never shows. Is this because I am calling it from a windows service? ...
1
by: ginee lee via .NET 247 | last post by:
(Type your message here) hi all, It seems that the arguments of System.Diagnostics.Process.Start()can only be the absolute path. The args can not be like".\abc\efg.exe" or "..\abc\efg.exe". While i...
2
by: andreas | last post by:
hi, In windows xp in the start launch menu when i put notepad "c:\test.txt" i get notepad with test.txt in it. in vb.net when i state system.diagnostics.process.start("notepad.exe" i get...
0
by: Daniel | last post by:
System.Diagnostics.Process.Start fails on windows server 2003 the process returns process.ExitCode == 0 but executing any process with System.Diagnostics.Process.Start on windows xp works fine....
1
by: Daniel | last post by:
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific...
0
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to...
0
by: Colin Williams | last post by:
I am using the code below to map network drive and then fire up an app in a sub dir of that drive. However when using the file open dialog from that app, drive K: appears just as Network drive K:...
6
by: kimiraikkonen | last post by:
Hello, I want to ask this: If i do: System.Diagnostics.Process.Start("c:\lame", "--preset standard c:\blabla.wav c:\blabla.mp3") it works. But i don't want this. I want my 2 textboxes must...
3
KodeKrazy
by: KodeKrazy | last post by:
I can use System.Diagnostics.Process.Start to launch .txt, .bmp, .jpg, etc., but if I try to launch an .exe, from the same folder, I get the "The system cannot find the file specified." error. For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.