Home All Groups Group Topic Archive Search About

InvalidOperations excetion running wsh with Process class

Author
12 Dec 2006 8:29 PM
kevin
When launching a wsh file (.js) I get a windows dialog box asking if I want
to run the script (which I have to address manually) and then the error "No
process is associated with this object" (InvalidOperationException) is
thrown. 

The script, by the way, runs as expected.

How do I handle this?
--
kevin...

Author
13 Dec 2006 1:06 PM
Dave Sexton
Hi Kevin,

The following works fine for me (XP SP2):

Process.Start("wscript", @"c:\test.js");

You should post your code if that doesn't help.

--
Dave Sexton

Show quoteHide quote
"kevin" <ke***@discussions.microsoft.com> wrote in message
news:EBFBCDFD-14CF-46DB-8B7C-438B8901040E@microsoft.com...
> When launching a wsh file (.js) I get a windows dialog box asking if I
> want
> to run the script (which I have to address manually) and then the error
> "No
> process is associated with this object" (InvalidOperationException) is
> thrown.
>
> The script, by the way, runs as expected.
>
> How do I handle this?
> --
> kevin...
Are all your drivers up to date? click for free checkup

Author
13 Dec 2006 1:49 PM
kevin
My code is not written to specifically run WSH files.  It executes any passed
file, assuming that the file association already exists in windows.  I have
verified that js and vbs are associated with cscript and wscript in Windows. 

I probably need to determine the associated exe and pass it as the process.

....
Process p = new Process();
p.StartInfo.FileName = processName; //i.e. c:\myfolder\myscript.js
p.StartInfo.WindowStyle = windowStyle;
p.StartInfo.Arguments = scriptArgs; //i.e. c:\myfolder\output.txt c:\myfolder
p.Start();
....

--
kevin...


Show quoteHide quote
"Dave Sexton" wrote:

> Hi Kevin,
>
> The following works fine for me (XP SP2):
>
> Process.Start("wscript", @"c:\test.js");
>
> You should post your code if that doesn't help.
>
> --
> Dave Sexton
>
> "kevin" <ke***@discussions.microsoft.com> wrote in message
> news:EBFBCDFD-14CF-46DB-8B7C-438B8901040E@microsoft.com...
> > When launching a wsh file (.js) I get a windows dialog box asking if I
> > want
> > to run the script (which I have to address manually) and then the error
> > "No
> > process is associated with this object" (InvalidOperationException) is
> > thrown.
> >
> > The script, by the way, runs as expected.
> >
> > How do I handle this?
> > --
> > kevin...
>
>
>
Author
13 Dec 2006 2:04 PM
Dave Sexton
Hi Kevin,

You could just assume that the computer has not modified the default
associations:

string ext = Path.GetExtension(processName);

if (ext != null && ((ext = ext.ToLower()) == ".js" || ext == ".vbs"))
{
    scriptArgs = "\"" + processName + "\" " + scriptArgs;
    processName = "wscript";
}

After that you can just use your code below.

I'll admit that's not ideal but given that your other option is to search
the registry for the file mappings instead, it sounds a little better :)

--
Dave Sexton

Show quoteHide quote
"kevin" <ke***@discussions.microsoft.com> wrote in message
news:B76C7764-3D89-4753-AE10-E1AE69D8CD3C@microsoft.com...
> My code is not written to specifically run WSH files.  It executes any
> passed
> file, assuming that the file association already exists in windows.  I
> have
> verified that js and vbs are associated with cscript and wscript in
> Windows.
>
> I probably need to determine the associated exe and pass it as the
> process.
>
> ...
> Process p = new Process();
> p.StartInfo.FileName = processName; //i.e. c:\myfolder\myscript.js
> p.StartInfo.WindowStyle = windowStyle;
> p.StartInfo.Arguments = scriptArgs; //i.e. c:\myfolder\output.txt
> c:\myfolder
> p.Start();
> ...
>
> --
> kevin...
>
>
> "Dave Sexton" wrote:
>
>> Hi Kevin,
>>
>> The following works fine for me (XP SP2):
>>
>> Process.Start("wscript", @"c:\test.js");
>>
>> You should post your code if that doesn't help.
>>
>> --
>> Dave Sexton
>>
>> "kevin" <ke***@discussions.microsoft.com> wrote in message
>> news:EBFBCDFD-14CF-46DB-8B7C-438B8901040E@microsoft.com...
>> > When launching a wsh file (.js) I get a windows dialog box asking if I
>> > want
>> > to run the script (which I have to address manually) and then the error
>> > "No
>> > process is associated with this object" (InvalidOperationException) is
>> > thrown.
>> >
>> > The script, by the way, runs as expected.
>> >
>> > How do I handle this?
>> > --
>> > kevin...
>>
>>
>>

Bookmark and Share