This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1101. |
Solve : Open .pdfs at same time? |
|
Answer» I would like a batch FILE that SELECTS all .pdf files in a folder and then presses the enter KEY which will open those files in Adobe. |
|
| 1102. |
Solve : How can i change this batch?? |
|
Answer» i SAW this batch file on DosTips i saw this batch file on DosTipsThen why don't you ask the question on the DosTips forums? |
|
| 1103. |
Solve : Baruch to replace space in file name with underscore.? |
|
Answer» Baruch to replace space in file name with underscore. |
|
| 1104. |
Solve : batch file to run vbscript in all subfolders? |
|
Answer» Hello, |
|
| 1105. |
Solve : Copy or move wildcard foloders up to root.? |
|
Answer» On my PC I have downloaded a bunch of MP3 files during the past year. Sad to say, I am a POOR ORGANIZER. I don't always save the files in the save place or move them to the same place. I forget things. The above will copy all folders taht match to the J: drive and include the contents of the folders. Reading this, I am thinking your looking to Collapse the tree then so if you had the following: Code: [Select]J:\data\1 J:\data\2 J:\data\3\4\5\6 That you would end up with: Code: [Select]J:\1 J:\2 J:\3 J:\4 J:\5 J:\6 ? First of all I am pretty SURE it wouldnt be able to be all done on same drive due to cyclic error issue. All data would need to be moved elsewhere and then brought back to J: I believe. Drawing a blank on best method to collapse the tree. Its really easy to just grab all files and throw them into root of J:, but if you have files with same file names that will be a problem. You only want it to be folders 1 level deep then as I showed above or am i not getting what your trying to do? |
|
| 1106. |
Solve : Can't set variable in for loop even when setlocal enabledelayedexpansion is on? |
|
Answer» Okay I have this script which uses a for loop to search through all batch files on the computer, I want to disable them by turning them Into a text file. However I need to modify a variable but it will not set. Thank you, I'll have to check it out tomorrow, I'll swing back back and tell you if it worked for me.I think the issue I was having was not being able to see the values within the loop, because when I typed echo "%%~DpnxA" and echo "%%X", nothing appeared except "", so it made it difficult to make debug notes within the script.Is there a way to make it ignore file paths that don't satisfy or end with the .bat extension before its path is set to the variable and modified to an .txt extension? I know everything isnt possible in batch but thank you anyway for the help. Quote from: zask on February 02, 2017, 03:24:07 PM when I typed echo "%%~DpnxA" and echo "%%X",They appear for me. Where and when were you "typing" these things? When I'm trying to put it in !file1! & !file2! Running inside the infinite for loop, it just didn't appear for some reason Quote from: zask on February 02, 2017, 06:07:42 PM When I'm trying to put it in !file1! & !file2! Running inside the infinite for loop, it just didn't appear for some reason, I don't know why but I'll try to figure it out.What do you mean I would be interested to know what they are going to do? Quote from: zask on February 02, 2017, 06:33:14 PM What do you mean you would be interested to know what they are going to do? I'm trying to mimic the assoc command without actually setting every file's extension to a different extension permanently until you change it back, well it would change it like that, but it wouldn't permanently associate every extension for every file after that. If sure you understand what I mean if you have ever used the assoc command. |
|
| 1107. |
Solve : batch file to convert text file into excel? |
|
Answer» Hello Guys, Batch files cannot read or write excel files. If you need to read or write excel files then use Vbscript, Jscript or Powershell.Your logic is backward. He does not need a batch file to read or write Excel files. He needs to know how to import data into Excel. Quote from: soybean on February 01, 2017, 08:39:53 AM Your logic is backward. He does not need a batch file to read or write Excel files. He needs to know how to import data into Excel.No. I import (write) text files into excel all the time with Vbscript. There is nothing illogical about it. Quote from: Squashman on February 01, 2017, 08:56:15 AM I import (write) text files into excel all the time with Vbscript. There is nothing illogical about it.Absolutely. |
|
| 1108. |
Solve : Call .bat and go to label?? |
|
Answer» I googled it, thought I found a solution but it doesn't seem to work. I think I saw a thread on this a while back but I can't find it (the search NEVER seems to work for me on the forum here for some reason, I get "no results" no matter what I search for). I'm USING Win7 if that makes a difference. I found something that said extensions had to be enabled for this to work then checked my registry according to another site and determined they are enabled. I also tried setlocal enableextensions at the head of test.bat, that didn't work either. You do realise that this code will always go to :two after test.bat has finished? I'd forgotten about that, but as it turned out it worked OK with this particular example since test.bat would either call test1.bat again or exit depending on the selection chosen. I can see the error of my ways though if set /p didn't pause test.bat waiting for user input it would finish and then go back to test1.bat :two. Here's what I came up with, I guess GOING to :EOF after the pause would terminate test1.bat so it doesn't return after test.bat finishes (and :two doesn't need it because we're at EOF when it returns to test.bat anyway)? test1.bat Code: [Select]echo off goto %1 echo. echo. echo. echo this shouldn't ever show :one echo. echo. echo. echo this is selection 1 pause ::call test.bat goto :EOF :two echo. echo. echo. echo this is selection 2 pause That seems to do what I wanted to do anyway, still working on catching wrong or missing labels. Again, I appreciate the help. Jim Quote from: JRobinson on January 29, 2017, 12:02:15 AM Here's what I came up with, I guess going to :EOF after the pause would terminate test1.bat so it doesn't return after test.bat finishes (and :two doesn't need it because we're at EOF when it returns to test.bat anyway)?Perfect! Sometimes with labels instead of the implicit :eof I put a final one called :end or whatever and have something like this :end echo Script finished pause |
|
| 1109. |
Solve : Batch/Multi rename only files with a specific range? |
|
Answer» Hello, i hope someone can help me with this. |
|
| 1110. |
Solve : Creating a batch file to run RDP and connect? |
|
Answer» Hi, I am a complete novice with zero experience. |
|
| 1111. |
Solve : Batch file "IF" error "GoTo" EOF commandline? |
|
Answer» Hi, I didn't know this forum existed until today, how awesome!! The batch file has four commands, three of which are to a game engine required to compile maps.Since we are not telepaths, the actual code would make the task of deciding if we can help a lot easier. You can clean up personal references or sensitive stuff. Sorry, I didn't think that the path and filename specifics would make a difference. Code: [Select]"C:\MOHAAT~1\Q3map.exe" -v -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox "C:\MOHAAT~1\Q3map.exe" -vis -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox "C:\MOHAAT~1\MOHlight.exe" -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox "C:\Program Files (x86)\Microsoft VISUAL Studio\VB98\My Projects\Map Mate\041\done.exe" As I said, the batch works well except when error occurs with either stage of the compile (first three command lines)You could check for the exit code from the apps you are running, Q3map.exe and MOHlight.exe, assuming that they give a nonzero exit code when the errors of which you speak occur. Do these programs give console output? You could try something like this using the && (zero ERRORLEVEL) and || (nonzero errorlevel) tests Code: [Select]Echo Starting sequence... echo Starting task 1 of 3 "C:\MOHAAT~1\Q3map.exe" -v -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && (echo OK) || (goto error) echo starting task 2 of 3 "C:\MOHAAT~1\Q3map.exe" -vis -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && (echo OK) || (goto error) echo Starting task 3 of 3 "C:\MOHAAT~1\MOHlight.exe" -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && && (echo OK) || (goto error) goto done :error echo ERROR :done "C:\Program Files (x86)\Microsoft Visual Studio\VB98\My Projects\Map Mate\041\done.exe"Correction (accidentally doubled the &&) Code: [Select]echo Starting task 3 of 3 "C:\MOHAAT~1\MOHlight.exe" -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && (echo OK) || (goto error)Sorry for not getting back to this sooner, life got in the way. Thank you, I will give that a try. edit: Sorry I skipped this.. Quote from: Salmon Trout on January 07, 2017, 07:20:39 AM .........Yes, they do, for several minutes.Whoohoo!! It worked perfectly. Thank you, Salmon Trout. Sorry, I don't have any erroneous maps so I had to ask around for some so I could test the bat. lolI can't see how to mark the thread as "Resolved". |
|
| 1112. |
Solve : GTR and LSS seem to fail for large sizes? |
|
Answer» Was trying to determine which ISOs are BluRay and which are DVD and I picked 9gb as the size cutoff. %~z1 gave the correct size but GTR failed to calculate properly. Maybe I did something wrong or perhaps there is another way to differentiate the two types. ECHO OFF SET SIZELIMIT=9000000000 SET FILESIZE=%~z1 IF %FILESIZE% GTR %SIZELIMIT% GOTO No ECHO DVD PAUSE GOTO :EOF :No ECHO BluRay PAUSE GOTO :EOF Thanks for looking.Correct. Because batch files can only handle 32bit Integers.Change your IF comparison to use quotes. Code: [Select]IF "%FILESIZE%" GTR "%SIZELIMIT%" Goto No ECHO OFF echo Wscript.echo eval(WScript.Arguments(0)) > evaluate.vbs echo %1 %~z1 SET SIZELIMIT=9000000000 SET FILESIZE=%~z1 for /f "delims=" %%A in ('cscript evaluate.vbs "%filesize% > %sizelimit%"') do set result=%%A If %result% equ -1 goto no ECHO DVD PAUSE GOTO :EOF :No ECHO BluRay PAUSE GOTO :EOF The suggestion to use quotes did not work. Possibly only the first letter is checked. However, Salmon's evaluate.vbs worked fine. Sizeof or strlen would have worked OK if they existed.Well I tested it a few times with quotes and it worked. No it does not just compare the first character.Strange - I tested it on both the Win10 command prompt and the Micro$oft VS 14 one and it appears only to check the first character. Are you using the power shell or some other extension? You know you can copy and paste text from the cmd window. Wouldn't that be a lot EASIER then posting a SCREEN shot? Quote from: BeemerBiker on February 14, 2017, 07:12:39 AM Strange - I tested it on both the Win10 command prompt and the Micro$oft VS 14You realize there is no difference between the two? You are just in a different directory.As Squashman stated, it doesn't only compare the first character. The confusion is in expecting a numeric comparison. The use of quotation marks makes it no longer a numeric comparison, instead, it is comparing the two values as strings. Code: [Select]if "2" LSS "10" (echo lower) else (echo higher) outputs "higher", becasue it is comparing the string "2" to the string "10" alphanumerically. The "solution" is to have it use leading zeroes: Code: [Select]if "02" lss "10" (echo lower) else (echo higher) outputs "lower". using VBScript via evaluate.vbs tends to be the better alternative if you want to exceed the rather basic math capabilities of batch. Quote from: BeemerBiker on February 13, 2017, 04:30:14 PM Sizeof or strlen would have worked OK if they existed.echo off set mystring=9000000000 call :strlen %mystring% echo string length %slen% goto end :strlen set slen=0 set tempstring=%1 :loop set tempstring=%tempstring:~0,-1% set /a slen+=1 if "%tempstring%"=="" goto :eof goto loop :end echo done pause |
|
| 1113. |
Solve : command prompt to samsung galaxy j2 model SM-J200F? |
|
Answer» Greetings, |
|
| 1114. |
Solve : Find_Suspicious_SVCHOST_Paths.bat? |
|
Answer» Hi
REM First release on 01/03/2017 04:45 REM Updated on 07/03/2017 04:05 Set "ProcessName=SVCHOST" Set "Tmp_Services=%Tmp%\%~n0.txt" If Exist "%Tmp_Services%" Del "%Tmp_Services%" Set "ProcessLog=%Tmp%\%ProcessName%.log" If Exist "%ProcessLog%" Del "%ProcessLog%" Set "Legits_Services_SVCHOST=%~dp0Legits_Services_%ProcessName%.txt" Set "Legit_Location=%windir%\system32\svchost.exe" Set "LogFile=%~dp0%ProcessName%_ProcessList.txt" Set "Suspicious_LogFile=%~dp0%ComputerName%_%ProcessName%_Suspicious_Paths.txt" Title Finding all instances and paths of "%ProcessName%" by Hackoo 2017 If Exist "%LogFile%" Del "%LogFile%" Set /A Counter=0 setlocal enableDelayedExpansion for /F "skip=1" %%a in ('WMIC Path win32_process where "name like '%%%ProcessName%%%'" get commandline') do ( for /F "delims=" %%b in ("%%a") do ( Color 0A set /A Counter+=1 set "p=%%b" for /f %%f in ('echo !p! ^|Findstr /LI "%Legit_Location%"') do ( echo [!Counter!] : !p! ) ( echo "!p!" )>>"%LogFile%" ) ) Powershell.exe Get-WmiObject Win32_Process ^| select ProcessID,ProcessName,Handle,commandline,ExecutablePath ^| Out-File -Append "%ProcessLog%" -Encoding ascii TYPE "%ProcessLog%" | find /i "%Legit_Location%" > "%Tmp_Services%" ( echo( echo Those are legitimes services of "%ProcessName%.exe" Tasklist /SVC /FO TABLE /FI "IMAGENAME eq %ProcessName%.exe" )>con ( echo( echo Those are legitimes services of "%ProcessName%.exe" Tasklist /SVC /FO TABLE /FI "IMAGENAME eq %ProcessName%.exe" )>> "%Tmp_Services%" CMD /U /C Type "%Tmp_Services%" > "%Legits_Services_SVCHOST%" echo( Echo All instances of "%ProcessName%" in this path "%Legit_Location%" are legitimes services echo( echo Hit any KEY to look for a SUSPICIOUS "%ProcessName%" paths Findstr /LVI "%Legit_Location%" "%LogFile%" > "%Suspicious_LogFile%" PAUSE>nul Start "" "%Suspicious_LogFile%" Start "" "%Legits_Services_SVCHOST%" & exit ::*********************************************************************************************Do you have a question? Quote from: Squashman on March 07, 2017, 07:29:49 AM Do you have a question?Yes ! I have just tested this script under Windows 7 (32 bits) ! I wonder if there is another legit location of svchost.exe on (64 bits machines) ? for example should i check it on sysWOW64 location or not ? Thank you ! |
|
| 1115. |
Solve : search for mutiple txt files and copy file name and path into one txt file? |
|
Answer» How can I search for multiple txt files with the partly same name under multiple subfolders and COPY that filename and path to that file into one txt file. WHERE (Windows 2003 + )I know but I don't know how to put it in batch for my caseI have managed to make a list with paths but cant make it to write at the end of path if file is logH.txt or logL.txt Code: [Select]for /f "tokens=*" %a in ('dir .\log /B /S) do echo %~fa %~za >> d:\users\drivers\mike\testfolder\List.txtthis one says can not find file Code: [Select]for /f "tokens=*" %a in ('dir .\new /s /b /A-D "*.txt"') do echo %~fa %~za >> d:\users\drivers\mike\testfolder\List.txtHi You can give a try for this batch file : Search_LogFiles.bat Code: [Select]echo off Title Searching files . . . Color 9E & Mode con cols=75 lines=3 set "Master_Folder=C:\users" set "Pattern=logfile*.txt" set "LogSearch=%~dpn0.txt" echo( echo Please wait ... Searching "%Pattern%" files is in progress ... Where /R "%Master_Folder%" "%Pattern%" /F >"%LogSearch%" 2>&1 start "" "%LogSearch%"I have one problem here. loghi*.txt files are also in folder logfiles and in its subfolder new it is only one. And I need only file from subfolder new, this script finds also fles in folder logfiles. d:\users\john\logfiles\logfileH12022017.txt this file I am looking for to write in txt d:\users\john\logfiles\new\logfileH12022017.txt Quote from: Blisk on May 23, 2017, 12:07:37 AM I have one problem here. In this case you can try like that if i understood what you mean ? Code: [Select]echo off Title Searching files . . . Color 9E & Mode con cols=75 lines=3 set "Master_Folder=C:\users" set "Pattern=logfile*.txt" set "LogSearch=%~dpn0.txt" echo( echo Please wait ... Searching "%Pattern%" files is in progress ... Where /R "%Master_Folder%" "%Pattern%" /F >"%LogSearch%" 2>&1 Type "%LogSearch%" | find /I "new" > NewLog.txt start "" NewLog.txtI named that batch test.bat and it also creates test.txt where all logfile*.txt are in, from \logfiles folder too which is wrong. But at the same time it opens notepad named NewLog.txt where is result which I want, from folder \new How to do this to get results saved in NewLog.txt and there is no test.txt created and doesn't open notepad.exe but save directly to NewLog.txt file. And is it possible to get result in txt file from this logfileH12022017.txt to this logfileH? Hot Quote from: Blisk on May 23, 2017, 02:37:06 AM I named that batch test.bat and it also creates test.txt where all logfile*.txt are in, from \logfiles folder too which is wrong.Did you mean something like that ? Code: [Select]echo off Title Searching files . . . Color 9E & Mode con cols=75 lines=3 set "Master_Folder=C:\users" set "Pattern=logfile*.txt" Rem Name it as you want set "LogSearch=TextFile_As_You_want_here.txt" echo( echo Please wait ... Searching "%Pattern%" files is in progress ... Where /R "%Master_Folder%" "%Pattern%" /F >"%LogSearch%" 2>&1 REM We filter our search into file named NewLog.txt Type "%LogSearch%" | find /I "new" > NewLog.txt Rem We delete the "%LogSearch%" If exist "%LogSearch%" Del "%LogSearch%"Thank you this is what I want. |
|
| 1116. |
Solve : [Batch] Extracting targets from shortcuts Links? |
|
Answer» Hi Why does it write the same temp vbs file every time it needs to process a shortcut, and delete it again?Thank you for your remark and i changed it to this code : Code: [Select]echo off Title Extracting target from shortcut (*.url) and (*.lnk) by Hackoo 2017 Mode con cols=62 lines=3 & color 9E Set "Log=%~dp0TARGET_LINK_PATHS.txt" Set "TmpVbs=%Tmp%\%~n0.vbs" Set "Links=url lnk" If exist "%Log%" Del "%Log%" Set "Folders=%UserProfile%\Desktop %Public%\Desktop %AllUsersprofile%" For %%i in (%Links%) Do ( For %%F in (%Folders%) Do ( Cls Echo ***************************************************************** Echo "%%F" for "*.%%i" Links (echo. & echo Scanning "%%F" for "*.%%i" Links ...)>CON Echo ***************************************************************** Echo; For /f "delims=" %%L in ('Dir /b /s "%%F\*.%%i"') do ( echo "%%L" & Call:ExtractTarget "%%L" echo -------------------------------------------------------- ) ) )>>"%Log%" Start "" "%Log%" If Exist "%Tmpvbs%" Del "%Tmpvbs%" Exit ::************************************************************************* :ExtractTarget <Link> ( echo set Ws = CreateObject("WScript.Shell"^) echo set Lnk = Ws.Createshortcut(WScript.Arguments(0^)^) echo WScript.echo Chr(34^) ^& Lnk.TargetPath ^& Chr(34^) )>"%Tmpvbs%" cscript //nologo "%Tmpvbs%" "%~1" Exit /b ::*************************************************************************It still does it. Quote from: Salmon Trout on February 09, 2017, 03:50:36 AM It still does it.Ok Can you provide me a better solution with code to optimize this later Thank you !You wrote that code, didn't you? Just move the part that creates the vbscript out of the subroutine and put it at the start of the script.Ok I think this is better Code: [Select]echo off Title Extracting target from shortcut (*.url) and (*.lnk) by Hackoo 2017 Mode con cols=62 lines=3 & color 9E Set "Log=%~dp0TARGET_LINK_PATHS.txt" Set "TmpVbs=%Tmp%\%~n0.vbs" ::************************************************************************ ( echo set Ws = CreateObject("WScript.Shell"^) echo set Lnk = Ws.Createshortcut(WScript.Arguments(0^)^) echo WScript.echo Chr(34^) ^& Lnk.TargetPath ^& Chr(34^) )>"%Tmpvbs%" ::************************************************************************ Set "Links=url lnk" Set "Folders=%UserProfile%\Desktop %Public%\Desktop %AllUsersprofile%" For %%i in (%Links%) Do ( For %%F in (%Folders%) Do ( Cls Echo ***************************************************************** Echo "%%F" for "*.%%i" Links (echo. & echo Scanning "%%F" for "*.%%i" Links ...)>CON Echo ***************************************************************** Echo; For /f "delims=" %%L in ('Dir /b /s "%%F\*.%%i"') do ( echo "%%L" & Call:ExtractTarget "%%L" echo -------------------------------------------------------- ) ) )>>"%Log%" Start "" "%Log%" If Exist "%Tmpvbs%" Del "%Tmpvbs%" Exit ::************************************************************************* :ExtractTarget <Link> cscript //nologo "%Tmpvbs%" "%~1" Exit /b ::************************************************************************* |
|
| 1117. |
Solve : Help Im Stuck with Batch Variables in Loops? |
|
Answer» First of all here is my script. |
|
| 1118. |
Solve : net use not going to EOF? |
|
Answer» in an simple "IF" statement, I want, after the text, for it to GOTO :EOF. |
|
| 1119. |
Solve : Load Random File from Folder location Question? |
|
Answer» Was wondering if there was an easier way vs naming files 1, 2, 3, 4, 5, 6, 7 .... to launch an executable with random file appended to it within " " to when running an EXE have it pick from any number of many files at random. I right now can do this all in C++ with file names that are numbers. With C++ I can concatenate the random number output generated to .mp3 for example and then perform a system call to the player.exe "4.mp3" for example to play the 4th file NAMED 4.mp3. But I'd like the files to all keep their original file names without having to rename all files to numbers.mp3 since sometimes I want to manually go in and launch a file to listen to and navigating in a folder with numbers without a list of what is what it is all a mess of unknown. |
|
| 1120. |
Solve : installing multiple software from network? |
|
Answer» Hi, |
|
| 1121. |
Solve : Cannot read text in script? |
|
Answer» I don't think I have found a bug, but I have surely uncovered a problem. |
|
| 1122. |
Solve : Wifi Password Recovery? |
|
Answer» Hi Does it not work on machines that aren't in French? I can't see any reason why it wouldn't.Here is the problem : Consider if you have a German or spanich machine : this will not work with this piece of code : Code: [Select]for /f "tokens=2 delims=:" %%a in ('netsh wlan show profile name^="%Input%" key^=clear ^|find /I "Cont"') do ( set "pwd=%%a" )Because when you want to find this string with the command Find /I "Cont" you will not find it I update this script in order to find and display all SSIDs saved on a PC with their passwords and save them in a text file. and here is its screenshot : Wifi Passwords Recovery.bat Code: [Select]echo off & setlocal enabledelayedexpansion Set "Copyright=by Hackoo 2017" Title %~n0 %Copyright% Mode con cols=75 lines=8 cls & color 0A & echo. echo *********************************************** echo %~n0 %Copyright% echo *********************************************** echo( if _%1_==_Main_ goto :Main Set Count=0 Set L=0 :getadmin echo %~nx0 : self elevating set vbs=%temp%\getadmin.vbs ( echo Set UAC = CreateObject^("Shell.Application"^) echo UAC.ShellExecute "%~s0", "Main %~sdp0 %*", "", "RUNAS", 1 )> "%vbs%" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" goto :eof ::************************************************************************************* :Main Call :init Call :CountLines Set "PasswordLog=%~dp0Wifi_Passwords_on_%ComputerName%.txt" %Mod% echo( echo *********************************************** echo %~n0 %Copyright% echo *********************************************** echo( Call :Color 0E " [Num][SSID] ============== Password" 1 echo( ( echo *********************************************** echo %~n0 %Copyright% echo *********************************************** echo( echo [Num][SSID] ============^> "Password" echo( )>"%PasswordLog%" for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do ( if not "%%a"=="" ( set "ssid=%%a" set "ssid=!ssid:~1!" call :Getpassword "!ssid!" ) ) echo( echo Done If EXIST "%PasswordLog%" start "" "%PasswordLog%" pause>nul exit ::************************************************************************************* :Getpassword set "name=%1" set "name=!name:"=!" Set "passwd=" for /f "delims=: tokens=2" %%a in ('netsh wlan show profiles %1 key^=clear ^|find /I "Cont"') do ( set "passwd=%%a" Set /a Count+=1 ) If defined passwd ( set passwd=!passwd:~1! echo [!Count!][!name!] ====^> "!passwd!" echo [!Count!][!name!] ====^> "!passwd!" >> "%PasswordLog%" ) else ( Set /a Count+=1 call :color 0C " [!Count!][!name!] The Password is empty" 1 echo [!Count!][!name!] The Password is empty >> "%PasswordLog%" ) exit /b ::************************************************************************************* :init prompt $g for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a" exit /b ::************************************************************************************* :color set nL=%3 if not defined nL echo requires third argument & pause > nul & goto :eof if %3 == 0 ( <nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof ) else if %3 == 1 ( echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof ) exit /b ::************************************************************************************* :CountLines for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do ( if not "%%a"=="" ( set /a L+=1 ) ) set /a L=!L! + 10 Set Mod=Mode con cols=75 Lines=!L! exit /b ::************************************************************************************* [attachment deleted by admin to conserve space]Topic Closed. |
|
| 1123. |
Solve : Batch File to create, move folder name based on user input? |
|
Answer» I'm looking to create a batch file that will create, move folder name based on user input. |
|
| 1124. |
Solve : Am I in the right place ?? |
|
Answer» I have tried searching to see if this site deals with the command interpreter scripts (??.cmd files). They are essentially the "new" batch files (real DOS doesn't exist in newer versions of Windows?). I don't want to ask questions in the wrong place, or waste anyone's time so I want to first find out if I can ask questions about .cmd files/scripts here. Most of what I have SEEN so far FOCUSES on ".bat" files, so let me know if this is not the right place (and PLEASE recommend a good site for answering .cmd questions). |
|
| 1125. |
Solve : File Names too long - following an attempted backup? |
|
Answer» Hi, I recently had computer issues and I decided to copy my music files on to an external hard drive. I now wish to access the files, but when I try I get a MESSAGE that the file name is too long and the file(s) will not open. A more worrying aspect of this issue is that some files APPEAR to be empty. If anyone out there has a solution to this issue I WOULD be very grateful your for assistance. |
|
| 1126. |
Solve : How do I make a save file?? |
|
Answer» OMG first post For my game, I want to make a save file. I already have this code: Code: [Select]( echo %Name% echo %HP% echo %LV% ) > %Name%Save.lsavto save. How do I make the batch file read each line? Please HELP!The > redirection operator has an opposite operator the < to pass from file back to the VARIABLE. http://stackoverflow.com/questions/3068929/how-to-read-file-contents-into-a-variable-in-a-batch-file Quote Read file contents into a variable: also more here on this: http://www.robvanderwoude.com/redirection.php Okay, let me rephrase. How do I make it read every line? I want this: Save File: 1234 4321 1324 Now in the batch file: (Sets the variables to the line) %Line1% = 1234 %Line2% = 4321 %LINE3% = 1324 Quote from: Luigi master on June 11, 2016, 12:55:36 PM Okay, let me rephrase. There are many ways to skin this cat: using this format when creating the save file allows you to rename the .lsav file and add a .bat extension, which you call and rename the file back again. All your variables are set. Code: [Select]( echo set name=%Name% echo set HP=%HP% echo set LV=%LV% ) > %Name%Save.lsavI'm not sure this topic was resolved, or if the OP FOUND it helpful. To reiterate what Foxidrive said with an example: :save ( echo %health% echo %bees% )>textfile.txt :load ( set /p health= set /p bees= ) Use "Echo" to set the variable, "set /p" to load it. Also NOTE the direction of the carrots. ">" to save, "<" to load. Hope that helps! |
|
| 1127. |
Solve : Batch file to move files to folders wher foldername is the same until underscore? |
|
Answer» I want to move pdf-files to a folder where the foldername is the same as the filename until the _ in the filename. Works perfectYou are welcome dude and don't forget to use the Thanks link Have a nice DAY |
|
| 1128. |
Solve : Accessing a CD with an MS-DOS Computer, without Windows? |
|
Answer» Is it possible to write and read text files on a CD on a computer that has MS-DOS 6.0 and WordPerfect, but not Windows? Thanks for posting in Microsoft TechNet forums.Hope that is some help.The OakRom CD drivers for CDRom show the most success...in my experience.I think maybe the OP is asking about burning CDs in MS-DOS, which is not very easy... For a start the CD drive needs to be a burner, not a CD-ROM device. Secondly the software arrangements are not always simple. Quote from: little timmy on March 28, 2017, 10:29:55 AM Is it possible to write and read text files on a CD on a computer that has MS-DOS 6.0 [...] I would like to be able to save all my text files to a CD...Perhaps Timmy could clarify? An old guy was trying to use a computer. The message on the screen was "press any key to continue". Not finding a key labeled "ANY", he quit in disgust. I'm not quite that clueless, but I'm 72 and really have a lot to learn - I remember when a computer took up a whole room. I keyed in on a teletype - no video display. Made a mistake? Re-type the entire line. Even little items like "OP" (other person? operator? on the 3rd guess, dawn broke: original poster. Makes sense. The greatest thing about the Internet is you can look stuff up as you go. Many thanks to all who replied - I reviewed all the links which you supplied, which raised many more questions for me to try to answer on my own. From my standpoint, I see no quick and easy way to implement CD use. Poke around in autoexec.bat and config.sys files? I think I did that maybe 20 years ago - I wouldn't try it today on a computer that I want to keep using, but I will study the process and try to do it. Salmon asked if I want to access a CD from MS-DOS - I don't mind if I have to have another piece of software to do that; I just didn't want to run WordPerfect under Windows. Here again I'm confused - I recall someone telling me DOS 7 supported CD ROMs (somewhere here I have a computer w/7 installed, but the only version I own is 6.0, complete with MANUAL). I see that OldSoftware.com has both DOS 6.22 full sets and 6.22 'step up' discs for sale - all certified stuff. Prices seemed very reasonable; seems like it would be a good investment. Anyone have experience with this company? Final question: What, if any DOS versions support thumb drives? If I could save to a thumb drive, then I could upload to my Win 7 computer and burn a CD. Many thanks and kind regards, TimI don't think it was an infection... Only way that would occur on a PC not on the web is if someone loaded/used a floppy with an infection on it...highly unlikely. Quote from: little timmy on March 30, 2017, 09:58:10 AM Salmon asked if I want to access a CD from MS-DOSI asked if you wanted to write CDs under MS-DOS. Just reading them is pretty simple and easy to arrange. You talked in your original post about saving important files to CD. There is a well-known Panasonic USB driver for MS-DOS that may allow you to use a pen drive. Google for "Panasonic v2.06 ASPI Manager for USB mass storage" Salmon, thank you for your replies. Yes, I want to both write and read to CDs from a DOS-only (no Windows) computer. I have 2 locations, and when I leave one to go to the other, I've been taking the computer with me, because it has all my business records on it. It would be so much easier to just take a CD. It do have floppy backups, but it's cumbersome to upload these to another computer. I looked at the Panasonic driver for a thumb drive - the feasibility of this seems to be iffy, plus I don't want to download unauthorized/unpurchased software. I also considered an external hard drive, but I suppose that would require a driver also. Regarding Patio's suggestions about the infection on the Win XP computer: that computer had been connected to the web several years before it was used (unconnected) for billing. Obviously the malware executed when it was used for billing. I have run the Win XP built-in malware program; here is what it finds and removes: Trojan: DOS/Alureon.A.; however, the program says I need to run Standalone System Sweeper, which I downloaded to a Win 7 computer on CD, and uploaded it to the Win XP computer, but wasn't able to get it to execute. Regards, Tim Quote from: little timmy on April 06, 2017, 10:21:45 AM I looked at the Panasonic driver for a thumb drive - the feasibility of this seems to be iffy, plus I don't want to download unauthorized/unpurchased software.The Panasonic driver is free, and has been made available for download by Panasonic. If you think installing that would be iffy, getting a CD writer drive to work would be somewhere between very difficult and impossible. OK, Salmon, and many thanks. I will give the Panasonic driver my best shot. Regards, Tim |
|
| 1129. |
Solve : Batch File to Open a word template file and run a macro in that template? |
|
Answer» I am trying to create a batch file to open a Word template file (.dotm) and run a macro file in that template. Follow these steps to create a shortcut to start Word from the Windows desktop:Read over List of Word startup switches I think it says that you can open a file, set a template and auto run a macro on on one command line. I will try something after I think about this some more. Meanwhile, maya e a quick mind might jump in. OK. A simple experiment. Now I can do a BAT fle and open a document and do a macro all none command line. I put the document in D:REPORT to reduce the long path name. Here is what works as a batch file: Code: [Select]"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" D:\rEPORT\report.doc /mmacro1 The macro starts automatically and inserts some text then stops. I have not tired using a template. Hi This a starting batch to create a Winword shortcut with arguments on the desktop : So, give a try and modify it as you need Code: [Select]echo off Title Creating a Winword shortcut with arguments on the desktop Mode con cols=70 lines=5 & color 9E REM Determine if the OS is (32/64 bits) to set the correct path of Program files. IF /I "%PROCESSOR_ARCHITECTURE%"=="x86" ( Set "strProgramFiles=%ProgramFiles%" ) else ( Set "strProgramFiles=%programfiles(x86)%" ) set Key="HKEY_CLASSES_ROOT\Word.Application\CurVer" For /f "tokens=4 delims= " %%a in ('reg Query %Key% /ve ^| findstr /R "[0-9]"') do ( for /f "tokens=3 delims=." %%b in ('echo %%a') do ( Set "Ver=%%b" ) ) Rem The shortcut name with the .lnk extension Set "MyShortcutName=%userprofile%\desktop\%~n0.lnk" set "TargetPath=%strProgramFiles%\Microsoft Office\Office%ver%\Winword.EXE" Rem Here we put the arguments of the command line Set "Arguments=/q /a" If not exist "%MyShortcutName%" ( Call :CreateShortcut ) else ( Goto Main ) Exit ::*********************************************************************** :CreateShortcut echo( echo Creating the shortcut on the desktop is in progress ..... ::*********************************************************************** Powershell ^ $s=(New-Object -COM WScript.Shell).CreateShortcut('%MyShortcutName%'); ^ $s.TargetPath='"%TargetPath%"'; ^ $s.Arguments='%Arguments%'; ^ $s.Save() Exit /b ::*********************************************************************** :Main echo Hello pause |
|
| 1130. |
Solve : Deleting characters from a string through a batch command? |
|
Answer» I'm trying to write a batch command that deletes characters from a file and then outputs the new file into a folder. bjobojd0000004609142355sd.txt After Quote from: beasty so it reads bjobojd00000046sd insteadYes i would like to lose the .txt One of our systems regularly creates a file of around 26 characters long which is to long for a contractors system to input into there system. So BASICALLY what i was asking was everytime a similar file is created, a batch command removes the characters from the 16th and 24th position in the string so it can be accepted into the Contractors system. I'm not the BEST with batch files, Sidewinder below has given me something to try. The mask instruction is working perfectly but what i have found out today is that there will be multiple files in a directory that will need changing simultaneously and all will have different date and time values in the characters being removed. Any help would be appreciated The for instruction changes the the entire personality of a batch file. A subroutine was used to cut down on the complexity of the code. Code: [Select]echo off setlocal enabledelayedexpansion for /f "tokens=* delims=" %%v in ('dir /b *.txt') do ( set oldfile=%%v for /f "tokens=* delims=" %%i in ("!oldFile!") do ( set newFile=%%~ni call :doit ) ) goto :eof :doit set mask=%oldFile:~15,8% call set newFile=%%newFile:%mask%=%% echo copy %oldFile% %newFile% The last line of the code is prefaced with an echo command. This allows you to see the possible results without ACTUALLY creating any files. Remove the word echo when satisfied. When removing characters from file names be aware you run the risk of creating duplicate file names. Code is set up to run from the same directory as the .txt files are located. Good luck. BTW: positions 16-24 is 9 characters, but the example posted only shows 8 character for removal. If the number of removed characters varies, a better solution would be VBScript which has functions for better inspecting the data.If you wouldn't mind could you give me a little bit more of an explanation. Where it says ('dir /b *.txt') i take it the 'dir stands for the directory in which the multiple files are located? If i gave you an example i.e. There are multiple files in a folder called c:\bobjects\sample jobs and all the files need to have the characters removed. Does that need to go in ('dir /b *.txt'). What about outputting the amended files into a different folder? Excuse my lack of knowledge in this area as i do not tend to get involved to much with batch scripts and i'm struggling!!! You have been more than helpful by the wayThis should fix it up. Added a pushd instruction to set the CURRENT folder to where the txt files live, and a popd instruction to navigate the user back to the starting folder. The batch file and the text files do not have to live in the same folder. Also changed the last line of code so you can see how to direct the output to the folder of your choice. Code: [Select]echo off setlocal enabledelayedexpansion pushd c:\bobjects\sample jobs for /f "tokens=* delims=" %%v in ('dir /b *.txt') do ( set oldfile=%%v for /f "tokens=* delims=" %%i in ("!oldFile!") do ( set newFile=%%~ni call :doit ) ) popd goto :eof :doit set mask=%oldFile:~15,8% call set newFile=%%newFile:%mask%=%% echo copy %oldFile% drive:\path\%newFile% It still holds true that removing characters from otherwise unique file names runs the risk of duplicates and file overwrites. Happy coding Right i've got a little bit further, the first bit seems to work and it copies the files but it won't copy files into another folder. echo off setlocal enabledelayedexpansion pushd C:\bobjects\SampleJobs for /f "tokens=* delims=" %%v in ('dir /b *.*') do ( set oldfile=%%v for /f "tokens=* delims=" %%i in ("!oldFile!") do ( set newFile=%%~ni call :doit ) ) pause popd goto :eof :doit set mask=%oldFile:~15,8% call set newFile=%%newFile:%mask%=%% echo copy %oldFile% c:\bobjects\test\%newFile% Have i missed something Quote from: beasty on July 05, 2011, 10:30:54 AM Right i've got a little bit further, the first bit seems to work and it copies the files but it won't copy files into another folder. Remove the echo? Thanks i'm getting somewhere now Hi I'm still having a couple of problem's but i am getting further. I need to incorporate a call command with in the script below: echo off rem W-Dixon Test repairs out rem echo Press Ctrl+C or close the window to stop or rem pause echo Working........................ net use D: \\"ipaddress"\test_var /persistent:no C: cd \wdftp rmdir wdtestoutold /s /q ren wdtestout wdtestoutold mkdir wdtestout cd \wdftp\wdtestout rem Copy test files from orchard/Test_var to wdftp folder for ftp to W-Dixon xcopy D:\l\test\var\pmcli\ifc\output\wd\* c:\wdftp\wdtestout /v /y xcopy c:\wdftp\wdtestout\* c:\wdftp\wdtestoutold /v /y ftp -i -s:"c:\batch\wdtest.ftp" ip address del /q D:\l\test\var\pmcli\ifc\output\wd\* del /q c:\wdftp\wdtestout\* echo . echo wdtestout finished rem pause The call command needs to go just under the second xcopy in the file and needs to call the script earlier in the post using call instead of push and then needs to be out putted to an FTP folder: pushd C:\wdftp\wdconvert for /f "tokens=* delims=" %%v in ('dir /b *.*') do ( set oldfile=%%v for /f "tokens=* delims=" %%i in ("!oldFile!") do ( set newFile=%%~ni call :doit ) ) popd goto :eof :doit set mask=%oldFile:~15,8% call set newFile=%%newFile:%mask%=%% copy %oldFile% c:\wdftp\wdconvert\%newFile% Would someone be kind enough to show me how to do this? Thanks Beasty beasty, You do yourself a disservice by requesting stuff in dribs and drabs. Many responders will see your thread has 12 replies and figure they have nothing to add or the problem was solved. Better to split your request into multiple posts or ask all your questions in your first post. Unless I missed a day in Batch Coding 101, The call statement and the pushd statement are unrelated. The call is used in a batch file to give control to a secondary batch file located somewhere in your system. It sets up a mechanism so when the secondary file terminates, control is passed back to the calling program at the statement following the call which then continues executing. The pushd statement is like the cd statement with benefits. Pushd saves the current directory on the stack and then changes to the directory passed as the first argument on the command line. The opposite of pushd is popd which navigates to the directory pulled from the stack. The order is last in, first out (LIFO), so it pays to keep TRACK of this info. It's useful on forums where the OP fails to mention path information. Ex: c:\temp> pushd c:\windows this will save the c:\temp directory on the stack and then navigate to the c:\windows directory. Insert the call statement after the second xcopy as call scriptfromearlierpost.bat If the called file is not in the current directory you will need to supply path information. Same as for the file that ends up in the FTP folder. Quote from: Sidewinder on July 11, 2011, 11:07:24 AM The call is used in a batch file to give control to a secondary batch file located somewhere in your system. It sets up a mechanism so when the secondary file terminates, control is passed back to the calling program at the statement following the call which then continues executing. In addition to the above, CALL can also call a subroutine within the batch file and as beasty is trying to do, CALL can also be used to run any internal command (SET, ECHO etc) expanding any environment variables passed on the same line. |
|
| 1131. |
Solve : DOS Command to capture image names & output to Excel ?? |
|
Answer» Hi - i have 1000's of product images (mostly JPG / PNG) STORED in a folder. HiNice little .bat file Hackoo. I'd recommend changing the line echo %%i;!list[%%i]!;!listpath[%%i]!>> "%LogFile%" to use commas instead of semi-colons, that way Excel will put the count, file name and location in separate columns. As for Salmon's comment regarding .bmp files, any other type of image files can be added to the line: Set "EXT=jpg png gif bmp tif" or in my original command: for %x in (*.jpg *.gif *.png *.bmp *.tif) do echo %x , >> out.csvNew script to search for [jpg png gif bmp tif] with ShowBalloonTip function in powershell for fancy ImagesFinder.bat Code: [Select]echo off Title Search for images files mode con cols=75 lines=5 & Color 0A REM We set the variable Folder Set "Folder=%USERPROFILE%\Pictures" Rem We set the variable EXT for the extensions images to be searched by the script Set "EXT=jpg png gif bmp tif" REM We initialize the variable Count from zero for counting images files SET "Count=0" Rem Set the variable LogFile to save the information after the scanning Set "LogFile=%~n0.csv" If exist "%LogFile%" Del "%LogFile%" Set "Msg=Please wait a while scanning for" Setlocal Enabledelayedexpansion For %%a in (%EXT%) Do ( Call :Scanning %%a Call :ShowBalloonTip 'Information' 100 '"%~n0 to find images"' '"%Msg% """*.%%a""" images ..."' 'Info' 10 FOR /f "delims=" %%f IN ('dir /a-d /b /s "%Folder%\*.%%a"') DO ( Rem We increment the variable Count SET /a "Count+=1" rem populate the array variable list with the name of images set "list[!Count!]=%%~nxf" rem populate the array variable listpath with the whole path of images set "listpath[!Count!]=%%~dpFf" ) ) Cls echo( echo Saving information into the file "%LogFile%" echo The Total of [%EXT%] images files(s) found is !Count! rem Display array elements for /L %%i in (1,1,%Count%) do ( rem save information into the LogFile.csv echo %%i,!list[%%i]!,!listpath[%%i]!>> "%LogFile%" ) Start "" "%LogFile%" & exit ::**************************************************************************** :Scanning %1 Cls echo( & echo( echo %Msg% "*.%1" images ... exit /b ::**************************************************************************** :ShowBalloonTip $notifyicon $time $title $text $icon $Timeout PowerShell ^ [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^ [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^ $notify = new-object system.windows.forms.notifyicon; ^ $notify.icon = [System.Drawing.SystemIcons]::%1; ^ $notify.visible = $true; ^ $notify.showballoontip(%2,%3,%4,%5); ^ Start-Sleep -s %6; ^ $notify.Dispose() %End PowerShell% exit /B ::*****************************************************************************Maybe I can contribute something POSITIVE.............. If you have multiple folders in different locations and don't want the bother of putting the script in the "current folder" you're welcome to drop this code into your script. This will let you put your script wherever you want - then - at run-time - you can browse your computer and pick the target folder you want to work with. Obviously, you have to tweak the original script to include this code - and use the variable that returns the folder you picked. And don't forget... make SURE the "EXITs" in this script are removed or modified so when this code ends it doesn't terminate the script it was inserted into. Cheers !! Code: [Select]echo off setlocal enabledelayedexpansion :: set SName=%~dpn0 :: call :SavBrowse :: cls & color 2E :: :: ===================================================================== :: call the folder-finder :: ===================================================================== :: set _Repo= For /f "delims=" %%A in ( 'cscript //nologo "%temp%\900_VBrowse.vbs" "C:\"' ) do set _Repo=%%A :: echo. & echo. echo Selected Folder: %_Repo% echo. & echo. echo. & echo. pause :: :: :: ===================================================================== :: End-of-Script :: ===================================================================== :: cls & color 5E echo. & echo. & echo. & echo. echo. & echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * echo. & echo * %~nx0 echo. & echo * Blah, Blah, Blah........ echo. & echo * echo. & echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * echo. & echo. set /p entered=....Hit any key to continue :: EXIT :: :: :: :: :: :: -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- :: Subroutines :: -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- :: :SavBrowse :: set _aa=Function BrowseForFile() echo %_aa% > %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=xparm = "" echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=xparm = WScript.Arguments.Item(0) echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=Dim shell : Set shell = CreateObject("Shell.Application") echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=Dim file : Set file = shell.BrowseForFolder(0, "Choose a folder:", ^^^&H4000, xparm) echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=BrowseForFile = file.self.Path echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=End Function echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=' echo %_aa% >> %temp%\900_VBrowse.vbs set _aa=WScript.echo(BrowseForFile) echo %_aa% >> %temp%\900_VBrowse.vbs goto :EOF As someone who has tinkered with batch/vbs hybrid scripts, I have to ask: why all those set _aa and echo %_aa% commands? Why not just echo the lines directly into the vbscript? It makes the batch harder to read and doubles the number of lines in that section. Also, double-colons (which are really broken labels) as comments are severely deprecated in NT family batch scripting; they may look cool but they can break scripts, e.g. in parenthesis blocks. Not wishing to pour cold water on what is a very neat idea. If you want to use the function Browse4Folder, you can do something like this ImagesFinder.bat Code: [Select]echo off Title Search for images files mode con cols=75 lines=5 & Color 0A REM We set the variable Folder Call :Browse4Folder "Choose source folder to scan for images files" "c:\scripts Set "Folder=%Location%" Rem if the variable %Folder% have a trailing back slash, we remove it ! IF %Folder:~-1%==\ SET Folder=%Folder:~0,-1% If "%errorlevel%" EQU "0" ( echo( & echo( echo You choose this folder "%Folder%" Timeout /T 2 /nobreak>nul ) else ( echo( & echo( echo "%Folder%" Timeout /T 2 /nobreak>nul & Exit ) Rem We set the variable EXT for the extensions images to be searched by the script Set "EXT=jpg png gif bmp tif" REM We initialize the variable Count from zero for counting images files SET "Count=0" Rem Set the variable LogFile to save the information after the scanning For %%f in (%Folder%) do set "LogFile=%~n0_%%~nf.csv" If exist "%LogFile%" Del "%LogFile%" Set "Msg=Please wait a while scanning for" Setlocal Enabledelayedexpansion For %%a in (%EXT%) Do ( Call :Scanning %%a Call :ShowBalloonTip 'Information' 100 '"%~n0 to find images"' '"%Msg% """*.%%a""" images ..."' 'Info' 10 FOR /f "delims=" %%f IN ('dir /a-d /b /s "%Folder%\*.%%a"') DO ( Rem We increment the variable Count SET /a "Count+=1" rem populate the array variable list with the name of images set "list[!Count!]=%%~nxf" rem populate the array variable listpath with the whole path of images set "listpath[!Count!]=%%~dpFf" ) ) Cls echo( echo Saving information into the file "%LogFile%" echo The Total of [%EXT%] images files(s) found is !Count! rem Display array elements for /L %%i in (1,1,%Count%) do ( rem save information into the LogFile.csv echo %%i,!list[%%i]!,!listpath[%%i]!>> "%LogFile%" ) If exist "%LogFile%" ( Start "" "%LogFile%" & exit ) else ( exit ) ::**************************************************************************** :Scanning %1 Cls echo( & echo( echo %Msg% "*.%1" images ... exit /b ::**************************************************************************** :ShowBalloonTip $notifyicon $time $title $text $icon $Timeout PowerShell ^ [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^ [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^ $notify = new-object system.windows.forms.notifyicon; ^ $notify.icon = [System.Drawing.SystemIcons]::%1; ^ $notify.visible = $true; ^ $notify.showballoontip(%2,%3,%4,%5); ^ Start-Sleep -s %6; ^ $notify.Dispose() %End PowerShell% exit /B ::***************************************************************************** :Browse4Folder set Location= set vbs="%temp%\_.vbs" set cmd="%temp%\_.cmd" for %%f in (%vbs% %cmd%) do if exist %%f del %%f for %%g in ("vbs cmd") do if defined %%g set %%g= ( echo set shell=WScript.CreateObject("Shell.Application"^) echo set f=shell.BrowseForFolder(0,"%~1",0,"%~2"^) echo if typename(f^)="Nothing" Then echo wscript.echo "set Location=Dialog Cancelled" echo WScript.Quit(1^) echo end if echo set fs=f.Items(^):set fi=fs.Item(^) echo p=fi.Path:wscript.echo "set Location=" ^& p )>%vbs% cscript //nologo %vbs% > %cmd% for /f "delims=" %%a in (%cmd%) do %%a for %%f in (%vbs% %cmd%) do if exist %%f del /f /q %%f for %%g in ("vbs cmd") do if defined %%g set %%g= goto :eof ::******************************************************************************I am not a "scriptor" - I just solve problems as I encounter them. Everyone has his/her own style so if it works for me - but you don't like what I do - or the way I do it - I still go to sleep at night knowing that it works for me. I'm not trying to sell you anything - I'm just offering code that might be helpful to somebody. I'm very sorry if that offends you to the point you must criticize my efforts. If you must pick-pick-pick I hope you feel better now. I do appreciate the help some have given me in other threads. BlueThere are two ways to accept criticism, you can take it personally, or you can use it to improve. |
|
| 1132. |
Solve : Remote desktop information through DOS command? |
|
Answer» Hi, |
|
| 1133. |
Solve : xcopy/copy refuses to use long file names? |
|
Answer» Good evening: BTW, I have verified that the %1 parameter really contains what I expect. Quote Naming convention is xnnymmmmm I'm kinda puzzled by your use of a single % (percentage sign) which is not a wildcard so doesn't represent any letter/digit in the file name. Seems to me that U1*.* would copy/xcopy every file in the 'U10ymmmmm' thru 'U19ymmmmm' range. However if you have SET 1=something then it's understandable except that you need to use the full %1% (leading and trailing percentage signs) in the filename. Why does my tired brain keep giving me the message there's something I've missed and that I've just made a complete fool of myself - again:-? Grrrrrrrr Quote Sorry - it's been long hard day and I must confess you've got me on that one. I could have sworn I replied to this, but it's not there, so here goes again. The %1 is parameter 1. I call the .bat file and pass a number from 10-19 for the zone. I'm thinking I'll just write something in C, though I bet it'll be much slower since I'll have to call the copy once for each file. For now, I have just extracted the high resolution B&W photos out and an working on the other types. I'm glad to see it has you confused as well. Makes me feel not quite so dumb. Thanks for you help, Dusty! -dan Best and quick solution is to use (long_path_tool)If he comes back...after 10 years i'm sure he'll appreciate it... |
|
| 1134. |
Solve : How to output echo'd info from a for loop? |
|
Answer» Hello! |
|
| 1135. |
Solve : Use batch file to insert text in a text file after a word i specify?? |
|
Answer» To put it in plain terms guys n gals what i would like to know is if this is possible? guys wow replies were excellent and very fast thanks very much, this forum rocks. quick question to batcher, i noticed equ 12 does that insert the text i want on line 12 cause there is like hundreds of different lines and it is near the end and it is not on the same line anytime, i like the look of yours best as it seems the simplest so COULD you edit it to insert the text after the word i originally specified? is that possible?if line 12 always have the word CLEANUP, then the batch solution should be ok. Otherwise, need to change it to something more flexible.does my solution work ? Quote from: rytech on April 22, 2009, 06:22:01 AM quick question to batcher, i noticed equ 12 does that insert the text i want on line 12 cause there is like hundreds of different lines and it is near the end and it is not on the same line anytime, i like the look of yours best as it seems the simplest so could you edit it to insert the text after the word i originally specified? Everything is possible. Try this one. Code: [Select]echo off set SrcFolder=C:\test1 set DstFolder=C:\test2 for %%a in ("%SrcFolder%\*.txt") do ( (for /f "usebackq delims=" %%h in ("%%a") do ( echo.%%h if "%%h" equ "SCHEDULES CLEANUP" ( echo SYS DUEGATE 60 05:00 echo DISPLAY SCHED 00:30 01:30 ) ))>"%DstFolder%\%%~nxa" ) Batcher your the man thanks very much buddy Devcom i never tried it mate cause the line number thing you had in yours but batchers done the job and i edited the batch file to delete the un needed folder once it had done it so it's all sorted but i need to know if it is possible to delete some text in the file and replace it, i need to replace the date with the date i am working with rather than the date set in the files as well it was just i forgot about that so i have: ECHO OFF set SrcFolder=C:\Test set DstFolder=C:\Test1 for %%a in ("%SrcFolder%\*.txt") do ( (for /f "usebackq delims=" %%h in ("%%a") do ( echo.%%h if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 ) ))>"%DstFolder%\%%~nxa" ) Where SYS CONFIG 20090327 i want that replaced with SYS CONFIG 20090427, is that possible, this question goes to my man batcher lol or anyone with the knowledge cause i aint got it try to change this: Code: [Select] echo.%%h if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 )to Code: [Select] if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 ) else ( echo.%%h ) should work devcom sorry to be a bloody pain but it says the system could not find the path specified, here is what i have, can you think of anything that looks wrong? ECHO OFF set SrcFolder=c:\test set DstFolder=C:\test1 for %%a in ("%SrcFolder%\*.txt") do ( (for /f "usebackq delims=" %%h in ("%%a") do ( if "%%h" equ "SYS CONFIG 20090327" ( echo SYS CONFIG 20090427 ) else ( echo.%%h ) ))>"%DstFolder%\%%~nxa" ) ECHO. ECHO Done! ECHO. PAUSE CLS |
|
| 1136. |
Solve : finding/moving files? |
|
Answer» Good Morning Good MorningHi Did you mean move or copy them in NEW folder ?To copy pleaseHi You can give a try with this batch file : CopyPDF.bat Just copy and paste this code with your NOTEPAD and save it as CopyPDF.bat and just drag and drop your folder on it. Code: [Select]echo off Title Copying All PDF files in folder and its subfolders with drag and drop Mode con cols=75 lines=3 & color 0E set "Drag_Dir=%~1" set "Ext=pdf" echo( IF ["%Drag_Dir%"] EQU [""] Goto:Error set "newFolder=%Drag_Dir%\New_%Ext%_Folder" Rem Create the new folder to copy all *.pdf on it If not exist "%newFolder%" md "%newFolder%" 2>nul cd "%newFolder%" && Call :CopyPDFfiles || Goto:Error EXplorer "%newFolder%" Exit ::******************************************** :CopyPDFfiles for /f "delims=" %%I in ('Dir /a-d /b /s "%Drag_Dir%\*.%Ext%"') do ( Copy /Y "%%I" "%newFolder%" ) Exit /b ::******************************************** :Error Mode con cols=75 lines=5 & Color 0C echo( ECHO You must drag and drop a folder on this batch program ECHO to copy all PDF files in new location Timeout /T 10 /NoBreak >nul Exit /b ::*****************************************Thank you Hacko. It created the folder but no pdf's inside it. Quote from: widetree on April 20, 2017, 07:41:51 AM It created the folder but no pdf's inside it.Check if your folder and its subfolders contains any pdf files or not ! if the batch file dosen't find any pdf files it create an empty folder named New_PDF_FolderYes that worked beautifully! Thank you very much! Could you possibly tweet the code so I could run this batch file to find pdf's with a name containing the characters "plan"? Quote from: widetree on April 20, 2017, 08:13:16 AM Yes that worked beautifully! Thank you very much! Could you possibly tweet the code so I could run this batch file to find pdf's with a name containing the characters "plan"?Here we go Code: [Select]echo off Title Copying All PDF files in folder and its subfolders with drag and drop Mode con cols=75 lines=3 & color 0E set "Drag_Dir=%~1" set "Ext=pdf" set "Word=plan" IF ["%Drag_Dir%"] EQU [""] Goto:Error set "newFolder=%Drag_Dir%\New_%Ext%_Folder" Rem Create the new folder to copy all *.pdf on it If not exist "%newFolder%" md "%newFolder%" 2>nul cd "%newFolder%" && Call :CopyPDFfiles || Goto:Error Explorer "%newFolder%" Exit ::******************************************** :CopyPDFfiles for /f "delims=" %%I in ('Dir /a-d /b /s "%Drag_Dir%\*.%Ext%" ^| find /I "%Word%"') do ( Rem find all pdf's with a name containing the characters "plan" and copy them to the newfolder Copy /Y "%%I" "%newFolder%" ) Exit /b ::******************************************** :Error Mode con cols=75 lines=5 & Color 0C echo( ECHO You must drag and drop a folder on this batch program ECHO to copy all PDF files in new location Timeout /T 10 /NoBreak >nul Exit /b ::*****************************************That worked too! Thank you so much! I did not realise so much coding was involved. Quote from: widetree on April 21, 2017, 12:14:51 AM That worked too! Thank you so much! I did not realise so much coding was involved.You are welcome dude and don't forget to use the Thanks LINK Have a nice day ! |
|
| 1137. |
Solve : need to create a batch file to Convert .csv to html? |
|
Answer» Hi team, |
|
| 1138. |
Solve : Unable to copy files containing html tags after adding text inside it.? |
|
Answer» Hi everyone, |
|
| 1139. |
Solve : remove lines in txt files? |
|
Answer» Windows 7
Sample file attached - can't attach a real one, not my property and contains private data. There are thousands of files, they are not large files, 30-1000KB each. In each text file in an Input folder I want to delete everything down the line that starts with say Purpose: and write the edited file to an Output folder, if Purpose: is not found write the file to an Exceptions folder. So a command might look something like Code: [Select]EditTextFiles -i="d:\textdata\first set of files" -s="Purpose:", -o="d:\textdata\first set of files\edited", -e="d:\textdata\first set of files\exceptions" where -i is the input directory/folder; -s is the search string; -o is the output directory/folder; -e is the exceptions directory/folder. The person who 'owns' the data is a competent computer user, but not a computer geek, hence a preference for a GUI based tool. But a batch script will do. PhilD [attachment deleted by admin to conserve space]Once you have a thing that works, you can 'decorate' it with Vb Script. You can use Visual Basic to create VB Scripts that will run with batch files. You might look at this: https://social.msdn.microsoft.com/Forums/en-US/6cf20733-75c4-4018-81dc-22369020e492/creating-a-gui-with-visual-basic?forum=Vsexpressvb Also this: http://www.instructables.com/id/How-to-Make-a-message-box-using-VBScript/ And: https://community.spiceworks.com/topic/93619-vbscript-to-gui-or-to-visual-basic Of course, none of the above are specific to what you are doing. But almost anything you do in batch cam can made into a GUI program.A VB Script can INVOKE a command line program and get the results sent to a file. Some users hate using anything related to Visual Basic. Nevertheless, Visual Basic and is offspring have done and still do a lot of work in the IT industry. https://en.wikipedia.org/wiki/Visual_Basic Quote On April 8, 2008, Microsoft stopped supporting Visual Basic 6.0 IDE.Some early versions of Visual Basic are easy to learn and are compatible with current versions of Windows. Here is a link for the free 2008 version: http://www.freewarefiles.com/Microsoft-Visual-Basic-Express-Edition_program_17931.html Quote from: Geek-9pm on April 25, 2017, 08:29:55 PM Once you have a thing that works, you can 'decorate' it with Vb Script.Thanks - but I'm a minimalist - less is better, least is best. This is a short term need for dealing with the thousands of archived text files. The ongoing updates won't come from text files, they will go directly into the database as LOB transactions. For the job at hand a batch file solution will perfectly adequate. PhilD OK. You are the one who keeps adding things. But you fest said: Quote In each file I want to remove lines up to and including a line starting with 'xxxxxxx'.That is almost trivia. The pseudo code is: open file. begin loop read a line If line starts with 'xxxxxxx' exit loop write line to output end loop close Is that what you want? Quote from: Geek-9pm on April 25, 2017, 11:11:15 PM OK. You are the one who keeps adding things.What I wrote was Quote from: PhilD on April 25, 2017, 01:18:00 PM I have a number of folders each containing a lot of text files. In each file I want to remove lines up to and including a line starting with 'xxxxxxx'. I did add a post because I forgot the exception condition of the xxxxxxx not being found I provided a sample and clarification as requested by Hackoo. I responded Geek_9s suggestion that I write something in Basic. If its batch file I want to be able specify the input folder, the search string, the output folder and the exceptions folder in a command line, in essence I don't want those things hard coded in the batch file. So assuming xxxxxx is 'Purpose:" for file shown in the attachment I do not want lines 1 to 15 to be written, the output would consist of lines 16 until the end of file If the xxxxxx isn't found copy the file to an exceptions folder And I want it to operate on every .txt file in the input folder. I appreciate it is not very hard for you, but at 83 I find coding hard. Thanks PhilD [attachment deleted by admin to conserve space]You are 83? Now I understand why you want it simple. I am 78 and get tired very easy. For me, it works best if I can divide things into little parts. Tomorrow I will look at this again and if nobody has given you a batch file, I will try to do something in a script. Quote from: Geek-9pm on April 26, 2017, 01:05:55 AM You are 83? Now I understand why you want it simple.Thanks pal - had mild stroke a few years ago, it zapped any coding skills I ever had. Hi I made this script just for testing for one file ! and you should confirm me if this what you want for one file or not ? Code: [Select]echo off Set "Stop_String=Purpose" Set "File=Sample.txt" Set "OutPutFile=OutPutFile.txt" if exist "%OutPutFile%" Del "%OutPutFile%" set /A "Count=0" For /f "tokens=1 delims=:" %%A in ('findstr /I /N "%Stop_String%" "%File%"') Do ( Set /a "Count=%%A" ) echo We found the string "%Stop_String%" at line number %Count% pause & Cls For /f "skip=%Count% delims=*" %%a in ('Type "%File%"') do ( echo %%a echo %%a >> "%OutPutFile%" ) echo. Echo Hit any key to open the output file ... pause>nul Start "" "%OutPutFile%" & exit Quote from: Hackoo on April 26, 2017, 01:46:16 AM HiThanks a lot Hackoo Yeah it finally worked - my blunder I didn't copy all the code, I don't see many SMF forums PD Hi This an update version with Browse for folder Just give a try and tell me the result Code: [Select]echo off Title Search for files and remove lines in text files mode con cols=75 lines=5 & Color 0A REM We set the variable Folder with the function Browse4Folder Call :Browse4Folder "Choose source folder to scan for files" "c:\scripts" Set "Folder=%Location%" Rem if the variable %Folder% have a trailing back slash, we remove it ! IF %Folder:~-1%==\ SET "Folder=%Folder:~0,-1%" If "%errorlevel%" EQU "0" ( echo( & echo( echo You choose this folder "%Folder%" Timeout /T 2 /nobreak>nul ) else ( echo( & echo( echo "%Folder%" Timeout /T 2 /nobreak>nul & Exit ) Set "Stop_String=Purpose" Set "Edited_Files=%HomeDrive%\Edited_Files" Set "Exceptions_Folder=%HomeDrive%\Exceptions" If not exist "%Edited_Files%" MD "%Edited_Files%" If not exist "%Exceptions_Folder%" MD "%Exceptions_Folder%" SetLocal EnableDelayedExpansion for /f "delims=" %%f in ('Dir /b /s "%Folder%\*.txt"') Do ( Cls echo. set /A "Count=0" set "InputFile=%%~dpFf" findstr /I /C:"%Stop_String%" "!InputFile!" >nul 2>&1 If "!ErrorLevel!" EQU "0" ( Call :Counting "%Stop_String%" "!InputFile!" echo We found the string "%Stop_String%" at line number !Count! on "!InputFile!" Timeout /T 4 /nobreak>nul Set "OutPutFile=%Edited_Files%\%%~nf_edited.txt" if exist "!OutPutFile!" Del "!OutPutFile!" Call :Write2File "!InputFile!" "!OutPutFile!" ) else ( Call :Copyfiles "!InputFile!" "!Exceptions_Folder!" ) ) Explorer "%Edited_Files%" & exit ::******************************************************************** :Counting <Stop_String> <InputFile> For /f "tokens=1 delims=:" %%A in ('findstr /I /N "%~1" "%~2"') Do ( Set /a "Count=%%A" ) exit /b ::******************************************************************** :Write2File <InputFile> <OutPutFile> For /f "skip=%Count% delims=*" %%a in ('Type "%~1"') do ( echo %%a >> "%~2" ) exit /b ::******************************************************************** :Browse4Folder set Location= set vbs="%temp%\_.vbs" set cmd="%temp%\_.cmd" for %%f in (%vbs% %cmd%) do if exist %%f del %%f for %%g in ("vbs cmd") do if defined %%g set %%g= ( echo set shell=WScript.CreateObject("Shell.Application"^) echo set f=shell.BrowseForFolder(0,"%~1",0,"%~2"^) echo if typename(f^)="Nothing" Then echo wscript.echo "set Location=Dialog Cancelled" echo WScript.Quit(1^) echo end if echo set fs=f.Items(^):set fi=fs.Item(^) echo p=fi.Path:wscript.echo "set Location=" ^& p )>%vbs% cscript //nologo %vbs% > %cmd% for /f "delims=" %%a in (%cmd%) do %%a for %%f in (%vbs% %cmd%) do if exist %%f del /f /q %%f for %%g in ("vbs cmd") do if defined %%g set %%g= goto :eof ::******************************************************************** :Copyfiles <Source> <Target> Copy /Y "%~1" "%~2" >nul 2>&1 goto :eof ::******************************************************************** Quote from: Hackoo on April 26, 2017, 11:56:10 AM HiHi Hakoo - I'm on to it - Thanks * 80 I'll be back soon as possible |
|
| 1140. |
Solve : Downloading video from youtube using VLC with the command line ?? |
|
Answer» Hi Lots of this in vlc log for that problem videoSo, did you think that error is coming with a copyright PROTECTED url from youtube ?Could be. Yepper... |
|
| 1141. |
Solve : batch for using 2 txt files? |
|
Answer» I am trying to make a batch FILE which will take a comand line from text file and computer name to execute command. why waste time on this when you got powershell?Powershell Tutorials are available. https://mva.microsoft.com/en-us/training-courses/getting-started-with-powershell-3-0-jump-start-8276 |
|
| 1142. |
Solve : find files older than 7 days and send email? |
|
Answer» I need a simple batch to find files which are older than 7 days. |
|
| 1143. |
Solve : command line to restart script.bat ?? |
|
Answer» Hi, all i want is to add a NEW line to script.bat, so when when my tool disconnect or receive the word ''error connection'' repeating more then 10 times then ''script.bat'' must restart itself.I will also POST the script if there is anyone who wants to help me script.bat(wich work with Ncrack)Ncrack is a high-speed network authentication cracking tool. Also, like we're sure going to go to your link for this! Topic Closed... |
|
| 1144. |
Solve : I need a batch or a command line to restart the ''process? |
|
Answer» I need a batch or a command line to restart the ''process'' 2 minutes after the process is over mm my process works with AlwaysUP ''as system'' so u can't find '' mytool.exe'' in the processes tab, but maybe works ,thanksIf this batch dos not work in your case, i will try to write you a vbscript instead So what did you thing ?What do i think?I radiate of happiness u read the PM i sent to you?u saw the script?restarting and waiting time i need only for that script,can u integrate that command lines inside that script?So when my tool stops need to restart after 5 min. i tried to scheduler with AlwaysUP (This is important:wich runs ''as system'') but no succes maybe need to add some new lines to that script, i don't know so plz take a look,thank you!Ok, this vbscript show you how we can monitor some process if there aren't running like iexplore.exe , notepad.exe, and calc.exe Check+RunApp.vbs Code: [Select]Option Explicit If AppPrevInstance() Then WScript.Echo "Instance already running" WScript.Quit Else Do Call Main(Array("%ProgramFiles%\Internet Explorer\iexplore","%windir%\system32\calc.exe","%windir%\system32\notepad.exe")) 'Pause 2 minutes Call Pause(2) Loop End If Sub Main(colProcessPaths) Dim ProcessPath For Each ProcessPath In colProcessPaths CheckProcess(ProcessPath) NEXT End Sub Sub CheckProcess(ProcessPath) Dim ProcessName : ProcessName = StripProcPath(ProcessPath) msgbox ProcessPath &vbcr& CommandLineLike(ProcessName) &vbcr& CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34)) With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") With .ExecQuery("SELECT * FROM Win32_Process WHERE Name LIKE " & CommandLineLike(ProcessName) & " OR Commandline LIKE " & CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34))) If .Count = 0 Then With CreateObject("WScript.Shell") .Run DblQuote(ProcessPath) End With Else EXIT Sub End if End With End With End Sub Function AppPrevInstance() With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptName)) AppPrevInstance = (.Count > 1) End With End With End Function Sub Pause(Minutes) Wscript.Sleep(Minutes*1000*60) End Sub Function StripProcPath(ProcessPath) Dim arrStr : arrStr = Split(ProcessPath, "\") StripProcPath = arrStr(UBound(arrStr)) End Function Function CommandLineLike(ProcessPath) ProcessPath = Replace(ProcessPath, "\", "\\") CommandLineLike = "'%" & ProcessPath & "%'" End Function Function DblQuote(str) DblQuote = chr(34) & str & chr(34) End FunctionFor your case i will try to take a look on it or i will advise you where you can ask this kind of question, because i don't know it for the moment how your program work ?can u come now for 1 min with team viewer? u will understand imediatelly how the mechanism work or i can make a video and show you the steps,but with team viewer will much faster and easyi made a change i tried to run my .bat script but opens fast and then crushing Code: [Select]Option Explicit If AppPrevInstance() Then WScript.Echo "Instance already running" WScript.Quit Else Do Call Main(Array("C:\Windows\windefender\ncrack-autorunner.bat")) 'Pause 2 minutes Call Pause(2) Loop End If Sub Main(colProcessPaths) Dim ProcessPath For Each ProcessPath In colProcessPaths CheckProcess(ProcessPath) Next End Sub Sub CheckProcess(ProcessPath) Dim ProcessName : ProcessName = StripProcPath(ProcessPath) msgbox ProcessPath &vbcr& CommandLineLike(ProcessName) &vbcr& CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34)) With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") With .ExecQuery("SELECT * FROM Win32_Process WHERE Name LIKE " & CommandLineLike(ProcessName) & " OR Commandline LIKE " & CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34))) If .Count = 0 Then With CreateObject("WScript.Shell") .Run DblQuote(ProcessPath) End With Else Exit Sub End if End With End With End Sub Function AppPrevInstance() With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptName)) AppPrevInstance = (.Count > 1) End With End With End Function Sub Pause(Minutes) Wscript.Sleep(Minutes*1000*60) End Sub Function StripProcPath(ProcessPath) Dim arrStr : arrStr = Split(ProcessPath, "\") StripProcPath = arrStr(UBound(arrStr)) End Function Function CommandLineLike(ProcessPath) ProcessPath = Replace(ProcessPath, "\", "\\") CommandLineLike = "'%" & ProcessPath & "%'" End Function Function DblQuote(str) DblQuote = chr(34) & str & chr(34) End Function |
|
| 1145. |
Solve : batch for find and start batch where it is located? |
|
Answer» I have fev batch files in differend folders and it works as they should when I run it manually. |
|
| 1146. |
Solve : dir on comand prompt? |
|
Answer» Hi, |
|
| 1147. |
Solve : Get rid of flicker of echo display? |
|
Answer» Put this together to log only failed pings with request TIME out. But was playing around with a way to have the output showing and not flickering, but also I dont want to affect how fast this runs either. I know that I could put a sleep condition before the goto to make it display longer before refresh. I sized the shell window down to only show the Ping of Device Was Successful And this way you dont SEE multiples of each test scrolling. I tried of CLS, but it makes the output ALMOST hidden with constant flicker. Also tried a bunch of echos as a refresh method instead of clear screen but then the output looks like an older TV with the rolling of the PICTURE. I have avoided use of sleep because I want to avoid slowing down the batch if possible to get as precise log data. Maybe its just the nature of the beast to have the fast execution of this that it will flicker. I guess I am just a perfectionist in that this does as intended, but I guess curious if there is a method that can be implemented that gets rid of flicker and shows the date and time of each test loop and condition. By the way 127.0.0.1 is just for testing purposes. The actual IP address will be entered and saved to this for each IP address to be logged. You can change it to some IP address that doesnt exist to see the error condition and the log start to append date and times. Code: [Select]echo off :restart echo. Ping Logger v2.0 Running... ping 127.0.0.1 -n 1 | find "Reply from" > nul if %ERRORLEVEL% == 0 goto Device_Replied ping 127.0.0.1 -n 1 | find "Request timed out" > nul if %ERRORLEVEL% == 0 goto No_Reply echo. Possible INVALID IP address. goto restart :Device_Replied echo. Ping of Device Was Succesful. echo. On %date% at %time% goto restart :No_Reply echo. No Reply from Device. Request timed out. echo. On %date% at %time% echo. %date% at %time% >>PingLog104.log goto restart Closing this request.... did some research and only way to get rid of flicker would be to slow it down. So its fine as is. |
|
| 1148. |
Solve : Delete all users except for some? |
|
Answer» I work in IT, and I have to remove USERS from loaner laptops all the time. What I currently use to do this is: |
|
| 1149. |
Solve : run batch file invisible with uac, continue batch script invisibly if not admin? |
|
Answer» i want to make my batch files run there self invisible while requesting for UAC after the computer retarts, how ever if the UAC fails to retrieve elevation, i want to continue the batch script while still running invisible. How can i do this? |
|
| 1150. |
Solve : Who can help me create a script to stop MySpecific.exe process but only when CPU? |
|
Answer» Who can help me create a script to monitor and stop automatically MySpecific.exe process but only when CPU ACTIVITY is idle for a given period of time? |
|