2012-11-27 18 views
5

मैं अपनी लिपि (अनुसूचित Tak (CronJob)) प्रति मिनट के लिए .bat फ़ाइल चला रहा हूं। जब यह चलता है, विंडोज कमांड प्रॉम्प्ट समय की कल्पना के लिए प्रकट होता है।.bat फ़ाइल चलाते समय मैं ms-dos विंडो को कैसे छिपा सकता हूं?

इस तरह मेरा बैच कोड;

@ECHO OFF 
C:\wamp\bin\php\php5.4.3\php.exe -f "C:\wamp\www\tst\index.php" 

यह चलाने के दौरान मैं इस विंडो को कैसे छुपा सकता हूं?

उत्तर

6

उपयोग एक VBScript

Set objShell = WScript.CreateObject("WScript.Shell") 
objShell.Run("C:\yourbatch.bat"), 0, True 

भागो कि जो अपने बैच फ़ाइल छिपा चलेंगे।

+0

आप @Bali सी –

+0

धन्यवाद @prestack कोई चिंता नहीं :) –

+0

+1 हमेशा अपने काम देखो और अधिक पेशेवर बनाता है जब वहाँ कमांड प्रॉम्प्ट – Teddy

3

मुझे वीबीस्क्रिप्ट समाधान पसंद नहीं है। जैसे

nircmd.exe win hide ititle "cmd.exe" 

या सभी cmd खिड़कियां छुपा से बचने के लिए title कमांड के साथ पहली बार अपने बैच शीर्षक कस्टम बनाने के लिए,:

अपने %systemroot%\system32 फ़ोल्डर में डाउनलोड

और कॉपी nircmd.exe, तो अपने बैच की पहली पंक्ति को यह आदेश जोड़ने इस:

title MyBatch 
nircmd.exe win hide ititle "MyBatch" 
2

यह VBScript% अस्थायी% में अपने बैच फ़ाइल एक कॉपी बन जाती है, यह चुपचाप निष्पादित करता है और यह बाद में हटा देता है

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 
+0

धन्यवाद चला सकता हूँ की कोई क्षणिक चमक रहे हैं। यह सबसे अच्छा काम करता है – codeMonger123

0

मुझे पता है कि पोस्ट पुराना है लेकिन यहां मेरा समाधान है, डॉस्टिप्स से एग्रमैन ने मुझे इस स्क्रिप्ट को कोड करने में मदद की, यह बहुत उपयोगी है।

@echo off &setlocal EnableExtensions DisableDelayedExpansion 

:: Change the working directory to the directory of the batch file. 
:: If the first passed argument was ~e~ (that is, the batch file was called from the VBScript) 
:: then shift the parameters by one and continue at label :elevated 
cd /d "%~dp0"&if "%~1"=="~e~" (shift&goto :elevated) 

:: Assign the passed arguments to variable param. 
set "param=%*" 

:: NET SESSION fails if the batch code doesn't run with elevated permissions. 
:: Assign variable __verb to "open" if the batch file runs elevated or to "runas" if it doesn't run elevated 
>nul 2>&1 net session &&(set "__verb=open")||(set "__verb=runas") 

:: Assign the name of the VBScript to variable vbs. 
:: Assign the full name of the batch file to variable me. 
:: Enable delayed variable expansion. 
set "vbs=%temp%\uac.vbs"&set "me=%~f0"&setlocal enabledelayedexpansion 

:: If arguments were passed, prepare them to be passed from within the VBScript by doubling the quotation marks. 
if defined param set "param=!param:"=""!" 

:: Write the VBScript. The ShellExecute method will run the batch file in a cmd.exe process where ~e~ will be passed as 
:: first argument followed by the original arguments (saved in param). The UAC will be invoked if __verb was set to "runas". 
:: Elsewise the UAC will not be invoked. For further information about the ShellExecute method see: 
:: https://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx 
>"!vbs!" echo CreateObject("Shell.Application").ShellExecute "!comspec!", "/c """"!me!"" ~e~ !param!""", "", "%__verb%", 0 

:: Run the VBScript in a cscript.exe process. 
:: Delete the VBScript file. 
:: Quit the batch execution. 
cscript //nologo "!vbs!"&del "!vbs!"&goto :eof 

:elevated 
::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
:: Do your elevated stuff here...