How can I hide ms-dos window when running a .bat file?

后端 未结 4 1417
感情败类
感情败类 2021-01-18 07:48

I am running a .bat file for my script (Scheduled Tak (CronJob)) per minute. When it runs, windows command prompt appears for a fiction of time.

My batch code like

4条回答
  •  北海茫月
    2021-01-18 08:29

    This VBScript creates a copy of your batch file in %Temp%, executes it silently and deletes it afterwards

    Dim fso
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Dim tempfolder
    
    Const TemporaryFolder = 2
    
    Dim WshShell, strCurDir
    
    Set WshShell = CreateObject("WScript.Shell")
    
    strCurDir    = WshShell.CurrentDirectory
    
    batch = "@ECHO OFF" & vbCrLf & _
            "C:\wamp\bin\php\php5.4.3\php.exe -f C:\wamp\www\tst\index.php"
    
    Set tempfolder = fso.GetSpecialFolder(TemporaryFolder)
    
    WshShell.CurrentDirectory = tempfolder
    
    i=1
    
    n=0
    
    While n <> 1
    
    If (fso.FileExists(i&".bat")) Then
    
      i = i + 1
    
    Else
      n = 1
    
    End If
    
    Wend
    
    Set File = fso.CreateTextFile(i&".bat",True)
    
    File.Write batch
    
    File.Close
    
    Dim batchfile
    
    batchfile = fso.GetAbsolutePathName(i&".bat")
    
    WshShell.CurrentDirectory = strCurDir
    
    WshShell.Run chr(34) & batchfile & Chr(34), 0, TRUE
    
    fso.DeleteFile batchfile
    

提交回复
热议问题