Can someone help me with this source

This is a discussion on Can someone help me with this source within the Windows Programming forums, part of the Platform Specific Boards category; hey everyone iv got a problem with the below source and I cant understand why it wont compile. When i ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    10

    Can someone help me with this source

    hey everyone iv got a problem with the below source and I cant understand why it wont compile. When i try to compile it I get the following error:

    105 runassrc.cpp incompatible types in assignment of `const char[11]' to `char[1000]'

    Iv been messing about with it for hours but cant get it to work.

    Any help is appreciated.

    Code:
    // Runas Program Created by SuperStonerMan
    
    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <string.h>
    #include <cstdlib>
    #include <cstdio>
    
    void whichControl(int a);
    char control[1000];
    
    int main()
    {
     using namespace std;
    
     //Variable decleration
     char userN[1000] = "administrator";
     char command[1000] = "runas /user:";
     int option = 0;
    
     // Intro and username input
     cout<<"This program was written by SuperStonerMan and allows a user\n";
     cout<<"to efficentley use Windows Xp as a non admin user\n\n";
     cout<<"Please enter the username you wish to open an applicationw with.\n";
     cout<<"Username: ";
     cin>>userN;
     cin.ignore();
    
     //Menu
     cout<<"\n";
     cout<<"Which program would you like to open as " << userN << "\n";
     cout<<"Option: 1 Explorer\n";
     cout<<"Option: 2 Microsoft Mangment Console\n";
     cout<<"Option: 3 Control Panel\n";
     cout<<"Option: ";
     cin>>option;
     cin.ignore();
    
     //Menu Logic
     if (option == 1)
     {
      cout<<"\n";
      cout<<"Explorer\n";
      strcat(command, userN);
      strcat(command, " \"explorer.exe /separate\"");
      system(command);
     }
    
     else if (option == 2)
     {
      cout<<"\n";
      cout<<"Microsoft Mangment Console\n";
      strcat(command, userN);
      strcat(command, " \"mmc /separate\"");
      system(command);
     }
    
     else if (option == 3)
     {
      int option1 = 0;
      cout<<"\n";
      cout<<"Control Panel\n\n";
      cout<<"Control Panel Menu\n";
      cout<<"Option 1 Accessibility Options\n";
      cout<<"Option 2 Add New Hardware\n";
      cout<<"Option 3 Add/Remove Programs\n";
      cout<<"Option 4 Date/Time Properties\n";
      cout<<"Option 5 Display Properties\n";
      cout<<"Option 6 Fonts Folder\n";
      cout<<"Option 7 Internet Properties\n";
      cout<<"Option 9 Keyboard Properties\n";
      cout<<"Option 10 Windows Messaging\n";
      cout<<"Option 11 Modem Properties\n";
      cout<<"Option 12 Mouse Properties\n";
      cout<<"Option 13 Multimedia Properties\n";
      cout<<"Option 14 Network Properties\n";
      cout<<"Option 15 Password Properties\n";
      cout<<"Option 16 Printers Folder\n";
      cout<<"Option 17 Regional Settings\n";
      cout<<"Option 19 Sound Properties\n";
      cout<<"Option 20 System Properties\n\n";
    
      cout<<"Option: ";
      cin>>option1;
      cin.ignore();
    
      whichControl(option1);
      cout<<"\n";
      strcat(command, userN);
      strcat(command, " \"control  ");
      strcat(command, control);
    
      //system(command);
      cout<<command;
      cin.get();
      }
    
    }
    
    void whichControl(int a)
    {
     if (a == 1)
     {
      control = "access.cpl";
     }
    }

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,449
    1. use only c++ headers
    Code:
    //#include <stdio.h> - remove it you are using cstdio
    #include <iostream>
    #include <cstring>
    //#include <string.h> - remove it - you are using cstring
    #include <cstdlib>
    #include <cstdio>
    Do not use C-strings, use std::string
    then you can do as you like:
    control = "access.cpl";

    3. do not use globals until you cannot avoid it at any cost
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    10
    Thanks for your help but im having problems with strings. Iv read the following tutorial:
    http://www.cprogramming.com/tutorial/string.html

    But the the follwoing code wont compile:

    Code:
    #include <iostream>
    #include <cstring>
    #include <string.h>
    #include <cstdlib>
    #include <cstdio>
    
    int main(int argc, char *argv[])
    {
      using namespace std;
      string hello = "hello";
    
      cout<<string;
      cin.get();
      return 0;
    }
    Im sorry if im missing something really simple. Any help is appreciated
    Last edited by superstonerman; 07-26-2007 at 03:06 PM.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    cstring is the equivalent of string.h, except that it's for C++. So use cstring, not string.h.

    that goes for all the header.h files.
    header.h is then cheader

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    instead of direct assignment, try :

    Code:
    // control = "access.cpl";
    sprintf( control , "access.cpl\0" );
    Dont listen to Vart, he is a moron.

    1. The problem isnt in the headers you use.
    2. He skipped form 1 to 3, what appears to be his second point is just pointless blather
    3. The use of globals has no impact on this problem
    Last edited by abachler; 07-26-2007 at 03:22 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #6
    Registered User
    Join Date
    Jul 2007
    Posts
    10
    Thanks sprintf( control , "access.cpl\0" ); works fine. The problem is however that I need a quotation mark at the end of access.cpl. So the output is: access.cpl".

    How would I code this as I understand quotation marks cannot be used in strings. Alos what is the \0 used for?

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    "\0" is used to indicate the end of a string. In this case, I don't really understand why it's there, it is implicitly added by the compiler to any text in double-quotes.

    You can add quotation marks inside a string by prefixing them with a \, something like this:

    Code:
    printf("My name is \"Mats\"\n");
    which will output:

    My name is "Mats"

    [Why anyone would like to print that is a different matter :-) ]

    --
    Mats

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    10

    Thumbs up

    Thank you very much to everyone who helped me. if anyones interested heres the completed program:

    Code:
    // Runas Program Created by SuperStonerMan
    
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    char control[1000];
    
    void whichControl(int a);
    
    int main()
    {
      using namespace std;
    
    
     //Variable decleration
     char userN[1000] = "administrator";
     char command[1000] = "runas /user:";
     int option = 0;
    
     // Intro and username input
     cout<<"This program was written by SuperStonerMan and allows a user\n";
     cout<<"to efficentley use Windows Xp as a non admin user\n\n";
     cout<<"Please enter the username you wish to open an application with.\n";
     cout<<"Username: ";
     cin>>userN;
     cin.ignore();
    
     //Menu
     cout<<"\n";
     cout<<"Which program would you like to open as " << userN << "\n";
     cout<<"Option: 1 Explorer\n";
     cout<<"Option: 2 Microsoft Mangment Console\n";
     cout<<"Option: 3 Control Panel\n";
     cout<<"Option: ";
     cin>>option;
     cin.ignore();
    
     //Menu Logic
     if (option == 1)
     {
      cout<<"\n";
      cout<<"Explorer\n";
      strcat(command, userN);
      strcat(command, " \"explorer.exe /separate\"");
      system(command);
     }
    
     else if (option == 2)
     {
      cout<<"\n";
      cout<<"Microsoft Mangment Console\n";
      strcat(command, userN);
      strcat(command, " \"mmc /separate\"");
      system(command);
     }
    
     else if (option == 3)
     {
      int option1 = 0;
      cout<<"\n";
      cout<<"Control Panel\n\n";
      cout<<"Control Panel Menu\n";
      cout<<"Option 1 Accessibility Options\n";
      cout<<"Option 2 System Properties\n";
      cout<<"Option 3 Add/Remove Programs\n";
      cout<<"Option 4 Date/Time Properties\n";
      cout<<"Option 5 Display Properties\n";
      cout<<"Option 6 Internet Properties\n";
      cout<<"Option 7 Keyboard Properties\n";
      cout<<"Option 8 Modem Properties\n";
      cout<<"Option 9 Mouse Properties\n";
      cout<<"Option 10 Multimedia Properties\n";
      cout<<"Option 11 Network Properties\n";
      cout<<"Option 12 Regional Settings\n";
      cout<<"Option 13 Sound Properties\n";
    
    
      cout<<"Option: ";
      cin>>option1;
      cin.ignore();
    
      whichControl(option1);
      cout<<"\n";
      strcat(command, userN);
      strcat(command, " \"control  ");
      strcat(command, control);
    
      system(command);
      }
    
    }
    
    void whichControl(int a)
    {
     switch (a)
     {
     case 1:
          sprintf( control , "access.cpl\"" );
          break;
     case 2:
          sprintf( control , "sysdm.cpl\"" );
          break;
     case 3:
          sprintf( control , "appwiz.cpl\"" );
          break;
     case 4:
          sprintf( control , "timedate.cpl\"" );
          break;
     case 5:
          sprintf( control , "desk.cpl\"" );
          break;
     case 6:
          sprintf( control , "inetcpl.cpl\"" );
          break;
     case 7:
          sprintf( control , "main.cpl keyboard\"" );
          break;
     case 8:
          sprintf( control , "modem.cpl\"" );
          break;
     case 9:
          sprintf( control , "main.cpl\"" );
          break;
     case 10:
          sprintf( control , "mmsys.cpl\"" );
          break;
     case 11:
          sprintf( control , "Ncpa.cpl\"" );
          break;
     case 12:
          sprintf( control , "intl.cpl\"" );
          break;
     case 13:
          sprintf( control , "mmsys.cpl sounds\"" );
          break;
     default:
          break;
     }
    
    
    }
    Now i can use windows as a non admin user and improve on windows XP stupid design.

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,449
    to use std::string you need to include <string> header
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debug into Source
    By lehe in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2009, 09:45 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Open Source Licenses
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 10-10-2006, 08:53 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

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