Announcement

Collapse
No announcement yet.

how to suppress command prompt while running?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to suppress command prompt while running?

    hi everyone,

    i am running vbscript code which fetch me the DN of the server through command prompt (using dsquery) i am having more than 300 server, so each time when it invokes command prompt the DOS prompt window will appear i want this windows should be suppersed but the code should run and get its result.

    how its possible is there any possible way to do this?

  • #2
    Re: how to suppress command prompt while running?

    Can you post the script or the specific section of the script?
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

    Comment


    • #3
      Re: how to suppress command prompt while running?

      this what my script do which loop through the file and get the result

      Code:
      Option Explicit
      'dim FilePath1 
      Const FilePath1 = "c:\distinguish name.txt"
      
      Dim objFSO,objFile,objFile1,i
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objFile = objFSO.OpenTextFile("c:\Server move list.txt", ForReading)
      Set objFile1 = objFSO.CreateTextFile(FilePath1, True)
      
      Const ForReading = 1
      Dim arrFileLines()
      
      i = 0
      Do Until objFile.AtEndOfStream
         Redim Preserve arrFileLines(i)
         arrFileLines(i)= objFile.ReadLine
         Dim objShell,objWshScriptExec,objStdOut,strline,strcommand
      
         strcommand="dsquery computer -name" & Chr(32)& arrFileLines(i)
       WScript.Echo strcommand '*
      
         Set objShell = CreateObject("WScript.Shell")
         Set objWshScriptExec = objShell.Exec(strcommand) 
         Set objStdOut = objWshScriptExec.StdOut
         strline=objStdOut.ReadLine
      
       MsgBox strline '*
         objFile1.WriteLine(strline)
      
         i = i + 1
      Loop
      
      objFile.Close
      Last edited by Rems; 13th July 2009, 13:01. Reason: added code-tags

      Comment


      • #4
        Re: how to suppress command prompt while running?

        ahh so you want to save the results to to a file.

        (I had already asked what to do with the results but it wasn't answered in this similar thread by the same poster: need vbscript to promote fully qualified name of server)

        Talking about the other script, why not use the other script to write the results to an outputfile? It will solve the issue you have now with the dos-boxes.
        Or, why not using a batch that uses dsquery? like:
        Code:
        @echo off
        
        If /i NOT {%1}=={min} (
          Start ""/Min cmd /c "%~0" min
        goto:eof)
        
        cls &color 6A
        echo\
        
        echo\DO NOT CLOSE THIS WINDOWS!
        
        Set "inputFile=c:\Server move list.txt"
        Set "outputFile=c:\distinguish name.txt"
        
        > "%outputFile%" (
         For /f "usebackq delims=" %%* in (
           "%inputFile%"
           ) do call:titlebar &dsquery.exe computer -name "%%~*"
        )
        
        echo\DONE  (window closes automaticaly)
        
        
        GOTO:ENDtitlebar Subroutine
          :titlebar --------------------------------------------
            Set _title=(Set "_mill=\ ")
            IF DEFINED _mill (call:updtitle) ELSE (%_title%)
            title ^>dsquery   %_mill% & goto:eof
            :updtitle
              If "%_mill:~-2%"=="\ " (Set "_mill=^|" & goto:eof)
              If "%_mill:~-2%"=="^|" (Set "_mill=/ " & goto:eof)
              If "%_mill:~-2%"=="/ " (Set "_mill=--" & goto:eof)
              %_title% & goto:eof
        :ENDtitlebar Subroutine
        The batch above will minimize it self. It is also possible to hide a running batch file entirely by using this utillity: CMDOW
        You could use this tool also on the command string in the vbscript you posted in this thread if that'll make you happy.
        However, If you'd prefer using vbscript then I suggest to use the 'LDAP Query' or use 'NameTranslate' (ADSI) for each computer name to retrieve its DN. And export the results to a file.

        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: how to suppress command prompt while running?

          hi rems!

          i think you misunderstood my question i dont want any batch file to replace this code, the code whatever i have presented is working fine, what i need is i want the cmd prompt windows should not apper for cilent but still it need to execute the query without opening the command prompt windows.

          and to answer your question i am storing the result to a Txt file which is happening at the end of the code if you look at the code it will clear for you

          Comment


          • #6
            Re: how to suppress command prompt while running?

            hello vivekmohan,

            I do try to help you.
            please read my reply more carefully, it actually does fully covered your question.
            (When reading it you probably also see that you dit not answered my question I was asking there).

            If you use what normally is a command line tool in a vbs script and you like to capture the results from it, then you will see the dos-boxes popping-up when running the vbs script, unless you use the cmdow tool in the command line as well
            (OR... alternatively use the objShell.Run method instead of objShell.Exec and redirect the results from the dsquery command line directly to a workfile hiddenly, additionally it would be possible to read the workfile silently to the script again if needed. It is even possible to adapt the For-Do loop from the above batch sample into the vbs script then you dont have to create the FileSystemObject, doing so would simplify your vbs script sample a lot).

            What I suggested in my previous reply is: when you like to use vbs then use ADO or ASDI programming in your vbs script to find the objects in the AD, that will make the vbscript run silently, instead of using dsquery.


            \Rems
            Last edited by Rems; 14th July 2009, 08:50.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: how to suppress command prompt while running?

              let me show an example of how the "objShell.Run strCommand" method can be used instead of "objShell.Exec(strcommand)".

              I use the FOR-Do loop from the batch sample and write this to a one-liner command line Doing so you don't have to create the "Scripting.FileSystemObject"), because - the inputfile is opened in the loop, and the output of the dsquery staments is redirected directly to a new file, so it will make the script use less code.

              Code:
              rem ---------------------------------------------------
              rem This is a VBS script !
              rem 
              rem Sample how to
              rem launch Dsquery statements from within a vbs script.
              rem Dsquery will run hidden.
              rem ---------------------------------------------------
              
              
              inputFile = "c:\Server move list.txt"
              outputFile = "c:\distinguish name.txt"
              
              strcommand = "@For /f ""usebackq delims="" %* in ("""
              strcommand = strcommand & inputFile & """) do "
              strcommand = strcommand & "@dsquery.exe computer -name ""%~*"""
              strcommand = "%comspec% /c (" & _
                           strcommand & ")>""" & outputFile & """"
              
              
              Set objShell = CreateObject("WScript.Shell")
              objShell.run strcommand, 0, false
              
              
              wscript.echo "DSquery is running please wait a few minutes before opening the files"
              \Rems

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment

              Working...
              X