|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
'System.Security.SecurityException' when running .exe file from otabout 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(); } 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. Show quoteHide quote "Svein Erik" <Svein E***@discussions.microsoft.com> wrote in message news:84274DCE-B92E-447B-8ACB-F015FA821A7B@microsoft.com... > 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" wrote: Thanks, i have infact read this article, but this program won't run on any > 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. 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 figure out why.
Show quote
Hide quote
"Svein Erik" <SveinE***@discussions.microsoft.com> wrote in message Did you apply the CAS policy changes to every computer on which you want the news:C53C1B90-3FD7-4BE0-9896-79F0D2730CAF@microsoft.com... > > > "Nicole Calinoiu" wrote: > >> 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. > > Thanks, i have infact read this article, but this program won't run on > any > other computer..! application to run? (The changes must be applied to each client computer, not the server on which the assemblies happen to be stored.) > The computers i've tried it on has Administrator rights, User permissions do not override CAS permissions (or vice versa). If CAS > but it throws the exception anyway. permissions are limiting your application's activities, you must address this regardless of the Windows permissions granted to the user running the applicaiton. > I just made a script that xcopy the program from a network disk to the Does this mean that the exception is still thrown when the assembly is run > clients c:\ and runs it from there, but the exception is thrown and i > can't > figure out why. 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?
Can't determine if a file exists
X509 digital certificate for offline solution MD5 or SHA1 or ??? How to send certificate for client authentication? IIS Delegation String to byte[] & back using Base64 Create an Event Log on a Least Privilege User Account Extra '\0' chars after decryption CAS Permission Sets asp.net err |
|||||||||||||||||||||||