Solved

objetshell ipconfig causes multiple cmd promt windows to open

Posted on 2007-04-05
7
332 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now