C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 14th, 2007, 10:29 PM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Exclamation General - C++ browse HELP

string b;
cout<<" Enter Your Search Here"<<endl;
cin>>b;
call "C:\Program Files\Internet Explorer\iexplore.exe" "b"


so i saw something like this in a bat file.. and i am making a command shell.. and id like to add a browse command.. so i need help reforming this to fit into my program... ty

Reply With Quote
  #2  
Old August 15th, 2007, 03:18 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
You can try the 'system' function. Depending on which OS you are using there are other non-portable possibilities. If you are looking at .bat files, that probably means windows where you could also use the ShellExecute or CreateProcess winapi functions.

Good luck
__________________
There is no such thing as C/C++, you either program C or C++

Reply With Quote
  #3  
Old August 15th, 2007, 01:57 PM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
but

Quote:
Originally Posted by Icon
You can try the 'system' function. Depending on which OS you are using there are other non-portable possibilities. If you are looking at .bat files, that probably means windows where you could also use the ShellExecute or CreateProcess winapi functions.

Good luck

yes but im makein that to go into a shell... and i need to the user cn typin... browse w w w. g o o g l e . c o m so where the address is i want the user to input


the address is spaced out cause im a new user and cant use urls...

Reply With Quote
  #4  
Old August 15th, 2007, 03:56 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
So your own program is a command shell right? So you can read user input by using cin or something like that and when the user types 'browse www.google.com' you want to start internet explorer (or default browser) and make it go to that webpage, right? If so, you can use shellexecute, which will open it in default browser, or createprocess. Both accept the same command line parameters as in from shell. You can find out how they work exactly on microsofts msdn website, or google

Reply With Quote
  #5  
Old August 15th, 2007, 11:46 PM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Quote:
Originally Posted by Icon
So your own program is a command shell right? So you can read user input by using cin or something like that and when the user types 'browse www.google.com' you want to start internet explorer (or default browser) and make it go to that webpage, right? If so, you can use shellexecute, which will open it in default browser, or createprocess. Both accept the same command line parameters as in from shell. You can find out how they work exactly on microsofts msdn website, or google
right.. ty

Reply With Quote
  #6  
Old August 16th, 2007, 01:49 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
To open with default browser it would be something like this:
ShellExecute(NULL, "open", "http://google.com", NULL, NULL, SW_SHOWNORMAL);

You'll have to include shellapi.h.

http://msdn2.microsoft.com/en-us/library/ms647732.aspx

Reply With Quote
  #7  
Old August 20th, 2007, 01:06 AM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Quote:
Originally Posted by Icon
To open with default browser it would be something like this:
ShellExecute(NULL, "open", "http://google.com", NULL, NULL, SW_SHOWNORMAL);

You'll have to include shellapi.h.

http://msdn2.microsoft.com/en-us/library/ms647732.aspx

cant get it to work please write a simple code where the user types in w w w . g o o g l e . c o m and it goes to the url...ty

Reply With Quote
  #8  
Old August 20th, 2007, 05:46 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
cpp Code:
Original - cpp Code
  1.         else if(command == "browse")
  2.         {
  3.             string b;
  4.             cout<<" Enter Your Search Here"<<endl;
  5.             cin>>b;
  6. //      call "C:\Program Files\Internet Explorer\iexplore.exe" "b"
  7.             ShellExecuteA(NULL, "open", b.c_str(), NULL, NULL, SW_SHOWNORMAL);
  8.  
  9.         }


You have to add
cpp Code:
Original - cpp Code
  1. #include <windows.h>
  2.  

to your includes. You might want to prepend b with "http://" if it does not have that already.

Good luck

Reply With Quote
  #9  
Old August 20th, 2007, 05:47 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
The above code will open the link in your default browser, which is not necessarily internet explorer. It could be a cool browser like Opera If you really want to open IE than you should use something else.

Reply With Quote
  #10  
Old August 20th, 2007, 09:14 AM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Quote:
Originally Posted by Icon
The above code will open the link in your default browser, which is not necessarily internet explorer. It could be a cool browser like Opera If you really want to open IE than you should use something else.

wow kool thanks

Reply With Quote
  #11  
Old August 20th, 2007, 09:19 AM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
#include <shellapi.h>


