VB.Net Shell() function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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 said:
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 said:
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
 
I know just the things to get you started

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms01232003.asp
http://www.yoda.arachsys.com/csharp/threads/winforms.shtml

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


Henning said:
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
:

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 said:
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
 
Back
Top