How do I check whether a user is allowed to read / write a particular registry key?

前端 未结 6 580
清歌不尽
清歌不尽 2020-12-31 08:14

Does anybody know how I can programmatically check (using C#) whether my program will be able to read / write a particular registry key (specifically: \"SOFTWARE\\Microsoft\

6条回答
  •  不思量自难忘°
    2020-12-31 09:07

    Simplest option is to try and open the key with write access and see if you get it. Remember to close the key afterwards.

    bool fWriteAccess;
    try {
        Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).Close();
        fWriteAccess = True;
    } catch (SecurityException) {
        fWriteAccess = False;
    }
    

提交回复
热议问题