creates problems in vc++ pro.. for somereason 150 errors when i keep it and 1 when i getrid. but the one error is cant recognize shellexecute..so im guessing thats shellapi.h is important.

Reply With Quote
  #12  
Old August 20th, 2007, 09:45 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
Yes I noticed the same problem. Using #include <windows.h> did not give me this problem however. Did you try that?

Reply With Quote
  #13  
Old August 20th, 2007, 09:47 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
windows.h is a big header file though.. You can try to #define WIN32_LEAN_AND_MEAN. ShellExecute is not really a portable solution, I do not know if that is a problem for you?

Reply With Quote
  #14  
Old August 21st, 2007, 01:02 AM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Quote:
Originally Posted by Icon
windows.h is a big header file though.. You can try to #define WIN32_LEAN_AND_MEAN. ShellExecute is not really a portable solution, I do not know if that is a problem for you?


nope didnt wrk

Reply With Quote
  #15  
Old August 21st, 2007, 03:20 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
You have to include windows.h before shellapi.h. Although I did not have to include shellapi.h at all.

Good luck

Reply With Quote
  #16  
Old August 21st, 2007, 04:02 AM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Quote:
Originally Posted by Icon
You have to include windows.h before shellapi.h. Although I did not have to include shellapi.h at all.

Good luck

.\SHELL CODE.cpp(190) : error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\Justin Edelson\My Documents\Visual Studio 2005\Projects\E-SHELL\E-SHELL\Debug\BuildLog.htm"
E-SHELL - 1 error(s), 0 warning(s)



can u paste ur code?

Reply With Quote
  #17  
Old August 21st, 2007, 05:12 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
Try using ShellExecuteA instead of ShellExecuteW like I posted earlier. If that does not work I'll post my code, if I can still find it. I'm at work, so I do not always have time

Reply With Quote
  #18  
Old August 21st, 2007, 10:11 AM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Quote:
Originally Posted by Icon
Try using ShellExecuteA instead of ShellExecuteW like I posted earlier. If that does not work I'll post my code, if I can still find it. I'm at work, so I do not always have time

both still didnt work..

Reply With Quote
  #19  
Old August 21st, 2007, 10:43 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
This is working for me in visual studio 2005:

