简体   繁体   中英

C# Error Access to the path 'C:\Windows\system32\Com\dmp' is denied When Windows Startup

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.

拒绝访问路径“ C:\\ Windows \\ system32 \\ Com \\ dmp”。

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]));
        }
    }

You should always run as an administrator.

Hope this helps link

And another one

授予对文件的访问权限,例如FileMode.Create,FileAccess.Write,FileShare。请不要尝试此操作,它可能会起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM