Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I this correct?

I this correct?

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
28 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Then it is simply a matter of creating the full command and parameter in a string and passing that string to the system command.

    wchar_t sysCommand[128];
    swprintf_s(sysCommand, L"attrib %s", store);
    system(sysCommand);

    See also system, _wsystem[^].

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #7

    I have no idea if this is the right answer to the OP's question, Richard, but the fact that you were able to ascertain something from it is impressive. :thumbsup:

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    L 1 Reply Last reply
    0
    • L Lost User

      Then it is simply a matter of creating the full command and parameter in a string and passing that string to the system command.

      wchar_t sysCommand[128];
      swprintf_s(sysCommand, L"attrib %s", store);
      system(sysCommand);

      See also system, _wsystem[^].

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #8

      Sir, errors are quiet similar to my initial work. i.e initially when I use system(store) it shows me an error the same error is showing when I use system(sysCommand); Error:

      Severity Code Description Project File Line
      Error C2664 'int system(const char *)': cannot convert argument 1 from 'wchar_t [128]' to 'const char *' CG C:\Users\User\Desktop\Analyser tools\Sub-Project\Sub-Project\USB informer.cpp 52

      Thank you for your kind help

      D L 2 Replies Last reply
      0
      • D David Crow

        I have no idea if this is the right answer to the OP's question, Richard, but the fact that you were able to ascertain something from it is impressive. :thumbsup:

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #9

        Thanks, it was somewhat easier than many of the questions we are seeing.

        1 Reply Last reply
        0
        • L Lost User

          Sir, errors are quiet similar to my initial work. i.e initially when I use system(store) it shows me an error the same error is showing when I use system(sysCommand); Error:

          Severity Code Description Project File Line
          Error C2664 'int system(const char *)': cannot convert argument 1 from 'wchar_t [128]' to 'const char *' CG C:\Users\User\Desktop\Analyser tools\Sub-Project\Sub-Project\USB informer.cpp 52

          Thank you for your kind help

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #10

          This is a Unicode issue.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          L 1 Reply Last reply
          0
          • L Lost User

            Sir, errors are quiet similar to my initial work. i.e initially when I use system(store) it shows me an error the same error is showing when I use system(sysCommand); Error:

            Severity Code Description Project File Line
            Error C2664 'int system(const char *)': cannot convert argument 1 from 'wchar_t [128]' to 'const char *' CG C:\Users\User\Desktop\Analyser tools\Sub-Project\Sub-Project\USB informer.cpp 52

            Thank you for your kind help

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #11

            Sorry, my mistake, you need to use _wsystem. See the link I provided in a previous message.

            L 2 Replies Last reply
            0
            • D David Crow

              This is a Unicode issue.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #12

              To sir DavidCrow: I am using Unicode characet set what should I do now? I am using only unicode and not multibyte Thank you for your kind help

              D 1 Reply Last reply
              0
              • L Lost User

                To sir DavidCrow: I am using Unicode characet set what should I do now? I am using only unicode and not multibyte Thank you for your kind help

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #13

                You can't send a wchar_t array to system(). It's expecting a char pointer/array instead.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                1 Reply Last reply
                0
                • L Lost User

                  Sorry, my mistake, you need to use _wsystem. See the link I provided in a previous message.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #14

                  Sir, It works now Thank you for you kind,quick and constant help!

                  1 Reply Last reply
                  0
                  • L Lost User

                    Sorry, my mistake, you need to use _wsystem. See the link I provided in a previous message.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #15

                    Sir, I have completed everything and when I run my code the command window disappears immediately what should I do now? Thank you

                    L 1 Reply Last reply
                    0
                    • L Lost User

                      Sir, I have completed everything and when I run my code the command window disappears immediately what should I do now? Thank you

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #16

                      The system process will only run the command that you send it, and then terminate. There are alternative ways of doing this: see the exec commands at Process and Environment Control[^].

                      L 1 Reply Last reply
                      0
                      • L Lost User

                        The system process will only run the command that you send it, and then terminate. There are alternative ways of doing this: see the exec commands at Process and Environment Control[^].

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #17

                        Sir, I referred here Execute a Program with C++[^] and did this

                        ShellExecute(
                        NULL,
                        _T("open"),
                        _T("cmd.exe"),
                        _T("attrib"),
                        (show),
                        SW_SHOW);

                        it is showing the show (I mean the directory) like this K:\ but not ececuting the attrib.how could I solve this? Thank you

                        D L 2 Replies Last reply
                        0
                        • L Lost User

                          Sir, I referred here Execute a Program with C++[^] and did this

                          ShellExecute(
                          NULL,
                          _T("open"),
                          _T("cmd.exe"),
                          _T("attrib"),
                          (show),
                          SW_SHOW);

                          it is showing the show (I mean the directory) like this K:\ but not ececuting the attrib.how could I solve this? Thank you

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #18

                          If you are wanting to get the attributes of a file/folder, why do it the way we were doing it 30 years ago? See GetFileAttributes() instead.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                          1 Reply Last reply
                          0
                          • L Lost User

                            Sir, I referred here Execute a Program with C++[^] and did this

                            ShellExecute(
                            NULL,
                            _T("open"),
                            _T("cmd.exe"),
                            _T("attrib"),
                            (show),
                            SW_SHOW);

                            it is showing the show (I mean the directory) like this K:\ but not ececuting the attrib.how could I solve this? Thank you

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #19

                            Your parameters are not correct, and it will not work just by opening cmd.exe. You need to add the option to tell cmd to execute the sub-command in the parameter list automatically like:

                            PWSTR show = L"/k attrib D:\\";
                            ShellExecute(
                            NULL,
                            L"open",
                            L"cmd.exe",
                            show,
                            NULL,
                            SW_SHOW);

                            Of course, the attrib command will not operate on a drive letter, and as David mentions, there are better ways of getting this information.

                            L 1 Reply Last reply
                            0
                            • L Lost User

                              Your parameters are not correct, and it will not work just by opening cmd.exe. You need to add the option to tell cmd to execute the sub-command in the parameter list automatically like:

                              PWSTR show = L"/k attrib D:\\";
                              ShellExecute(
                              NULL,
                              L"open",
                              L"cmd.exe",
                              show,
                              NULL,
                              SW_SHOW);

                              Of course, the attrib command will not operate on a drive letter, and as David mentions, there are better ways of getting this information.

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #20

                              Sir, Is there any other way to execute some commands like this to a specific drive by giving the drive string at the run time? because I have to define the drive name here? I have referred to create process, shell execute etc., attributes is one of my functions I need to execute several different commands like this on a specific drive how could one do it? Thank you

                              D L 2 Replies Last reply
                              0
                              • L Lost User

                                Sir, Is there any other way to execute some commands like this to a specific drive by giving the drive string at the run time? because I have to define the drive name here? I have referred to create process, shell execute etc., attributes is one of my functions I need to execute several different commands like this on a specific drive how could one do it? Thank you

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #21

                                VISWESWARAN1998 wrote:

                                ...I need to execute several different commands like this on a specific drive...

                                Be specific.

                                "One man's wage rise is another man's price increase." - Harold Wilson

                                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                L 1 Reply Last reply
                                0
                                • D David Crow

                                  VISWESWARAN1998 wrote:

                                  ...I need to execute several different commands like this on a specific drive...

                                  Be specific.

                                  "One man's wage rise is another man's price increase." - Harold Wilson

                                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #22

                                  Sir, my program will not do anything on its own. I have a added GetLogicalDriveStrings in a combobox which will show the list of drive present in the PC. Then if the user wishes to add a directory by pressing a push button, then cmd function should execute and create a directory or hiding folders and so on on the drive specified. I know it is much easier to do this manually but I am learning windows API so it will be helpful for my future use. Thank you

                                  D 1 Reply Last reply
                                  0
                                  • L Lost User

                                    Sir, my program will not do anything on its own. I have a added GetLogicalDriveStrings in a combobox which will show the list of drive present in the PC. Then if the user wishes to add a directory by pressing a push button, then cmd function should execute and create a directory or hiding folders and so on on the drive specified. I know it is much easier to do this manually but I am learning windows API so it will be helpful for my future use. Thank you

                                    D Offline
                                    D Offline
                                    David Crow
                                    wrote on last edited by
                                    #23

                                    VISWESWARAN1998 wrote:

                                    ...but I am learning windows API...

                                    Then start using it. Trying to do all of this via system() and ShellExecute() is all but completely wrong.

                                    "One man's wage rise is another man's price increase." - Harold Wilson

                                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                    L 1 Reply Last reply
                                    0
                                    • D David Crow

                                      VISWESWARAN1998 wrote:

                                      ...but I am learning windows API...

                                      Then start using it. Trying to do all of this via system() and ShellExecute() is all but completely wrong.

                                      "One man's wage rise is another man's price increase." - Harold Wilson

                                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #24

                                      Sir, what to use? could you please explain me briefly?

                                      D 1 Reply Last reply
                                      0
                                      • L Lost User

                                        Sir, what to use? could you please explain me briefly?

                                        D Offline
                                        D Offline
                                        David Crow
                                        wrote on last edited by
                                        #25

                                        See here.

                                        "One man's wage rise is another man's price increase." - Harold Wilson

                                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                        L 1 Reply Last reply
                                        0
                                        • L Lost User

                                          Sir, Is there any other way to execute some commands like this to a specific drive by giving the drive string at the run time? because I have to define the drive name here? I have referred to create process, shell execute etc., attributes is one of my functions I need to execute several different commands like this on a specific drive how could one do it? Thank you

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #26

                                          I showed you how to do it in my correction of your code.

                                          L 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups