VB.Net Shell() function
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Henning Kristensen (VIP)
Hello,

I am in dire need of help!

My problem is a follows:
The application MUST run from a share on a server (done by adding the
assembly strongname with Full Trust to the LocalIntranetZone of the
Machine)...

The application lists a bunch of files that I must be able to execute...
The file-types are of types *.vbs (I have to execute them by calling the
Shell function with cscript //NoLogo \\server\share\folder\script.vbs for
these to work.
Other file type is a custom (associated to run using a wsf script (can be
called by filename from anywhere on my machine), thus allowing me to double
click on these files on my machine and they run), lets call this filetype
*.ABC

My problems with the Shell function are as follows, in very much prioritized
order (I need to have the first issue solved!):
- I cannot make the shell work when any paths have spaces in it, and I need
to call it like this:
C:\Program Files\[full path]\script.wsf \\server\share\folder name\[full
path]\script.ABC
Thus I need to use shell to call the .wsf script in a folderpath that
contains spaces, the script should be called with a server-share path as
parameter, this parameter path can also contain spaces.
So far I have tried putting anywhere between 1 and 5 " around different
parts of the two paths, but nothing has worked yet.

- Shell can not find the .wsf script, when called with just scriptname.

- Shell can not execute the *.ABC file, without giving the .ABC file as a
parameter to the .wsf script, even though the .ABC filetype is associated to
run by using the wsf script.

- Shell can not execute the *.VBS files without calling cscript giving the
..vbs file as a parameter.

Any assistance with this will be deeply appreciated

Reply to this message...
 
    
saurabh
1) You can use the GetShortPathName API from kernel32 to get the short form
of the path. this short form of the path will be without spaces.

--Saurabh

"Henning Kristensen" <Click here to reveal e-mail address> wrote in
message news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Sijin Joseph
Take a look at the Process class, it is more powerful than Shell and
allows a lot of customization.

Look at the Process.Start() method and the ProcessStartInfo class.
Specifically check out the ProcessStartInfo.UseShellExecute and
ProcessStartInfo.Verb properties.

Let me know if you get stuck somewhere.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Henning Kristensen wrote:
[Original message clipped]

Reply to this message...
 
    
Henning Kristensen (VIP)
Thank you very much, that did much of the trick :o)

I now can get the .ABC files to run by just passing the path to them like:
Dim obj as new Process
obj.start("\\server\share\folder\script.ABC")

One question:
How can I now when the process has exited ?? (eg. I tried to do a while not
obj.HasExited, but that fails with "No process is associated with this
object.")

"Sijin Joseph" wrote:

[Original message clipped]

Reply to this message...
 
    
Sijin Joseph
You can use Process.WaitForExit() method to wait till the process has
termintated.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Henning Kristensen wrote:
[Original message clipped]

Reply to this message...
 
    
Henning Kristensen (VIP)
Thank you very much :o)

I actually found out about this shortly after I wrote, but your assistance
has been invaluable and deeply appreciated!

My code went from:
dim index as integer
index = Shell(path, AppWinStyle.Normal, True)

To:
Dim ShellProcess as new Process

Try
ShellProcess.StartInfo.FileName = path
ShellProcess.StartInfo.UseShellExecute = True
ShellProcess.Start()
ShellProcess.WaitForExit()
Catch....
Finally
ShellProcess.Dispose()
End Try

I works like a charm...
Now all I need to figure out is how to thread this process, in such a way
that I can make updates to my GUI while waiting for the process to exit.

Thank you for your help :o)
Kind regards
Henning
"Sijin Joseph" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Diagnostics.Process
System.Diagnostics.ProcessStartInfo




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com