|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
InvalidOperations excetion running wsh with Process classWhen 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... 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. -- Show quoteHide quoteDave 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... 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(); .... -- Show quoteHide quotekevin... "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... > > > 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 :) -- Show quoteHide quoteDave Sexton "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... >> >> >>
Other interesting topics
Fast Case Insensitive String Comparisons
Capturing screenshot of a window How to properly check for NULL! Launch Application as Different User in C# Windows Applicatoin Visual Studio Plugin? Appropriate pattern Need Simple Example of Class Event Raising and Handling in Form GetHicon memory leak How to realize a C# page that give back an image instead of an html page Client Side Datase / MemoryTables |
|||||||||||||||||||||||