Showing posts with label CMD. Show all posts
Showing posts with label CMD. Show all posts

Thursday, April 20, 2017

'C:\Program' is not recognized as an internal or external command

This seems to happen from time to time with programs that are very sensitive to command lines, but one option is to just use the DOS path instead of the Windows path. This means that C:\Program Files\ would resolve to C:\PROGRA~1\ and generally avoid any issues with spacing.

So your command would like below:

C:\PROGRA~1\.......

Saturday, February 4, 2017

Windows CMD, Clear All Browsers Cache & Everything

::@ECHO OFF
::cscript.exe "Test.vbs"
::pause
::exit;

@echo off

rem IE
taskkill /F /IM iexplore.exe
start "" "C:\Windows\System32\rundll32.exe" InetCpl.cpl,ClearMyTracksByProcess 255

:: Parse the Local AppData sub path
call :Expand xAppData "%%LocalAppData:%UserProfile%=%%"

set "xFirefox=\mozilla\firefox\profiles"
set "xChrome=\google\chrome\user data"
set "xOpera1=\Local\Opera\Opera"
set "xOpera2=\Roaming\Opera\Opera"

:: Start at the User directory
pushd "%UserProfile%\.."

taskkill /F /IM firefox.exe
taskkill /F /IM chrome.exe
taskkill /F /IM opera.exe

:: Loop through the Users
for /D %%D in (*) do if exist "%%~fD%xAppData%" (
    rem Check for Firefox
    if exist "%%~fD%xAppData%%xFirefox%" (
        rd /s /q "%%~fD%xAppData%%xFirefox%"
    )

    rem Check for Chrome
    if exist "%%~fD%xAppData%%xChrome%" (
        rd /s /q "%%~fD%xAppData%%xChrome%"
    )
 
 rem Check for Opera
    if exist "%%~fD%xAppData%%xOpera1%" (
        rd /s /q "%%~fD%xAppData%%xOpera1%"
    )
 if exist "%%~fD%xAppData%%xOpera2%" (
        rd /s /q "%%~fD%xAppData%%xOpera2%"
    )
)
popd
goto End


::::::::::::::::::::::::::::::
:Expand <Variable> <Value>
if not "%~1"=="" set "%~1=%~2"
goto :eof


:End
endlocal

Wednesday, February 1, 2017

How can I delete only PDF File from a folder using VBS

Option Explicit
Dim FileSystemObject, RootFolder, SubFolder, File
On Error Resume Next
 Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
 RootFolder = "C:\Users\PRITOM\Downloads"
 
 For Each File In FileSystemObject.GetFolder(RootFolder).Files
  If StrComp(Right(File.Path, 4), ".pdf", vbTextCompare) = 0 Then
   Wscript.Echo File.Path + " Deleted"
   FileSystemObject.DeleteFile File.Path, True
  End If
 Next
 
 For Each SubFolder In FileSystemObject.GetFolder(RootFolder).SubFolders
 Do
  If StrComp(SubFolder.Name, "management", vbTextCompare) = 0 Then
   Exit Do
  End If
  For Each File In FileSystemObject.GetFolder(SubFolder.Path).Files
   If StrComp(Right(File.Path, 4), ".pdf", vbTextCompare) = 0 Then
    Wscript.Echo File.Path + " Deleted"
    FileSystemObject.DeleteFile File.Path, True
   End If
  Next
 Loop Until True
 Next
On Error Goto 0

Tuesday, January 31, 2017

How to download files from command line in Windows, like Wget

Create a file named 'Download_File.vbs' with following contents:


DownloadUrl = "http://ovh.net/files/10Mb.dat"
FileLocation = "Download.dat"

Wscript.Echo "Start Downloading"
Set ObjXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
ObjXMLHTTP.open "GET", DownloadUrl, false, "username", "password"
'http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive'
'http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
ObjXMLHTTP.send()

If ObjXMLHTTP.Status = 200 Then
 Set ObjADOStream = CreateObject("ADODB.Stream")
 ObjADOStream.Open
 ObjADOStream.Type = 1
 'adTypeBinary

 ObjADOStream.Write ObjXMLHTTP.ResponseBody
 ObjADOStream.Position = 0
 'Set the stream position to the start

 Set ObjFSO = Createobject("Scripting.FileSystemObject")
 If ObjFSO.Fileexists(FileLocation) Then ObjFSO.DeleteFile FileLocation
 Set ObjFSO = Nothing

 ObjADOStream.SaveToFile FileLocation
 ObjADOStream.Close
 Set ObjADOStream = Nothing
 Wscript.Echo "Download Completed: " + FileLocation
Else
 Wscript.Echo "File Not Found"
End if

Set ObjXMLHTTP = Nothing

And create another file in the same folder named 'Download_Command.bat' with following contents & double click to download file from defined url:


@ECHO OFF
cscript.exe Download_File.vbs
pause
exit;