Click here to Skip to main content
15,898,649 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I want to disable autorun for flash with C#.

I write the following code:
C#
string root = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\IniFileMapping\\Autorun.inf";

RegistryKey Rkey1 = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true); 
RegistryKey Rkey2 = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true); RegistryKey RKey3 = Registry.LocalMachine.OpenSubKey(root, true);

Rkey1.SetValue("NoDriveTypeAutoRun", 255);
Rkey2.SetValue("NoDriveTypeAutoRun", 255);
disable RKey3.SetValue("", "@SYS:DoesNotExist");

This code works on my PC, but it doesn't work on laptop. Two setValue commands works and third setValue doesn't work on laptop.

Please help me!
Posted
Updated 3-May-12 19:46pm
v2
Comments
Sergey Alexandrovich Kryukov 4-May-12 1:32am    
I have somewhat limited access to your laptop in May... :-)
How can anyone figure out your problem without knowing what OS versions do you use?
--SA
maryam ak 4-May-12 1:36am    
they have same version

1 solution

test your key before you use it.
C#
const bool PermissionToWriteToRegistry = true;
key = Registry.CurrentUser.OpenSubKey(RootKey, PermissionToWriteToRegistry);
// If the return value is null, the key doesn't exist
if (key == null)
{
 // The key doesn't exist; create it / open it
 key = Registry.CurrentUser.CreateSubKey(RootKey);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900