Running a CMD or BAT in silent mode

前端 未结 11 1087
夕颜
夕颜 2020-11-28 03:51

How can I run a CMD or .bat file in silent mode? I\'m looking to prevent the CMD interface from being shown to the user.

11条回答
  •  暖寄归人
    2020-11-28 04:09

    I'm pretty confident I like this method the best. Copy and paste the code below into a .vbs file. From there you'll call the batch file... so make sure you edit the last line to specify the path and name of the batch file (which should contain the file you'd like to launch or perform the actions you need performed)

    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("C:\PathOfFile\name.bat", null, objConfig, intProcessID)
    

    It definitely worked for me. Comments are welcomed :)

提交回复
热议问题