?
Solved

How to Make Wshell.Run "cmd.exe ..." Execute in a Hidden Window

Posted on 2004-10-01
9
Medium Priority
?
20,658 Views
Last Modified: 2012-05-05
I need the following VBS code to start cmd.exe in either a minimized window or a hidden window:

Wshell.Run "cmd.exe /C" & chr(34) & "reg.exe query " & regPath & " /s >>" & filePath & chr(34),1,True

I tried adding vbHide to the end of the line, but Wshell.Run doesn't like it. I also tried adding some extra perameters to the cmd.exe call, but those didn't help either.
0
Comment
Question by:Grime121
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 1

Expert Comment

by:untarded
ID: 12201621
Call Shell("cmd.EXE" /s [commands here], vbHide)
0
 
LVL 1

Expert Comment

by:untarded
ID: 12201660
If you are trying to register a .dll then use

Call Shell("REGSVR32.EXE /s [path]", vbHide)

you can view this by replacing vbHide with vbNormalFocus and/or receive a confirmation message by removing the /s (silent) command.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1500 total points
ID: 12201907
Here's a version that uses the Wscript.Shell object to do this.

    Dim objShell As New WshShell
    x = objShell.Run("Cmd /C Dir", vbHidden)

I think the problem is that you both used vbHide instead of vbHidden.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Grime121
ID: 12201923
reg.exe query is for getting information from the registry. It's then getting put into a text file. I can't seem to get call shell to work. Here's what I've been trying:

call shell("cmd.exe" /S & chr(34) & " reg.exe query " & regPath &  " /s >>" & filePath & chr(34),1,True,vbHide)

the error is type mismatch '[string:"cmd.exe"]'

I don't know a whole lot about VB scripts :(
0
 
LVL 1

Author Comment

by:Grime121
ID: 12201951
that one isn't for VB script I don't think, bluedevilfan. It's not liking the 'As New WshSell' line.
0
 
LVL 1

Author Comment

by:Grime121
ID: 12201981
Ok, I've got it. All I had to do was remove the ,1,True and put ,vbHidden instead. That was easy enough :P

Wshell.Run "cmd.exe /C /S " & chr(34) & " reg.exe query " & regPath &  " /s >>" & filePath & chr(34),vbHidden
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12202013
Doh!  Sorry, I keep forgetting to remove VB things from VBScript posts.
0
 
LVL 1

Expert Comment

by:untarded
ID: 12202117
This will work in VB or VBA I don't know about VB script.

'READ FROM WINDOWS REGISTRY

Dim b As Object
On Error Resume Next
Set b = CreateObject("wscript.shell")
r = b.RegRead([Value]

Is this a web app?
0
 
LVL 1

Author Comment

by:Grime121
ID: 12202337
no, it makes a software inventory by reading the displayname values under the uninstall registry key into a file seperated by commas. Then we have an SQL script that is going to read the files and add the info to a table. That way we can bring up a computer's info by doing a query on a php webpage, and we won't have to mess with manually entering the data.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

777 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