Hi Dw

Is it possible to disable the autorun or autoplay feature on windows using VB.NET, I want to disable this feature automatically if it is enabled on a computer.

Any suggestion is welcome.

Thank you.

I found this somewhere:
I am not sure whether this works or not? But you can give a try:

<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function RegisterWindowMessage( _
     ByVal lpString As String) As UInteger
    End Function
    Private Sub EventsController_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim MessageID As Integer
        MessageID = RegisterWindowMessage("QueryCancelAutoPlay")
    End Sub

You can use this link this is related with C#.net but later on you can use converter

also view this link (VB.Net)

I was able to research how to enable/disable autorun through registry.

This is how to navigate and to disable the Autorun in VB through registry:

Imports Microsoft.Win32

    Public Class Form1

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim regVersion As RegistryKey

            regVersion =
            Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", True)
            If regVersion Is Nothing Then
                ' Key doesn't exist; create it.
                regVersion =
            Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer")
            End If

            Dim intVersion As Integer = 0
            If (Not regVersion Is Nothing) Then
                intVersion = regVersion.GetValue("Version", 0)
                intVersion = intVersion + 255
                regVersion.SetValue("NoDriveTypeAutoRun", intVersion)
                regVersion.Close()
            End If
        End Sub
    End Class

Depending on whether you want to disable AutoRun for all users or just for the current one, navigate to either of these registry keys (the current code is for one user):
If you want for all users, you need to substitude these lines of code:

Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", True)
            Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer")

to:

Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", True)
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer")

If you want to enable AutoPlay, just change the line of code:

intVersion = intVersion + 255

to:

intVersion = intVersion + 145

After enabling/disabling autorun, restart the computer.

The only problem, is that I've faced an error that said:
Requested registry access is not allowed. But I hope you could find a way to create an Security Exception to access the registry.

Hope this helps.

Thanks but all the codes didn't disable the Autoplay (Autorun) I restarted the computer after executing the codes but when I plugged the USB it Autoplay it but if I do it manually and plugged the USB it doesn't play it automatically. The OS is Win7 that I'm using.

In the Registry did you change the Permission settings for the "Explorer" folder? Also, after disabling the AuutoRun from the VB program, go to the registry to the locaton where you've disabled the Autorun, and make sure that the Data for NoDriveTypeAutoRun is "0x000000ff (255)". This will tell you that AutoRun is disabled. Otherwise if it's "0x00000091 (145)" then AutoRun is still enabled.

Hold down the start button and press r. This will open the Run box. Type "regedit". This will open the Registry Editor. Then navigate to the folder "Explorer". Right click on it. You will see "Permissions...". From there on, you can follow this Video to change the permissions.

did you prefer those link that I said to you in previous comment,
I am not sure for code that I type as I never attain this type of project but yes, one of those link include solved thread...

if that don't help you:
Follow this link: HERE and also HERE

More info: Click Here (this link is not related with the vb.net, this describe how you can do it manually?, but this will help you if you know how to work with reg. in vb.net programmatically...
I suppose you know it...

Best of luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.