cpp Code:
Original - cpp Code
  1. //JUSTIN'S E-SHELL CODE
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <cstdio>
  7. #include <ctime>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.    char dateStr[9];
  13. //   _strdate_s(dateStr, 9);
  14.    string date = dateStr;
  15.    char timeStr[9];
  16. //   _strtime_s(timeStr, 9);
  17.    string time = timeStr;
  18.    string command ;
  19.    string argument;
  20.    string input;
  21.    ifstream infile;
  22.    string cat;
  23.    cout << "Justin Edelson Corporation E-SHELL [v.2.0]"<<endl;
  24.    cout << "<C> Copy Right 2007 All Rights Reserved"<<endl;
  25.    cout<<""<<endl;
  26.    string user = "Guest";
  27.    //cout<<"Logged in as: "<<user<<endl;
  28.    // cout <<"DATE: " << date << endl;
  29.    // cout <<"TIME: " << time << endl;
  30.    string pass1 = "admin";
  31.    string users1 = "justin";
  32.    string users2 = "admin";
  33.    string pass2 = "admin";
  34.    string password;
  35.    string users;
  36.    int z = 0;
  37.    cout<<""<<endl;
  38.    system("title E-SHELL");
  39.    cout<<""<<endl;
  40.    cout<<"Username: ";
  41.    cin>>users;
  42.    cout<<"Password: ";
  43.    cin>>password;
  44.    if(users == users1 | users == users2)
  45.    {
  46.       z=z+1;
  47.    }
  48.    if(password == pass1 | password == pass2)
  49.    {
  50.       z=z+1;
  51.    }
  52.    if(z==2)
  53.    {
  54.       cout<<""<<endl;
  55.       string user = users;
  56.       system("color 07");
  57.       cout<<"Logged in as: "<<user<<endl;
  58.    }
  59.  
  60.  
  61.    cout<<""<<endl;
  62.    cout << "E-SHELL v.2.0> ";
  63.    getline(cin, input);
  64.  
  65.    while(z==2)
  66.    {
  67.  
  68.       getline(cin, input);
  69.       int pos = input.find(" ");
  70.       command = input.substr(0, pos);
  71.       if(command == "" )
  72.       {
  73.          // noop
  74.       }
  75.       else if(command == "cat")
  76.       {
  77.          argument = input.substr(pos+1);
  78.          infile.open(argument.c_str());
  79.  
  80.          if (!infile.is_open())
  81.          {
  82.             cerr <<"Could not open file.\n";
  83.             exit(-1);
  84.          }
  85.          //do cat code heren (just a while loop with getline)
  86.          while(getline(infile, cat))
  87.          {
  88.             cout<<""<<endl;
  89.             cout << cat << endl;
  90.          }
  91.       }
  92.       else if(command == "exit")
  93.       {
  94.          exit(0);
  95.       }
  96.       else if(command == "ls")
  97.       {
  98.          cout<<""<<endl;
  99.          cout<<"Add all to see hidden files"<<endl;
  100.          cout<<""<<endl;
  101.          system("dir");
  102.       }
  103.       else if(command == "lsall")
  104.       {
  105.          cout<<""<<endl;
  106.          system("dir/a");
  107.       }
  108.       else if(command == "ip")
  109.       {
  110.          system("ipconfig");
  111.       }
  112.       else if(command == "ipfix")
  113.       {
  114.  
  115.          system("start ipfix.bat");
  116.       }
  117.       else if(command == "clear")
  118.       {
  119.          system("cls");
  120.       }
  121.       else if(command =="rm")
  122.       {
  123.          command = input.substr(0, pos);
  124.          argument = input.substr(pos+1);
  125.          if( remove( argument.c_str() )!= 0 )
  126.          {
  127.             cerr << "Error deleting file, argument:" << argument;
  128.          }
  129.          else
  130.          {
  131.             cout<< "File successfully deleted" ;
  132.          }
  133.       }
  134.       else if(command == "rname")
  135.       {
  136.          command = input.substr(0, pos);
  137.          int pos2= input.find(" ", pos+1);
  138.          string oldname = input.substr(pos+1, pos2-pos);
  139.          string newname = input.substr(pos2+1);
  140.          //their code
  141.          int result;
  142.          result= rename( oldname.c_str() , newname.c_str () );
  143.          if ( result == 0 )
  144.             cout<< "File successfully renamed"<<endl;
  145.          else
  146.             cerr << "Error renaming file, argument:" << argument;
  147.       }
  148.       else if(command == "echo")
  149.       {
  150.          int pos2= input.find(">");
  151.          ofstream outfile;
  152.          argument = input.substr(pos+1);
  153.          outfile.open(input.substr(pos2+1).c_str());
  154.          outfile << input.substr(pos+1, pos2-(pos+1));
  155.          outfile.close();
  156.       }
  157.       else if (command =="cd")
  158.       {
  159.          // DirectoryInfo di = new DirectoryInfo("test");
  160.          // di.Attributes |= FileAttributes.ReadOnly;
  161.          //if(pos == string::npos)
  162.          //{
  163.          system("cd");
  164.          //}
  165.          //else
  166.          //{
  167.          // argument = input.substr(pos);
  168.          // cout << "command running: " << command+argument << endl;
  169.          // system((command + argument).c_str());
  170.          //}
  171.       }
  172.       else if (command == "move")
  173.       {
  174.  
  175.          int pos2= input.find(" ", pos+1);
  176.          argument = input.substr(pos+1);
  177.          //system("move");
  178.          system ((command +" "+ argument).c_str());
  179.       }
  180.       else if (command == "mkdir")
  181.       {
  182.          int pos2= input.find(" ", pos+1);
  183.          argument = input.substr(pos+1);
  184.          //system("mkdir")
  185.          system ((command +" "+ argument).c_str());
  186.       }
  187.       else if (command == "rmdir")
  188.       {
  189.          int pos2= input.find(" ", pos+1);
  190.          argument = input.substr(pos+1);
  191.          //system("rmdir")
  192.          system ((command +" "+ argument).c_str());
  193.       }
  194.       else if(command == "shutl")
  195.       {
  196.          cout<<""<<endl;
  197.          cout <<"Different Ways to shutdown."<<endl;
  198.          cout<<""<<endl;
  199.          cout<<"shutf immediatlly shutdowns the computer"<<endl;
  200.       }
  201.       else if(command == "shutf")
  202.       {
  203.          system("shutdown /f");
  204.       }
  205.       else if(command == "td")
  206.       {
  207.          cout<<""<<endl;
  208.          cout <<"DATE: " << date << endl;
  209.          cout <<"TIME: " << time << endl;
  210.          cout<<""<<endl;
  211.       }
  212.       else if(command == "note")
  213.       {
  214.          system("START /MAX NOTEPAD");
  215.       }
  216.       else if(command == "browse")
  217.       {
  218.          string b;
  219.          cout<<" Enter Your Search Here"<<endl;
  220.          cin>>b;
  221.          //call "C:\Program Files\Internet Explorer\iexplore.exe" "b"
  222.          ShellExecuteA(NULL, "open", b.c_str(), NULL, NULL, SW_SHOWNORMAL);
  223.       }
  224.       else if (command == "tips")
  225.       {
  226.          cout<<""<<endl;
  227.          cout<<"1. Hit F7 to see a list of usefull commands"<<endl;
  228.          cout<<"2. Type in shutl to see a list of shutdown commands"<<endl;
  229.          cout<<"3. Type in cac to get to a command line based caculator"<<endl;
  230.       }
  231.       else if (command == "help" | command == "/?" | command == "?" | command == "commands")
  232.       {
  233.          cout <<"" <<endl;
  234.          cout <<"Here is the list of all of the commands that this shell has so far.." <<endl;
  235.          cout <<"" <<endl;
  236.          cout <<" TIPS Displays a list of usefull commands"<<endl;
  237.          cout <<" SHUTL lists a couple of different ways to shutdown"<<endl;
  238.          cout <<" CAT Can read files" <<endl;
  239.          cout <<" NOTE Opens notepad"<<endl;
  240.          cout <<" ECHO Can write or edit files" <<endl;
  241.          cout <<" RM Deletes a file permanantly"<<endl;
  242.          cout <<" RNAME Renames a certain file"<<endl;
  243.          cout <<" TD Displays the time and date"<<endl;
  244.          cout <<" LS A list of the contents inside directory" <<endl;
  245.          cout <<" LSALL Displays all the files, including hidden, in the current directory"<<endl;
  246.          cout <<" MOVE Moves a file to a folder"<<endl;
  247.          cout <<" MKDIR Makes a new folder in current Directory"<<endl;
  248.          cout <<" RMDIR Removes a direcotry (/s to remove everthing in direcoty"<<endl;
  249.          cout <<" CD Displays the address of the current directory" <<endl;
  250.          cout <<" IP Displays your ip adderess and subnet mask" <<endl;
  251.          cout <<" IPFIX Renews your ip addres which usually fixes the problem" <<endl;
  252.          cout <<" CLEAR Clears the screen" <<endl;
  253.          cout <<" HELP Displays a list of commands working on v.1.0"<<endl;
  254.          cout <<" EXIT Exits the shell immediately" <<endl;
  255.       }
  256.  
  257.       else
  258.       {
  259.          system("color 0c");
  260.          cout << "This command is not recognized by this shell."<<endl;
  261.          cout << "Type in help to see a list of commands.";
  262.          cout << "\n";
  263.          cout << "\n";
  264.          cout << "\n"<<endl;
  265.          system("PAUSE");
  266.          system("color 07");
  267.       }
  268.  
  269.       cout<<""<<endl;
  270.       cout << "E-SHELL v.2.0> ";
  271.    }
  272. }

