Results 1 to 5 of 5

Thread: Help with executing command from cmd

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2012
    Posts
    61

    Help with executing command from cmd

    Hi,
    I am trying to execute this command from cmd when a button is clicked:

    Code:
    wevtutil qe system "/q:*[System [(Level=2)]]" /f:text /c:5 /rd:True
    The problem is that I can't execute it successfully due to the presence of the Quotations in the cmd line of code itself.

    The code in Visual Studio looks somewhat like this:

    Code:
    Shell("cmd /c wevtutil qe system " /q:*[System [(Level=2)]]"/f:text /c:5 /rd:true >C:\Last5.txt", vbHide)
    I'd really appreciate the help with this, please.

    Thanks in advance...

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: Help with executing command from cmd

    You need to escape each quote mark by adding another one to it (i.e replace 1 double quote mark with 2 double quote marks)
    Code:
    Shell("cmd /c wevtutil qe system ""/q:*[System [(Level=2)]]""/f:text /c:5 /rd:true >C:\Last5.txt", vbHide)
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2012
    Posts
    61

    Re: Help with executing command from cmd

    Quote Originally Posted by stanav View Post
    You need to escape each quote mark by adding another one to it (i.e replace 1 double quote mark with 2 double quote marks)
    Code:
    Shell("cmd /c wevtutil qe system ""/q:*[System [(Level=2)]]""/f:text /c:5 /rd:true >C:\Last5.txt", vbHide)
    Thanks for the reply, the code you provided seems to solve the error i was getting due to the quote marks, but it still won't write the output to the Text File (Last5.txt)
    It just creates an empty file...

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: Help with executing command from cmd

    Open the command prompt then manually type in the command and execute it... When you get the desired result, come back here and post the exact command you used...
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2012
    Posts
    61

    Re: Help with executing command from cmd

    There seemed to be a minor silly mistake in my code, i had forgotten to put a blank space after a quote mark which most probably caused the line of code to be unrecognized...
    it's now solved, thanks to you...
    thanks alot ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width