Solved

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

Posted on 2004-10-01
9
20,052 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
  • 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 500 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access - Capture pressed key onclick 4 33
How to debug this code 7 61
MS Access 03, TransferText, decimal places 8 69
Formula problem with Excel attachment 6 27
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…
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…
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…
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…

773 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