Diagnostics.Process starts exe's which raise SecurityException's

  • Thread starter Thread starter Willy Denoyette [MVP]
  • Start date Start date
W

Willy Denoyette [MVP]

Phil Mc said:
Hi Nicole
I am attempting to run target exe on the some server (same dir in
fact). That is to sat the first exe is running(scheduling program), and
it is attempting to start a second exe. The first app does not seem to
be raising any security exception, whereas the exe's started by this
app are causing problems.

The exe's are starting, but failing when an IO operations are
attempted.
thanks

Are both the exe's loaded from a local disk or from a network share?

Willy.
 
Phil Mc said:
Hi Willy,
Both exes are loaded from the same folder at present, on the win 2003
server.
thanks

I understand that, but the question is - do you run the code on the win 2003
server it is loaded from, or do you load the code from the server and run it
on another machine?
It looks like you are doing the latter, which obviously throws a
"FileIOPermission" security exception because (by default) code loaded from
non local storage has no FileIOPermission.

Willy.
 
Hi all
I have a small scheduling application that I have written which will be
running on a Windows 2003 server. This application is started at
different times by an 'autosys' job (though I am testing by
manually starting the app from the server, that is logging into the
server, and running).

This app depending on available resources (txt, xml data files), starts
simple exe console apps which load simple data feeds into an SQL db. In
this operation file IO operations are required (such as copying and
directory creation) by the scheduler app, and simple files resource
checks (FileExists(xxx.txt), are carried out by the simple console
apps. All works as expected when run from my workstation.

The problem I have is that the console apps raise IO security
exceptions when run on the server. That when I deploy the scheduler and
associated console apps, the console apps raise exceptions. These
simple console apps are started in my scheduler app by using the
System.Diagnostics.Process CLASS. The scheduler does not cause problems
although it carries much of the IO work (the app I start manually). The
app which are started by the scheduler are the ones causing all the
problems.

Code to start the process which run the console apps:

DateTime start = DateTime.Now;
try
{
// run the appropriate macro
System.Diagnostics.Process macro = new
System.Diagnostics.Process(); macro.StartInfo.FileName =
fp.MacroFilePathName;
macro.StartInfo.Arguments = this.feedProcessXMLDirprocess_" +
fp.FeedFileName + ".xml";
macro.StartInfo.Arguments += " " + fp.ProductionRun.ToString();
macro.StartInfo.CreateNoWindow = true;
macro.Start();
macro.WaitForExit(); //macro.WaitForExit(5000)
// keep track of all log files.
this.logs.Add(fp.LogFileDir + "\\" +
this.feedProcessXMLLogFileNameHeader + fp.LogFileName +
FeedProcess.dateToDirString(this.currentDate,fp.FeedFileDestinationDirFormat)
+ ".xml"); this.numMacros++;
}catch (Exception ex)


Exception raised by started console apps:
System.Security.SecurityException: Request for the permission of type
System.Sec
urity.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0,
Culture=neutra
l, PublicKeyToken=b77a5c561934e089 failed.
at
System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet
granted
Set, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permT
oken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken
permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
checkFrames, Int32
unrestrictedOverride)
at
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, S
tackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Path.GetFullPath(String path)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String
relativeUri)
at System.Xml.XmlTextReader..ctor(String url, XmlNameTable nt)
at System.Xml.XmlTextReader..ctor(String url)
at FeedProcessClassLibrary.FeedProcess.parseXML(String xmlFile)
at FeedProcessClassLibrary.FeedMacro..ctor(String
feedProcessXMLFilePath, Boo
lean production)
at TestMacro.TestMacro.Main(String[] args)

Sorry for such a long post, any help would be much appreciated.
 
From where are you attempting to load the target executable? (i.e.: What
does fp.MacroFilePathName return?)



Phil Mc said:
Hi all
I have a small scheduling application that I have written which will be
running on a Windows 2003 server. This application is started at
different times by an 'autosys' job (though I am testing by
manually starting the app from the server, that is logging into the
server, and running).

This app depending on available resources (txt, xml data files), starts
simple exe console apps which load simple data feeds into an SQL db. In
this operation file IO operations are required (such as copying and
directory creation) by the scheduler app, and simple files resource
checks (FileExists(xxx.txt), are carried out by the simple console
apps. All works as expected when run from my workstation.

The problem I have is that the console apps raise IO security
exceptions when run on the server. That when I deploy the scheduler and
associated console apps, the console apps raise exceptions. These
simple console apps are started in my scheduler app by using the
System.Diagnostics.Process CLASS. The scheduler does not cause problems
although it carries much of the IO work (the app I start manually). The
app which are started by the scheduler are the ones causing all the
problems.

Code to start the process which run the console apps:

DateTime start = DateTime.Now;
try
{
// run the appropriate macro
System.Diagnostics.Process macro = new
System.Diagnostics.Process(); macro.StartInfo.FileName =
fp.MacroFilePathName;
macro.StartInfo.Arguments = this.feedProcessXMLDirprocess_" +
fp.FeedFileName + ".xml";
macro.StartInfo.Arguments += " " + fp.ProductionRun.ToString();
macro.StartInfo.CreateNoWindow = true;
macro.Start();
macro.WaitForExit(); //macro.WaitForExit(5000)
// keep track of all log files.
this.logs.Add(fp.LogFileDir + "\\" +
this.feedProcessXMLLogFileNameHeader + fp.LogFileName +
FeedProcess.dateToDirString(this.currentDate,fp.FeedFileDestinationDirFormat)
+ ".xml"); this.numMacros++;
}catch (Exception ex)


Exception raised by started console apps:
System.Security.SecurityException: Request for the permission of type
System.Sec
urity.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0,
Culture=neutra
l, PublicKeyToken=b77a5c561934e089 failed.
at
System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet
granted
Set, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permT
oken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken
permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
checkFrames, Int32
unrestrictedOverride)
at
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, S
tackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Path.GetFullPath(String path)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String
relativeUri)
at System.Xml.XmlTextReader..ctor(String url, XmlNameTable nt)
at System.Xml.XmlTextReader..ctor(String url)
at FeedProcessClassLibrary.FeedProcess.parseXML(String xmlFile)
at FeedProcessClassLibrary.FeedMacro..ctor(String
feedProcessXMLFilePath, Boo
lean production)
at TestMacro.TestMacro.Main(String[] args)

Sorry for such a long post, any help would be much appreciated.
 
Hi Nicole
I am attempting to run target exe on the some server (same dir in
fact). That is to sat the first exe is running(scheduling program), and
it is attempting to start a second exe. The first app does not seem to
be raising any security exception, whereas the exe's started by this
app are causing problems.

The exe's are starting, but failing when an IO operations are
attempted.
thanks
 
Hi Willy,
Both exes are loaded from the same folder at present, on the win 2003
server.
thanks
 
If the "macro" assembly is being loaded from a local path on the same
machine*, is it possible that the machine's CAS policy has been altered so
that locally run assemblies are no longer automatically granted unrestricted
permissions? If you can't tell from examining the CAS policy yourself, it
would probably be a good idea to ask the machine administrator about this.


*This means not even a UNC path pointing to a share on the same machine, but
a strictly local path like "C:\SomeDirectory\SomeAssembly.exe".
 
Back
Top