نوشته شده توسط
ghasem110deh
سلام به همه :)
دوستان این مشکل دسترسی و access denied برنامه بعد از نصب در درایو ویندوز رو چجوری از طریق خود برنامه رفع و رجوع کنیم !!؟
که بعد از نصب کاربر نخواد بره یکی ، یکی دسترسی و ... رو ویرایش کنه
من الان کانکشن رو از طریق یه فایل تکست میخونم (چون ممکنه تغییر کنه) ولی بعد از نصب خطای دسترسی میده "access denied" و دیتابیس رو پیدا نمیکنه ، در صورتی که با همین کانکشن (که فعلا لوکال هست) روی دو تا سیستم دیگه جب میده (که مشکل دسترسی ندارن)
به احتما زیاد مشکل شما با این کد حل بشه ، کدهای کلاس program پروژه تون رو به این شکل بنویسین :
static class Program
{
static bool IsRunAsAdmin()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(id);
return principal.IsInRole(WindowsBuiltInRole.Administrato r);
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
if (Environment.OSVersion.Version.Major >= 6)
{
if (!IsRunAsAdmin())
{
ProcessStartInfo proc = new ProcessStartInfo();
proc.UseShellExecute = true;
proc.WorkingDirectory = Environment.CurrentDirectory;
proc.FileName = Application.ExecutablePath;
proc.Verb = "runas";
try
{
Process.Start(proc);
}
catch
{
// The user refused the elevation.
// Do nothing and return directly ...
return;
}
Application.Exit(); // Quit itself
}
else
{
Application.Run(new frmMain());
}
}
else
{
Application.Run(new frmMain());
}
}
}