"Svein Erik" <Svein Erik@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();
>
>
> }
>
>