0

I am sorry for my poor english. I need copy Embedded file in .exe to C:\ directory, this code working whose try to copy in D:. I think I need admin permissions. I tried to run my .exe as admin but It doesn't work. How to do this? Thanks for your replies!

private static void ExtractEmbeddedResource(string outputDir, string resourceLocation, List<string> files)
{
    foreach (string file in files)
    {
        using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceLocation + @"." + file))
        {
            using (System.IO.FileStream fileStream = new System.IO.FileStream(System.IO.Path.Combine(outputDir, file), System.IO.FileMode.Create))
            {
                for (int i = 0; i < stream.Length; i++)
                {
                    fileStream.WriteByte((byte)stream.ReadByte());
                }
                fileStream.Close();
            }
        }
    }
}
fconislla
  • 1
  • 2
  • Yes, writes into the root of C:\ require elevation so your app needs to be started with elevation (right click & *run as admin* or use a manifest) - or of course simply write somewhere else more appropriate where this restriction does not apply. – Alex K. Apr 02 '17 at 19:25
  • Thank you. I edited my question, as he tried running as administrator my .exe. Both have the same effect? Well I'll try what you say – fconislla Apr 02 '17 at 19:36
  • You really should try to avoid writing to the root directory in the first place. But assuming you must, the marked duplicate explains how to get admin rights. If admin rights don't solve your problem, then you have a configuration issue with your PC; the superuser.stackexchange.com site is a better choice for questions like that, as it has nothing to do with _programming_ per se. – Peter Duniho Apr 02 '17 at 19:53

0 Answers0