Solved

objetshell ipconfig causes multiple cmd promt windows to open

Posted on 2007-04-05
7
340 Views
Last Modified: 2012-05-05
I am writing scripts to run things like ipconfig and pathping and keep hitting same problem when trying to run them. The script below comes straight from microsoft http://www.microsoft.com/technet/scriptcenter/resources/tales/sg1002.mspx when it runs all i get is hundreds and hundreds of cmd windows. I'm copying the text into notepad and saving it as ipconfig.vbs and I run it using cscript ipconfig.vbs. why won't it run propley it also does the same if I use pathping or objshell.exec Ive tried running it in cmd prompt and powershell still same result. Only way to stop them running is to log off machine while they are running. Im running XP pro SP2. If I run them in cmd prompt window no problems works fine.

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /k ipconfig"

                           OR

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /k pingpath 192.168.1.1"
0
Comment
Question by:carlpotter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 18864077
did you try to change /k to /c ?


0
 
LVL 1

Author Comment

by:carlpotter
ID: 18865046
Yes I tried it both ways same result.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19114187
If you don't want to see the command prompts, while they will still be activating (but hidden), use:
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /k ipconfig", 0, True

The 0 states that it will be hidden, where 1 (default) is visible.  The True at the end tells the script to wait for the command prompt to finish it's task before continuing with the next statement.

Regards,

Rob.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 19256559
TheLearnedOne,

I just noticed an error in the method I posted, in that I used cmd /k instead of cmd /c, which means that multiple hidden instances of CMD.exe would have stayed running.

However, using
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /c ipconfig", 0, True

will cause each command prompt to exit when finished (the /c) and not be displayed to the user (the zero).  Therefore, I believe my answer would satisfy the requirements of this problem.

Regards,

Rob.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question