0

thanks because you has been come to this post. I have an error with my script, that log says:

Access to the path 'C:\Windows\system32\Com\dmp' is denied.

I want to set my application to windows startup, so when that computer client started, my software is automatically running. So i put this script on my Main Load.

    private void Main_Load(object sender, EventArgs e)
    {
        //Menjadikan software ke dalam Startup Windows, sehingga dapat berjalan ketika pc pertama kali dinyalakan
        RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        reg.SetValue("PR Reminder", Application.ExecutablePath.ToString());
        listMapel();
        bool notif = Properties.Settings.Default.Notification;
        if (notif == true)
        {
            checkExpired(); //Mengecek tanggal penyerahan dan pemberian
        } 

The result is work. But I'm getting an error like this.

Access to the path 'C:\Windows\system32\Com\dmp' is denied.

After explored more deeply, the center of the issue is the method listMapel(); where he was tasked to search for files ending in .db in the local directory.

I dont know why this method is got error. When i try to remove this method, my application running fine when startup. I think the problem is on system.io.

This is my listMapel(); method script

    public void listMapel()
    {
        comboListMapel.Items.Clear();
        string path = Directory.GetCurrentDirectory(); //Lokal direktori
        string[] files = Directory.GetFiles(path, "*.db", SearchOption.AllDirectories);
        foreach (string file in files)
        {
            nama = file.Split(".".ToCharArray()); //Hasil result yang ditampilkan Matapelajaran.db (Tapi dengan ini kita mengambil string sebelum .db
            comboListMapel.Items.Add(Path.GetFileName(nama[0]));
        }
    }
harryovers
  • 3,087
  • 2
  • 34
  • 56
Shin Ryu
  • 9
  • 6
  • Have you tried adding manifest and allowing the app to run as administrator? – M. Adeel Khalid Feb 24 '17 at 10:25
  • When i set this application run as administrator, this application does not appear at windows startup – Shin Ryu Feb 24 '17 at 10:26
  • Where is the executable located? My bet is that its located elsewhere but the way its called by the OS includes the working directory of that system folder. You should be able to specify the working directory somehow (similar to how you can with a shortcut) to the actual directory of the exe instead of that system directory which you don't have access to. This is on the assumption that your exe is located outside of that folder. IOW `GetCurrentDirectory` is the culprit. you can set current directory https://msdn.microsoft.com/en-us/library/system.io.directory.setcurrentdirectory(v=vs.110).aspx – pinkfloydx33 Feb 24 '17 at 11:37

2 Answers2

1

You should always run as an administrator.

Hope this helps link

And another one

Community
  • 1
  • 1
Murat Gündeş
  • 852
  • 2
  • 17
  • 31
0

Give the access to your file like FileMode.Create, FileAccess.Write, FileShare.None try this it will may work.

Govind Tupkar
  • 264
  • 2
  • 5