running CMD in silent
anybody know a switch or have a VBScript that will run the cmd windows in silent without showing any black windows?. I have tried the /c , but as you know the window does pop up and exits when done, so there anyway i can stop it from poping up at all?.
thanks
thanks
0 Comments
[ + ] Show comments
Answers (11)
Please log in to answer
Posted by:
selnomeria
11 years ago
Posted by:
Tone
17 years ago
Posted by:
bkelly
17 years ago
If your script does not generate any output, you might try running it with Wscript.exe instead of Cscript.exe. If you are not specifying the interpreter on the command line, you can set the default like so:
cscript //H:WScript
If there is output, each line appears in its own dialog box, so don't use this method unless there is no output currently echoing to the command prompt.
cscript //H:WScript
If there is output, each line appears in its own dialog box, so don't use this method unless there is no output currently echoing to the command prompt.
Posted by:
justinSingh
17 years ago
my script is listed below and i'm calling it from within my msi as an embedded custom action, but every time it launches through the MSI it pops 3 cmd windows that run in minimized mode. I have also tried this script with the 0 and 7 , but the results are the same and the funny thing is that if i run the script alone without calling it through the MSI i get no cmd windows...just a clean silent install. Anyone have any ideas?
on error resume next
Dim Username
Dim Workstation
Dim WshShell
Dim filesys
DIM arrBinaryValues()
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const strComputer = "."
Const Reg_SZ = 1
Const Reg_Expand_SZ = 2
Const Reg_Binary = 3
const reg_DWORD = 4
Const Reg_Multi_SZ = 7
Const HKEY_Current_User = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&strComputer&"\root\default:StdRegProv")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
'Determine if Intel 2200 Network Exists
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For each Item in colItems
If instr(Item.PNPDeviceID, "PCI\VEN_8086&DEV_4220") <> 0 Then 'If Card Exists
'Stop Wireless Service
wshShell.run "cmd /c net stop WZCSVC",0,True
'Save Network Settings
Set colItems = objWMIService.ExecQuery("SELECT Index FROM Win32_NetworkAdapter WHERE Name LIKE '%2200%'","WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
Pad = 4 - Len(objItem.Index)
strInterfaceNum = String(Pad, "0") & objItem.Index
Next
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"&strInterfaceNum
strValueName = "NetCfgInstanceId"
oReg.GetStringValue HKEY_Local_Machine,strKeyPath,strValueName,strValue
strNetCfgInstance = strValue
If strNetCfgInstance <> "" Then
strKeyPath = "SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
Set objMarker = objFSO.CreateTextFile("C:\temp\IntelWireless.txt", ForWriting)
For i=0 to UBound(arrValueNames)
If arrValueTypes(i) = REG_BINARY Then
strBinValue = ""
oReg.GetBinaryValue HKEY_Local_Machine,strKeyPath,arrValueNames(i),arrValue
For j=0 to UBOUND(arrValue)
strByte = CStr(hex(arrValue(j)))
If Len(strByte) = 1 Then strByte = "0"&strByte
strBinValue = strBinValue & strByte
Next
ObjMarker.WriteLine "Intel2200BG,EAPOL,REG_BINARY,"&arrValueNames(i)&","&strBinValue
End IF
Next
End IF
If strNetCfgInstance <> "" Then
strKeyPath = "SOFTWARE\Microsoft\WZCSVC\Parameters\Interfaces\"&strNetCfgInstance
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
For i=0 to UBound(arrValueNames)
If arrValueNames(i) <> "ActiveSettings" or arrValueNames(i) <> "LayoutVersion" Then
If arrValueTypes(i) = REG_BINARY Then
strBinValue = ""
oReg.GetBinaryValue HKEY_Local_Machine,strKeyPath,arrValueNames(i),arrValue
For j=0 to UBOUND(arrValue)
strByte = CStr(hex(arrValue(j)))
If Len(strByte) = 1 Then strByte = "0"&strByte
strBinValue = strBinValue & strByte
Next
ObjMarker.WriteLine "Intel2200BG,WZCSVC,REG_BINARY,"&arrValueNames(i)&","&strBinValue
ElseIF arrValueTypes(i) = REG_DWORD Then
oReg.GetDWORDValue HKEY_LOCAL_MAchine,strKeyPath,arrValueNames(i),dwValue
ObjMarker.WriteLine "Intel2200BG,WZCSVC,REG_DWORD,"&arrValueNames(i)&","&dwValue
End If
End If
Next
End IF
objMarker.Close
'Run Driver Install
wshShell.run "cmd /C c:\drivers\nc6220\n\iprodifx.exe /silent",0,True
'Restore Network Setting
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&strComputer&"\root\default:StdRegProv")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT Index FROM Win32_NetworkAdapter WHERE Name LIKE '%2200%'","WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
Pad = 4 - Len(objItem.Index)
strInterfaceNum = String(Pad, "0") & objItem.Index
Next
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"&strInterfaceNum
strValueName = "NetCfgInstanceId"
oReg.GetStringValue HKEY_Local_Machine,strKeyPath,strValueName,strValue
strNetCfgInstance = strValue
set objMarker = objFSO.OpenTextFile("C:\temp\IntelWireless.txt", ForReading)
test = oReg.GetStringValue(HKEY_Local_Machine,"SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance,,strValue)
If test <> 0 Then
oReg.CreateKey HKEY_Local_Machine,"SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance
End If
Do Until objMarker.AtEndOfStream
strTest = objMarker.Readline
arrInfo = split(strTest,",")
Select Case arrInfo(1)
Case "EAPOL"
strKeyPath = "SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance
Case "WZCSVC"
strKeyPath = "SOFTWARE\Microsoft\WZCSVC\Parameters\Interfaces\"&strNetCfgInstance
End Select
SELECT CASE arrInfo(2)
CASE "REG_BINARY"
Redim arrBinaryValues((Len(arrInfo(4))))
x=-1
For i = 1 to Len(arrInfo(4)) step 2
x = x + 1
arrBinaryValues(x) = CByte("&H"&MID(arrInfo(4),i,2))
Next
Redim Preserve arrBinaryValues(x)
test = oReg.SetBinaryValue(HKEY_Local_Machine,strKeyPath,arrInfo(3),arrBinaryValues)
CASE "REG_DWORD"
test = oReg.SetDWORDValue(HKEY_Local_Machine,strKeyPath,arrInfo(3),arrInfo(4))
END SELECT
Loop
objMarker.close
'Enable Wireless Configuration Service
wshShell.run "cmd /c net stop WZCSVC",0,True
End If
Next
Set WshShell = nothing
on error resume next
Dim Username
Dim Workstation
Dim WshShell
Dim filesys
DIM arrBinaryValues()
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const strComputer = "."
Const Reg_SZ = 1
Const Reg_Expand_SZ = 2
Const Reg_Binary = 3
const reg_DWORD = 4
Const Reg_Multi_SZ = 7
Const HKEY_Current_User = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&strComputer&"\root\default:StdRegProv")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
'Determine if Intel 2200 Network Exists
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For each Item in colItems
If instr(Item.PNPDeviceID, "PCI\VEN_8086&DEV_4220") <> 0 Then 'If Card Exists
'Stop Wireless Service
'Save Network Settings
Set colItems = objWMIService.ExecQuery("SELECT Index FROM Win32_NetworkAdapter WHERE Name LIKE '%2200%'","WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
Pad = 4 - Len(objItem.Index)
strInterfaceNum = String(Pad, "0") & objItem.Index
Next
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"&strInterfaceNum
strValueName = "NetCfgInstanceId"
oReg.GetStringValue HKEY_Local_Machine,strKeyPath,strValueName,strValue
strNetCfgInstance = strValue
If strNetCfgInstance <> "" Then
strKeyPath = "SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
Set objMarker = objFSO.CreateTextFile("C:\temp\IntelWireless.txt", ForWriting)
For i=0 to UBound(arrValueNames)
If arrValueTypes(i) = REG_BINARY Then
strBinValue = ""
oReg.GetBinaryValue HKEY_Local_Machine,strKeyPath,arrValueNames(i),arrValue
For j=0 to UBOUND(arrValue)
strByte = CStr(hex(arrValue(j)))
If Len(strByte) = 1 Then strByte = "0"&strByte
strBinValue = strBinValue & strByte
Next
ObjMarker.WriteLine "Intel2200BG,EAPOL,REG_BINARY,"&arrValueNames(i)&","&strBinValue
End IF
Next
End IF
If strNetCfgInstance <> "" Then
strKeyPath = "SOFTWARE\Microsoft\WZCSVC\Parameters\Interfaces\"&strNetCfgInstance
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
For i=0 to UBound(arrValueNames)
If arrValueNames(i) <> "ActiveSettings" or arrValueNames(i) <> "LayoutVersion" Then
If arrValueTypes(i) = REG_BINARY Then
strBinValue = ""
oReg.GetBinaryValue HKEY_Local_Machine,strKeyPath,arrValueNames(i),arrValue
For j=0 to UBOUND(arrValue)
strByte = CStr(hex(arrValue(j)))
If Len(strByte) = 1 Then strByte = "0"&strByte
strBinValue = strBinValue & strByte
Next
ObjMarker.WriteLine "Intel2200BG,WZCSVC,REG_BINARY,"&arrValueNames(i)&","&strBinValue
ElseIF arrValueTypes(i) = REG_DWORD Then
oReg.GetDWORDValue HKEY_LOCAL_MAchine,strKeyPath,arrValueNames(i),dwValue
ObjMarker.WriteLine "Intel2200BG,WZCSVC,REG_DWORD,"&arrValueNames(i)&","&dwValue
End If
End If
Next
End IF
objMarker.Close
'Run Driver Install
'Restore Network Setting
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&strComputer&"\root\default:StdRegProv")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT Index FROM Win32_NetworkAdapter WHERE Name LIKE '%2200%'","WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
Pad = 4 - Len(objItem.Index)
strInterfaceNum = String(Pad, "0") & objItem.Index
Next
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"&strInterfaceNum
strValueName = "NetCfgInstanceId"
oReg.GetStringValue HKEY_Local_Machine,strKeyPath,strValueName,strValue
strNetCfgInstance = strValue
set objMarker = objFSO.OpenTextFile("C:\temp\IntelWireless.txt", ForReading)
test = oReg.GetStringValue(HKEY_Local_Machine,"SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance,,strValue)
If test <> 0 Then
oReg.CreateKey HKEY_Local_Machine,"SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance
End If
Do Until objMarker.AtEndOfStream
strTest = objMarker.Readline
arrInfo = split(strTest,",")
Select Case arrInfo(1)
Case "EAPOL"
strKeyPath = "SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\"&strNetCfgInstance
Case "WZCSVC"
strKeyPath = "SOFTWARE\Microsoft\WZCSVC\Parameters\Interfaces\"&strNetCfgInstance
End Select
SELECT CASE arrInfo(2)
CASE "REG_BINARY"
Redim arrBinaryValues((Len(arrInfo(4))))
x=-1
For i = 1 to Len(arrInfo(4)) step 2
x = x + 1
arrBinaryValues(x) = CByte("&H"&MID(arrInfo(4),i,2))
Next
Redim Preserve arrBinaryValues(x)
test = oReg.SetBinaryValue(HKEY_Local_Machine,strKeyPath,arrInfo(3),arrBinaryValues)
CASE "REG_DWORD"
test = oReg.SetDWORDValue(HKEY_Local_Machine,strKeyPath,arrInfo(3),arrInfo(4))
END SELECT
Loop
objMarker.close
'Enable Wireless Configuration Service
End If
Next
Set WshShell = nothing
Posted by:
KrisBcn
17 years ago
Posted by:
bheers
17 years ago
Posted by:
jamsek19
17 years ago
Justin,
try this way.:
But sometimes this function returns me an error (I do not know why) therefore I need use your function on this way:
with winstate = 7 appears just minimized window in TaskBar.
Best regards
Andreo
try this way.:
Function RunCmd(acmd, ByRef a_cmd_out)
Set ShellObj = CreateObject("WScript.Shell")
Set ExecObj = ShellObj.Exec(a_cmd)
If Err.number <> RTN_OK Then
RunCMD = Err.Number
Wscript.Echo "Running " & a_cmd & " failed."
Set ExecObj = Nothing
Set ShellObj = Nothing
Exit Function
End If
i = 0
Do While ExecObj.Status = 0
Wscript.Sleep 1
i = i + 1
Loop
If Err.Number = RTN_OK Then
RunCMD = ExecObj.ExitCode
Else
RunCMD = Err.Number
End If
a_cmd_out = ExecObj.StdOut.ReadAll
Set ExecObj = Nothing
Set ShellObj = Nothing
End Function
By VBScript 5.6 help:
This function runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.
The Exec method returns a WshScriptExec object, which provides status and error information about a script run with Exec along with access to the StdIn, StdOut, and StdErr channels. The Exec method allows the execution of command line applications only. The Exec method cannot be used to run remote scripts. Do not confuse the Exec method with the Execute method (of the WshRemote object).
But sometimes this function returns me an error (I do not know why) therefore I need use your function on this way:
Function RunWindowedCMD(a_cmd)
winState = 7 ' Displays the window as a minimized window. The active window remains active.
' can be also 10 - Sets the show-state based on the state of the program that started the application.
Set ShellObj = CreateObject("WScript.Shell")
RunWindowedCMD = ShellObj.Run( a_cmd, winState, True)
Wscript.echo "CMD return " & RunWindowedCMD
Set ShellObj = Nothing
End Function
with winstate = 7 appears just minimized window in TaskBar.
Best regards
Andreo
Posted by:
justinSingh
17 years ago
Posted by:
kardock
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.