/build/static/layout/Breadcrumb_cap_w.png

How to hide a command prompt during scripting

Issue:

The Dell Kace agent opens a blank command processor window. Users can close the window causing the script to end prematurely.

Script type: Online shell script.

Script text: cscript hidecmd.vbs

Dependencies: HideCMD.VBS, Test.bat

--- Test.bat ---

echo do something here

--- end test.bat

---- HideCMD.VBS ---

dim NameOfBatch, CurrentDirectory, FullPath
NameOfBatch = "test.bat"

'Get current directory where the batch file is running

CurrentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))

' for debugging only WScript.Echo currentDirectory

FullPath = CurrentDirectory&NameOfBatch

'From MS website on how to hide a command processor window

Const HIDDEN_WINDOW = 12
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
 
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create(FullPath, CurrentDirectory, objConfig, intProcessID)
---- end HideCMD.VBS ---


Comments

  • Brian, Thanks for this vbs!

    Next, how can I get the next task item to launch? The cscript launching the vbs works but in my script it needs to wait for the bat to comple before the next itme can do its thing; extract my concatinated zip file. The result is run failure, obviously because it had nothing to extract or it appeared corrupt. - worzie 10 years ago
  • Oh, this is where you are using concatenation on part files to join to one large zip. Just add this to your copy command
    start /wait copy /b partfile.* file.zip
    That'll force that long copy process to wait until it's done before moving on. - briancollins 10 years ago
This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