Status "Open" for Reg.exe Load when launched using the WshShell Exec Method

jknuce
jknuce used Ask the Experts™
on
I am loading a Win PE registry hive using a VBscript and the WshShell exec method. I am using the status property as a indicator to proceed. However, the status returned is always 0, even after the registry hive is loaded. Am I doing something wrong?
Option Explicit
Call ExecCmd("%comspec% /k reg.exe load HKLM\WIM_SOFTWARE ""C:\PE2-Image\mount\windows\system32\config\software""")

Sub ExecCmd(cmd)
  Dim objShell,objExec
  Set objShell = CreateObject("WScript.Shell")
  Set objExec = objShell.Exec(cmd)
	Do While objExec.Status = 0
		Wscript.echo "Process Still Open = " & objExec.Status
		wscript.Sleep 100
	Loop
		Wscript.echo "Process Closed = " & objExec.Status
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Tech Lead (Windows), Endpoint Device Management Services
Commented:
It looks at first glance because the process you are waiting for is cmd.exe, but you are calling it with /k which means keep the window open.  So the script opens Cmd.exe, runs reg.exe within it, but then because /k was specified the cmd.exe process never finishes.

Try changing the /k for a /c which means close after child process finishes.

Hope this helps,
Daz.

Author

Commented:
That appears to be it. I should have caught this, but it did not cross my mind because I was running another sample command (imagex /info), with the /k switch and it would close after reporting the information exepected. Thanks for solving my headache. You deserve all points and more. Thanks again.
Darren CollinsTech Lead (Windows), Endpoint Device Management Services

Commented:
You're welcome, thanks for the grade.  The other thing I was going to say was that I'm not sure you even to call reg.exe within a Cmd window:  Reg.exe is a program in its own right, so you may only just need to:
Call ExecCmd("reg.exe load HKLM\WIM_SOFTWARE ""C:\PE2-Image\mount\windows\system32\config\software""")

Open in new window


Regards,
Daz.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial