Thread: haElPPP =)

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    3

    haElPPP =)

    Heyy pplz:
    I'm kind of a beginner at C++ and could use soem help with a program I'm writing for fun =)
    ( MY REVISED PROGRAM AS A WINDOWS APPLICATION )
    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdlib.h>
    #include <tchar.h>
    #include <iomanip>
    #include <stdio.h>
    #include <time.h>
    #include <Winuser.h>
    
    #pragma comment(lib, "user32.lib")
    #pragma comment(lib, "advapi32.lib")
    
    using namespace std;
    
    BOOL MySystemShutdown()
    {
       HANDLE hToken; 
       TOKEN_PRIVILEGES tkp; 
     
       // Get a token for this process. 
     
       
       if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
          return( FALSE ); 
     
       // Get the LUID for the shutdown privilege. 
     
       
       LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
            &tkp.Privileges[0].Luid); 
     
       tkp.PrivilegeCount = 1;  // one privilege to set    
       tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     
       
       // Get the shutdown privilege for this process. 
     
       
       AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES)NULL, 0); 
     
       if (GetLastError() != ERROR_SUCCESS) 
          return FALSE; 
     
       // Shut down the system and force all applications to close. 
     
       if (!ExitWindowsEx(0x00000001 | 0x00000004, 
            0x00020000 |
    		0x00000003 |
    		0x80000000))
        return FALSE; 
    
       //shutdown was successful
       
       return TRUE;
    }

    My program is suppose to... Say things... And shut down someones computer unexpectedly. It is meant as a practical joke and does not do harm to another's machine.

    ( MY ORIGINAL PROGRAM AS A WINDOWS CONSOLE APPLICATION )
    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdlib.h>
    #include <tchar.h>
    #include <iomanip>
    #include <stdio.h>
    #include <time.h>
    #include <Winuser.h>
    
    #pragma comment(lib, "user32.lib")
    #pragma comment(lib, "advapi32.lib")
    
    using namespace std;
    
    
    int APIENTRY _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
    {
    
            cout << "\a\n";
    		Sleep(200);
    		cout << "\a\n";
    		Sleep(200);
    		cout << "\a\n";
    		Sleep(200);
    		cout << "Alert. A virus has been detected in netcfgx.dll                                   " << endl;
    		Sleep(1500);
    		system ("PAUSE");
    		cout << "Please wait while WINDOWS attempts to remove the file.                            " << endl;
            Sleep(3000);
    		system ("PAUSE");
    		cout << "ERROR CODE 1505. FILE IS IN USE.                                                \a" << endl;
    		Sleep(500);
    		system ("PAUSE");
    		cout << "WINDOWS requires a process to be ended in order to remove the file.               " << endl;
    		system ("PAUSE");
    		Sleep(3000);
    		cout << "Unable to end process. WINDOWS CANNOT TERMINATE A SYSTEM PROCESS                \a" << endl;
            system ("PAUSE");
    		cout << "WINDOWS must be shut down to prevent damage to critical SYSTEM files              " << endl;
    		system ("PAUSE");
    		cout << "Please exit all applications and save all work. Shutdown in one minute            " << endl;
    		system ("PAUSE");
    		ExitWindowsEx(0x00000008, 0x00010000);
    
    		return (0);
    
    }
    
    BOOL MySystemShutdown()
    {
       HANDLE hToken; 
       TOKEN_PRIVILEGES tkp; 
     
       // Get a token for this process. 
     
       
       if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
          return( FALSE ); 
     
       // Get the LUID for the shutdown privilege. 
     
       
       LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
            &tkp.Privileges[0].Luid); 
     
       tkp.PrivilegeCount = 1;  // one privilege to set    
       tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     
       
       // Get the shutdown privilege for this process. 
     
       
       AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES)NULL, 0); 
     
       if (GetLastError() != ERROR_SUCCESS) 
          return FALSE; 
     
       // Shut down the system and force all applications to close. 
     
       if (!ExitWindowsEx(0x00000001 | 0x00000004, 
            0x00020000 |
    		0x00000003 |
    		0x80000000))
        return FALSE; 
    
       //shutdown was successful
       
       return TRUE;
    }

    And, Yes. I'm a stupid high-school student who is trying to use C++ to shut down someone elses computer =DD


    Also I keep getting 2 socially unacceptable errors....

    Code:
    LIBCD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol _wWinMain@16
    and
    Code:
    Debug/Shutdown.exe : fatal error LNK1120: 1 unresolved externals
    Please help if u can )
    Last edited by spartan118; 02-24-2010 at 10:12 AM.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    3
    21 views and NO replies? :P

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    3

    Fixxed

    It was my code.
    Code:
    #include <windows.h>
    #include <stdlib.h>
    #include <tchar.h>
    #include <iomanip>
    #include <stdio.h>
    #include <time.h>
    #include <Winuser.h>
    #include <atlbase.h>
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
        TOKEN_PRIVILEGES NewState;
        LUID_AND_ATTRIBUTES luidattr;
        HANDLE hToken;
        LUID tmpLuid;
    
        DWORD dwVersion = GetVersion();
        if ( dwVersion < 0x80000000)
        {
            // Windows NT4/2000/XP
            HANDLE handleProcess=GetCurrentProcess();
    
            // get a token handle
            if (!OpenProcessToken (handleProcess,
                    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
                return 0;
    
            if (!LookupPrivilegeValue(0, SE_SHUTDOWN_NAME, &tmpLuid))
                return 0;
    
             NewState.PrivilegeCount = 1;
             luidattr.Luid=tmpLuid;
             luidattr.Attributes=SE_PRIVILEGE_ENABLED;
             NewState.Privileges[0]=luidattr;
    
             // set privilege level
             if (!AdjustTokenPrivileges(hToken, false,
                     &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0))
                 return 0;
    }
    
    
    	{
    		cout << "\a\n";
    		Sleep(200);
    		cout << "\a\n";
    		Sleep(200);
    		cout << "\a\n";
    		Sleep(200);
    		cout << "Alert. A virus has been detected in netcfgx.dll                                   " << endl;
    		system ("PAUSE");
    		cout << "Please wait while WINDOWS attempts to remove the file.                            " << endl;
            Sleep(3000);
    		cout << "ERROR CODE 1505. FILE IS IN USE.                                                \a" << endl;
    		Sleep(500);
    		system ("PAUSE");
    		cout << "WINDOWS requires a process to be ended in order to remove the file.               " << endl;
    		system ("PAUSE");
    		Sleep(3000);
    		cout << "Unable to end process. WINDOWS CANNOT TERMINATE A SYSTEM PROCESS                \a" << endl;
            system ("PAUSE");
    		cout << "WINDOWS must be shut down to prevent damage to critical SYSTEM files              " << endl;
    		system ("PAUSE");
    		cout << "Please exit all applications and save all work. Shutdown in one minute            " << endl;
    		DWORD dwReserve = 0;
    		ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE|EWX_POWEROFF, dwReserve);
    		return 0;
    	}
    
    
    }
    U can lock this post

Popular pages Recent additions subscribe to a feed