Solved

objetshell ipconfig causes multiple cmd promt windows to open

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 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

23 Experts available now in Live!

Get 1:1 Help Now