Solved

objetshell ipconfig causes multiple cmd promt windows to open

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

710 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