Problems running console app from Winform

elmowatson

Member
Joined
Jun 5, 2007
Messages
17
Programming Experience
1-3
I'm trying to run an app (GacUtil) which is normally run through a console window, directly in my winforms app, but I keep getting the error:

"The system cannot find the file specified"

Here is the code:
Dim AppName = "gacutil"
Dim BaseOptions = " /i"
Dim oStartInfo As New ProcessStartInfo
Dim sFull As String
Dim sStartPath As String = Path.GetDirectoryName(TextBox1.Text)
oStartInfo.WorkingDirectory = Path.GetDirectoryName(TextBox1.Text)
sFull = AppName & BaseOptions & " " & Path.GetFileName(TextBox1.Text)
oStartInfo.FileName = sfull
Process.Start(oStartInfo)

In this case, the DLL is in C:\, and 'GacUtil' has been added to the Environment path variable.
I can put a break point on the next to the last last line, copy and past the output of the 'sfull' variable into a command prompt and it will run perfectly. (I've tried adding oStartInfo.UseShellExecute=False, removing the whole workingDirectory property line and just changing sFull so that it has the Startpath also, but I still get the error)

However, when I try it in the Winforms app I'm creating, I get the error. Any ideas?
Process.Start(oStartInfo)
 
Last edited:
Qualify the path to gacutil.exe.
 
tried that too - -
sfull ended up being: c:\gacutil.exe /i Dept_Search.dll

This is not making any sense to me, so I must be missing something really small...........any other ideas?
 
Is really your gacutil.exe placed in the root of C drive? Sounds misplaced to me.
 
no, but it should be able to be run anywhere, since it's in my Environment Path variable - -
If i open a command prompt, go to c:\, and run gacutil.exe, it runs fine, even though it's physically not there.
 
elmowatson said:
In that case you must not specify that that exe is in that place. For debugging you should call Environment.GetEnvironmentVariable("path") and verify that your process actually do have the necessary prerequisites set.

Something I missed in your code is that I see you place a lot of information in the placeholder for the executable path, ie the FileName can not be set to the sfull string where you have other options. Anything except the path to the exe must be set in Arguments property.
Also, do you understand the implications of UseShellExecute property? It sound to me that you have misinterpreted that help topic.
 
Actually, I do know the implications of UseShellExecute - if you set it to false, it's not used to find the executable, but set it to true, and it will be used that way.

when I set it to false (and gacutil is in the path variable), I've tried setting the arguments to "/i " & Textbox1.text (which is the full path and filename of the dll)
and I've set the appname to gactutil.exe

I did finally get it working, though, by explicitly setting the path in the working directory.

Do you know if there's a system shortcut for gacutil?
 
Do you know if there's a system shortcut for gacutil?
None that I know of, especially since that tools is not part of a default .Net installation, only the SDK has it. Also, it is not a very commonly used tool, regular deployment advice against it is most cases.
From what I understand it is possible to use a Setup Project and place the output in a special GAC folder there to achieve the effect, and that that more likely uses fusion.dll and not gacutil.exe to do this.
 
yeah I understand the use of Setup Projects, and I would do that, but take my word for it, this is not a full fledged app - it's a dll here and a dll there, kind of an 'outside the realm' type of deal. This is mainly for testing - I have an OpenFileDialog, choosing the dll. it's more for in the test environment

Thats' why I'm doing it this way.

If I had to build a setup project for each of these DLLs, it would be a real pain.
In the end, if I had multiple dlls that I have fully tested in the test environment, yes, I can see creating a setup project for all of them.
 
Back
Top