SecurityException in Console Application on GetCommandLineArgs()

J

jwgoerlich

I wrote a simple VB.Net console application. It accepts command line
parameters and creates a folder structure. It works on the local file
system without a problem

If I run the console app from a UNC or network share, I get a
SecurityException on the following line:

Dim args() As String = Environment.GetCommandLineArgs()

Has anyone seen this before? Is there something special I need to do
for console applications on UNC paths?

Thanks in advance,
J Wolfgang Goerlich


Here is the complete exception text:

System.Security.SecurityException
System.Security.SecurityException: Request for the permission of type
System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed.
at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken
permToken, CodeAccessPermission demand, StackCrawlMark& stackMark,
Int32 checkFrames, Int32 unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Environment.GetCommandLineArgs()
at VerifyFolder.Module1.Main() in C:\Documents and
Settings\jwgoerlich\My Documents\Visual Studio
Projects\VerifyFolder\Module1.vb:line 12
 
M

Mattias Sjögren

Dim args() As String = Environment.GetCommandLineArgs()

Has anyone seen this before? Is there something special I need to do
for console applications on UNC paths?

I suggest you get the command line args as parameters to your Main
method instead:

Shared Sub Main(ByVal CmdArgs() As String)



Mattias
 
J

jwgoerlich

Shared Sub Main(ByVal CmdArgs() As String)

Thank you, Mattias. While I cannot create sub main as shared in the
Console module, your solution works otherwise. That is one big step
forward.

The next problem is that I am getting a SecurityException when I go to
access the remote file system. I am going over a UNC path using the
domain Administrator account. I have verified that this account is a
member of the BUILTIN\Administrators on the computer I am accessing,
and that it has full share and NTFS rights. My console app works if I
copy it to that computer and run it locally. Unfortunately, I must run
it over UNC.

Can you give me some pointers on this one, too? Do .Net console
applications typically not perform well over UNC?

J Wolfgang Goerlich


Here is the complete exception text:

System.Security.SecurityException
System.Security.SecurityException: Request for the permission of type
System.Security.Permissions.FileIOPermission, mscorlib,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed.
at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken
permToken, CodeAccessPermission demand, StackCrawlMark& stackMark,
Int32 checkFrames, Int32 unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Directory.InternalCreateDirectory(String fullPath,
String path)
at System.IO.Directory.CreateDirectory(String path)
at VerifyFolder.Module1.Main(String[] args)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top