Groups | Blog | Home
all groups > dotnet security > august 2005 >

dotnet security : 'System.Security.SecurityException' when running .exe file from ot


Svein Erik
8/12/2005 5:32:05 AM
I've developed a small console application that gathers systeminformation
about the machine. I can run this from a shared network drive, and it works
fine. But when i implement 2 more functions that writes a key to the registry
and creates a desktop icon on the machine that runs the app, i get a
System.Security.SecurityException.
Any tips on how i can avoid this?
Here is the code that generates the error (i've found out that both the
registry-writing & the desktop creation generates the same error):

//Create registry entry
RegistryKey hku = Registry.Users;
RegistryKey numbers =
hku.OpenSubKey("S-1-5-21-985536280-989403192-929701000-1870");
RegistryKey software2 = numbers.OpenSubKey("Software");
RegistryKey microsoft2 = software2.OpenSubKey("Microsoft");
RegistryKey windows2 = microsoft2.OpenSubKey("Windows");
RegistryKey currVer = windows2.OpenSubKey("CurrentVersion");
RegistryKey internetSettings = currVer.OpenSubKey("Internet
Settings",true);

string regValue =
internetSettings.GetValue("ProxyOverride").ToString();
int exists = regValue.IndexOf(@"http://192.168.60.52");
//Om den ikkje finnes, legg den til i registeret
if( exists == -1 )
{
regValue += @";http://192.168.60.52";
internetSettings.SetValue("ProxyOverride", regValue);
internetSettings.Close();
}
else
{
internetSettings.Close();
}

//Create desktop shortcut:

IWshRuntimeLibrary.IWshShell_Class TheShell = new
IWshRuntimeLibrary.IWshShell_Class();
string desktopDir =
System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

IWshRuntimeLibrary.IWshShortcut_Class shellLink =
(IWshRuntimeLibrary.IWshShortcut_Class)TheShell.CreateShortcut(desktopDir +
@"\SYS-IKT - Helpdesk.lnk");
shellLink.TargetPath = @"http://192.168.60.52/helpdesk/";
shellLink.Save();


}

Nicole Calinoiu
8/13/2005 7:10:32 AM
See http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx for an
explanation of why this happens, as well as instructions for granting your
assembly the additional CAS permissions it needs.


[quoted text, click to view]

Svein Erik
8/15/2005 11:31:15 PM


[quoted text, click to view]

Thanks, i have infact read this article, but this program won't run on any
other computer..! The computers i've tried it on has Administrator rights,
but it throws the exception anyway.
I just made a script that xcopy the program from a network disk to the
clients c:\ and runs it from there, but the exception is thrown and i can't
Nicole Calinoiu
8/16/2005 7:29:06 AM
[quoted text, click to view]

Did you apply the CAS policy changes to every computer on which you want the
application to run? (The changes must be applied to each client computer,
not the server on which the assemblies happen to be stored.)


[quoted text, click to view]

User permissions do not override CAS permissions (or vice versa). If CAS
permissions are limiting your application's activities, you must address
this regardless of the Windows permissions granted to the user running the
applicaiton.


[quoted text, click to view]

Does this mean that the exception is still thrown when the assembly is run
from the local c:\ drive? If so, could you please specify exactly how you
are launching the application? If not, could you please explain exactly
under what conditions the exception is thrown or not thrown?

AddThis Social Bookmark Button