Reply With Quote
  #20  
Old August 21st, 2007, 01:51 PM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
------ Build started: Project: login_e-shell, Configuration: Debug Win32 ------
Compiling...
login.cpp
Linking...
login.obj : error LNK2028: unresolved token (0A000344) "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteA(struct HWND__ *,char const *,char const *,char const *,char const *,int)" (?ShellExecuteA@@$$J224YGPAUHINSTANCE__@@PAUHWND__ @@PBD111H@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
login.obj : error LNK2019: unresolved external symbol "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteA(struct HWND__ *,char const *,char const *,char const *,char const *,int)" (?ShellExecuteA@@$$J224YGPAUHINSTANCE__@@PAUHWND__ @@PBD111H@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
C:\Documents and Settings\Justin Edelson\My Documents\Visual Studio 2005\Projects\login_e-shell\Debug\login_e-shell.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Justin Edelson\My Documents\Visual Studio 2005\Projects\login_e-shell\login_e-shell\Debug\BuildLog.htm"
login_e-shell - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Reply With Quote
  #21  
Old August 21st, 2007, 02:00 PM
justinede justinede is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 justinede User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 51 sec
Reputation Power: 11
Code:
//JUSTIN'S E-SHELL CODE
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <ctime>
using namespace std;

int main()
{
	char dateStr[9];
	_strdate_s(dateStr, 9);
	string date = dateStr;
	char timeStr[9];
	_strtime_s(timeStr, 9);
	string time = timeStr;
	string command ;
	string argument;
	string input;
	ifstream infile;
	string cat;
	cout << "Justin Edelson Corporation E-SHELL [v.1.1]"<<endl;
	cout << "<C> Copy Right 2007 All Rights Reserved"<<endl;
	cout<<""<<endl;
	cout <<"DATE: " << date << endl;	
	cout <<"TIME: " << time << endl;	
	cout<<""<<endl;
	system("title E-SHELL");
	while(true)
	{
		cout<<""<<endl;
		cout << "E-SHELL v.1.1> ";
		getline(cin, input);
		int pos = input.find(" ");
		command = input.substr(0, pos);
		if(command == "cat")
		{
			argument = input.substr(pos+1);
			infile.open(argument.c_str());
			
			if (!infile.is_open())
			{
				cerr <<"Could not open file.\n";
				exit(-1);
			}
			//do cat code heren (just a while loop with getline)
			while(getline(infile, cat))
			{
				cout<<""<<endl;
				cout << cat << endl;
			}
		}
		else if(command == "exit")
		{
			exit(0);
		}
		else if(command == "ls")
		{
			cout<<""<<endl;
			cout<<"Add all to see hidden files"<<endl;
			cout<<""<<endl;
			system("dir");	
		}
		else if(command == "lsall")
		{
			cout<<""<<endl;
			system("dir/a");
		}
		else if(command == "ip")
		{
			system("ipconfig");
		}
		else if(command == "ipfix")
		{

			system("start ipfix.bat");
		}
		else if(command == "clear")
		{
			system("cls");
		}
		else if(command =="rm")
		{
			command = input.substr(0, pos);
			argument = input.substr(pos+1);
			if( remove( argument.c_str() )!= 0 )
			{
				cerr << "Error deleting file, argument:" << argument;
			}
			else
			{
				cout<< "File successfully deleted" ;
			}
		}
		else if(command == "rname")
		{
			command = input.substr(0, pos);
			int pos2= input.find(" ", pos+1);
			string oldname = input.substr(pos+1, pos2-pos);
			string newname = input.substr(pos2+1);
			//their code
		    int result;
			result= rename( oldname.c_str() , newname.c_str () );
			if ( result == 0 )
			cout<< "File successfully renamed"<<endl;
			else
			cerr << "Error renaming file, argument:" << argument;
		}
		else if(command == "echo")
		{
			int pos2= input.find(">");
			ofstream outfile;
			argument = input.substr(pos+1);
			outfile.open(input.substr(pos2+1).c_str());
			outfile << input.substr(pos+1, pos2-(pos+1));
			outfile.close();
		}
		else if (command =="cd")
		{
			// DirectoryInfo di = new DirectoryInfo("test");
			// di.Attributes |= FileAttributes.ReadOnly;	
			//if(pos == string::npos)
			//{
				system("cd");
			//}
			//else
			//{
			//	argument = input.substr(pos);
			//	cout << "command running: " << command+argument << endl;
			//	system((command + argument).c_str());
			//}
		}
		else if (command == "move")
		{

			int pos2= input.find(" ", pos+1);		
			argument = input.substr(pos+1);
			//system("move");
			system ((command +" "+ argument).c_str());
		}
		else if (command == "mkdir")
		{
			int pos2= input.find(" ", pos+1);		
			argument = input.substr(pos+1);
			//system("mkdir")
			system ((command +" "+ argument).c_str());
		}
		else if (command == "rmdir")
		{
			int pos2= input.find(" ", pos+1);		
			argument = input.substr(pos+1);
			//system("rmdir")
			system ((command +" "+ argument).c_str());
		}
		else if(command == "shutl")
		{
			cout<<""<<endl;
			cout <<"Different Ways to shutdown."<<endl;
			cout<<""<<endl;
			cout<<"shutf  immediatlly shutdowns the computer"<<endl;
		}
		else if(command == "shutf")
		{
			system("shutdown /f");
		}
		else if(command == "td")
		{
			cout<<""<<endl;
			cout <<"DATE: " << date << endl;	
			cout <<"TIME: " << time << endl;	
			cout<<""<<endl;
		}
		else if(command == "browse")
        {
            string b;
            cout<<" Enter Your Search Here"<<endl;
            cin>>b;
			//call "C:\Program Files\Internet Explorer\iexplore.exe" "b"
            ShellExecuteW(NULL, "open", b.c_str(), NULL, NULL, SW_SHOWNORMAL);
        } 
		else if(command == "note")
		{
			system("START /MAX NOTEPAD");
		}
		else if(command == "browse")
		{
			string b;
			cout<<" Enter Your Search Here"<<endl;
			cin>>b;
			//call "C:\Program Files\Internet Explorer\iexplore.exe" "b"
			ShellExecuteA(NULL, "open", b.c_str(), NULL, NULL, SW_SHOWNORMAL);
		}
		else if (command == "tips")
		{
			cout<<""<<endl;
			cout<<"1.  Hit F7 to see a list of usefull commands"<<endl;
			cout<<"2.  Type in shutl to see a list of shutdown commands"<<endl;
			cout<<"3.  Type in cac to get to a command line based caculator"<<endl;
		}
		else if (command == "help" | command == "/?" | command == "?" | command == "commands")
		{
			cout <<"" <<endl;
			cout <<"Here is the list of all of the commands that this shell has so far.." <<endl;
			cout <<"" <<endl;
			cout <<" TIPS	Displays a list of usefull commands"<<endl;
			cout <<" SHUTL	lists a couple of different ways to shutdown"<<endl;
			cout <<" CAT    Can read files" <<endl;
			cout <<" NOTE	Opens notepad"<<endl;
			cout <<" ECHO   Can write or edit files" <<endl;
			cout <<" RM	Deletes a file permanantly"<<endl;
			cout <<" RNAME	Renames a certain file"<<endl;
			cout <<" TD	Displays the time and date"<<endl;
			cout <<" LS     A list of the contents inside directory" <<endl;
			cout <<" LSALL	Displays all the files, including hidden, in the current directory"<<endl;
			cout <<" MOVE	Moves a file to a folder"<<endl;
			cout <<" MKDIR	Makes a new folder in current Directory"<<endl;
			cout <<" RMDIR	Removes a direcotry (/s to remove everthing in direcoty"<<endl;
			cout <<" CD	Displays the address of the current directory" <<endl;
			cout <<" IP	Displays your ip adderess and subnet mask" <<endl;
			cout <<" IPFIX	Renews your ip addres which usually fixes the problem" <<endl;
			cout <<" CLEAR  Clears the screen" <<endl;
			cout <<" HELP   Displays a list of commands working on v.1.0"<<endl;
			cout <<" EXIT   Exits the shell immediately" <<endl;
		}

		else
		{
			system("color 0c");
			cout << "This command is not recognized by this shell."<<endl;
			cout << "Type in help to see a list of commands.";
			cout << "\a";
			cout << "\a";
			cout << "\a"<<endl;
			system("PAUSE");
			system("color 07");
		}
	}	
}


then this error

------ Build started: Project: E-SHELL, Configuration: Debug Win32 ------
Compiling...
SHELL CODE.cpp
.\SHELL CODE.cpp(180) : error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\Justin Edelson\My Documents\Visual Studio 2005\Projects\E-SHELL\E-SHELL\Debug\BuildLog.htm"
E-SHELL - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - C++ browse HELP


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap