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.
| 2151. |
Solve : how to run an ftp script silently?? |
|
Answer» HI all, so I am trying to RUN a batch file to upload file via ftp using an ftp utility called cmdftp. It is almost the same as window's NATIVE ftp. I know how to run the batch file silently, but the batch file calls a text script that I don't know how to hide (so WHENEVER this file runs, the command line WINDOWS will pop up until it is finished) the batch file is (you can actually replace cmdftp with ftp) Code: [Select]cmdftp -s:ftpscript.txt -d:"Log.txt" the script is Code: [Select]open ftp.drivehq.com USERNAME xxxxxxxxx cd test delete orders.xml.bak rename orders.xml orders.xml.bak put c:\test\orders.xml quit I think i need to add something to the script file to make it run silently but I don't know what, echo off doesn't work. Any help is greatly appreciated!Did you try redirecting everything to NUL? Code: [Select]cmdftp -s:ftpscript.txt > NUL 2>&1 |
|
| 2152. |
Solve : Administrator privilege run code? |
|
Answer» Hi all, |
|
| 2153. |
Solve : Square roots in a batch file?? |
|
Answer» I'd like to start off saying I'm no expert in programming, so don't expect me to know exactly what you're talking about. I'm trying to write a batch file that automatically solves quadratic equations, and I have most of it figured out. I just can't figure out how to find the square root of a number. It WOULD also be NICE if you could tell me how to graph something too. I'm trying to write a batch file that automatically solves quadratic equations, and I have most of it figured out I, for one would truly love to see your code. hmm...that's pretty interesting. Now I just have to figure out how to put that into a batch file I'll post the code once I have everything figured out...thanks for the helpCan anybody think of a way to put this into a batch file? Quote from: juniorgiant8 on June 11, 2008, 02:05:45 PM I'll post the code once I have everything figured out...thanks for the help Quote from: Sidewinder on June 11, 2008, 01:58:32 PM I, for one would truly love to see your code. I would like to see it too. Show us what you've got so far, so we can understand where you are going with this. (It might help us to find the answer you need.) dont batch files only work for cmd? how are you going to get cmd to solve your math problums?seriously, why should you use batch for such things as solving quadratic equations? Get a real programming language.! Since batch arithmetic only knows about integers, I think that finding square roots might be quite hard. Here's what I have so far... echo off :input echo what is A? set /p A= echo what is B? set /p B= echo what is C? set /p C= goto calculate :calculate set /a discrim=%B%*%B%-4*%A%*%C% echo discriminant is %discrim% goto positive :positive echo Is the discriminant positive? set /p pos= if %pos% equ y goto square if %pos% lss y goto positive if %pos% gtr y goto positive if %pos% equ n goto imaginary if %pos% lss n goto positive if %pos% gtr n goto positive :square echo Is the discriminant a perfect square? set /p sq= if %sq% equ y goto graph if %sq% lss y goto square if %sq% gtr y goto square if %sq% equ n goto quad if %sq% lss n goto square if %sq% gtr n goto square :imaginary echo Error...cannot be solved as roots are imaginary goto input :quad set /a roots= :graph Also, I don't know any other programming languages yet I was just fooling around with batch files and came up with this idea...If you have any suggestions for a different programming language to use please tell me where a good guide is so I know how to use it. Code: [Select]if %pos% equ y goto square I think you meant this Code: [Select]if %pos% equ %y% goto square Quote Can anybody think of a way to put this into a batch file? I thought it might be interesting to follow the instructions from the link. This is actually easier to do with a pencil and paper than with batch language but if the ancient Greeks could do it, why not us? Except for perfect squares, square roots are irrational numbers and any mechanical method will only give close approximations. Code: [Select]echo off setlocal enabledelayedexpansion set count=0 set /p dend=Enter Number: set num=%dend% for /l %%i in (%dend%, -1, 1) do ( set /a sqr=%%i*%%i if !sqr! leq %dend% ( set digit=%%i. set root=%%i goto out ) ) :out call set /a count=%%count%%+1 if %count% GTR 5 goto next set /a dend=(%dend%-%sqr%)*100 set /a div=%root%*2 for /l %%i in (9,-1,0) do ( set /a sqr=%div%%%i*%%i if !sqr! leq %dend% ( set root=%root%%%i goto out ) ) :next set root=%root:~-5% if %dend% neq 0 set digit=%digit%%root% echo Square Root of %num% is %digit% Precision is 5 decimals. The code can be tweaked if you require changes. Note: This runs at glacial speed with large numbers. Edit: I was typing this when you made your last post. Most script languages have a square root function which would put the above code to shame. Check out VBSCRIPT (installed with Windows), Python (requires download) or even the C language. Good luck. Quote from: Dias de verano on June 12, 2008, 01:17:15 PM Code: [Select]if %pos% equ y goto square No, I tried that in a program without using %y% and it worked just fine y is supposed to mean yes. I guess I could add (y/n) to the question...Lol that looks really complicated Sidewinder. I just tried it and it doesn't work...it just closes out after I enter the number. I'll take a CLOSER look and try to figure out what is wrong. Maybe I should look into another programming language I had to make a quick edit, but it only dealt with the format of the output line. I cannot duplicate your results. Did you cut and paste all the code? Posters in the past have had problems with copying code off the boards. Quote Lol that looks really complicated Sidewinder That's why calculator were invented. yeah I couldn't get it to work... I think I copied the WHOLE thing |
|
| 2154. |
Solve : run program on a specific processor in a multi-core environment? |
|
Answer» Dear All |
|
| 2155. |
Solve : Gulp boy do I have a boo boo? |
|
Answer» While trying to USE my restore CD I accidentally hit the OPEN to the A:\ prompt. How do I get back to the windows start screen. As far as I KNOW I have not successfully rebooted the restore cd because of a Norton software GHOST that was running. I am trying to go back to the windows start screen so that I can get rid of the Norton software and restore and reboot. Is there hope that I can get this done? If all you did was SWITCH into the command prompt, a simple reset should fix that just fine. Or you could type "exit" or "reboot" in the prompt. |
|
| 2156. |
Solve : Find and Replace & File In Use? |
|
Answer» Hello... Here is my problem and my SOLUTION which I am having some problems with in a batch file on WINDOWS 2000 and XP platforms. |
|
| 2157. |
Solve : Help echo. is not recognized? |
|
Answer» Dear All, |
|
| 2158. |
Solve : Need help creating a specific batch? |
|
Answer» I just need a simple batch that will GO 2 directories deep and DELETE files that lack specific values in their NAME. |
|
| 2159. |
Solve : Deleting a DOS file? |
|
Answer» I tried to delete the "iolo" program file through DOS. It tells me access is denied |
|
| 2160. |
Solve : copy 3 files to every directory in a certiain folder? |
|
Answer» i compiled it to a exe file, in order to keep the 3 files also Code: [Select]set /p folder=Type in the directory please (ex. C:\desktop\uploads\) YES!! thank u Quote from: Dias de verano on August 21, 2008, 03:44:05 PM Do NOT post exe files. You should remove it straight away.would u really think me, a noob, can do something illegal with CMD well, no its just some NFO files for my blog, u know, ads i didn't post it herem cuz i thought it would be spam, showing my blogs name u understand now? thank you both Quote from: ehsan_08 on August 21, 2008, 05:45:45 PM Quote from: fireballs on August 21, 2008, 03:22:17 PMSorry, we dont know if you are a noob or not I did remove your file, please just post the source of the file. Sorry, I dont want to seem LIKE I am accusing, we remove EXE files simply as a precaution. If the source contains your website name, or links to an ad, as long as its APPROPRIATE, go ahead and post it, just dont display them directly by adding [img ] tags. yeah, im sorry and about the exe files too i was just trying to not break the rules well, i finished what i need it thanks |
|
| 2161. |
Solve : How do I access an external drive from DOS?? |
|
Answer» Hello |
|
| 2162. |
Solve : Help required...?? |
|
Answer» Hello, |
|
| 2163. |
Solve : Read torrent File Names, Find corresponding Folder or File, Move DATA into a DIR? |
|
Answer» Is there any way to make a batch script to read the names of a bunch of torrent files in a directory ( C:\Documents and Settings\USER\APPLICATION Data\uTorrent ) |
|
| 2164. |
Solve : Writing batch file for .dbf? |
|
Answer» Good day , |
|
| 2165. |
Solve : Close Open Network Files? |
|
Answer» Hi I am trying to write a batch to close open network files before I upgrade my program. What I need to do is... can you get the ID number in a text file? if so this will close the files: Code: [Select]net files > net.txt for /f "tokens=1-2 delims= " %%A in ('type net.txt |^ find "myprog"') do ( Net Files %%a /close exit This is the output from net.txt ------------------------------------------------------------------------------------------------------- ID Path User name # Locks -------------------------------------------------------------------------------------------------- 994 C:\myprog\...\mgxerces-c_2_6.dll RAPSTER 0 1104 C:\myprog RAPSTER 0 1105 C:\myprog RAPSTER 0 1126 C:\myprog\...\mgicuuc32.dll RAPSTER 0 1127 C:\myprog\...\mgicudt32.dll RAPSTER 0 1128 C:\myprog\...\MGmerge.dll RAPSTER 0 1129 C:\myprog\...\MGrqgnrc94.dll RAPSTER 0 1130 C:\myprog\...\MG_OCX.DLL RAPSTER 0 1131 C:\myprog\...\mgrqsoap.dll RAPSTER 0 1133 C:\myprog\...\mgresrc.dll RAPSTER 0 1138 C:\myprog\...\GATEWAYS\MGMS7.DLL RAPSTER 0 1139 C:\myprog\...\GATEWAYS\MGMEMORY.DLL RAPSTER 0 1141 C:\myprog\...\LIBEAY32.dll RAPSTER 0 1169 C:\myprog\...\AMSPROD92704sp8.MFF RAPSTER 0 1177 C:\myprog\...\mglock1.dat RAPSTER 0 The command completed successfully. _______________________________________ ________________________ I tried this but it said "%%A was unexpected at this time" I am not sure how this command works but I may have type it wrong? Quote from: devcom on August 30, 2008, 12:53:22 PM Code: [Select]echo off I tried this one to but it is prob the way i explained it and that I don't really know what this code is doing so I may have explained and or miss typed thecode when I tried itBased on your listing, you need to match myprog not myprog.exe Code: [Select]echo off for /f %%a in ('net files ^| find /i "myprog"') do ( net files %%a /close ) pause > nul Quote from: Sidewinder on August 30, 2008, 03:00:23 PM Based on your listing, you need to match myprog not myprog.exe The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need SOMETHING to kill the ID Number Code: [Select]net files IDnumberhere /close In the txt file that net files > net.txt grabs the ID is random for each file that is open by the user... net.txt ------------------------------------------------------------------------------------ ID 994 C:\myprog\...\mgxerces-c_2_6.dll RAPSTER 0 1104 C:\myprog RAPSTER 0 Quote The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number Understood. net file - Displays all the open shared files on a server and the lock-id net file id /close - Close a shared file (disconnect other users and remove file locks) Code: [Select]echo off for /f %%a in ('net file ^| find /i "myprog"') do ( net file %%a /close ) pause Does the above code work? Might be better to copy/paste rather than re-type. Doesn't closing shared files make the executing program unstable? Quote from: Sidewinder on August 30, 2008, 03:55:01 PM QuoteThe reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number C:\Documents and Settings\Administrator\Desktop> Code: [Select]net files > net.txt Code: [Select]for /f %%a in ('net.txt ^| find /i "myprog"') do (net files %%a /close) Result %%a was unexpected at this time. Closing the files has never hurt anything before we are replacing all the files they are using in the "myprog" folder at the time of the upgrade but most people go home at the end of the day leaving the program open Did I type the code wrong? that is the result I got from RUNNING it.. And thanks for working with me on this to everyone... I apologize for my minimal skill in code.... Quote from: rmathes on August 30, 2008, 04:33:34 PM Quote from: Sidewinder on August 30, 2008, 03:55:01 PMUser Error.... I did the copy paste this time... the code works as it should !! Thanks a bunch.,,,QuoteThe reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number |
|
| 2166. |
Solve : Able to clear history and cookies with Batch?? |
|
Answer» Hey guys, would it be possible in Batch to clear your internet browsing history and cookies?, Thanks. Clipper34you COULD just delete the cookies from your cookies folder under Documents and Settings. by using the delete command. |
|
| 2167. |
Solve : In DOS, how to include a Pipe | character to pipe it to CLIP? |
|
Answer» Thank you in advance for any help |
|
| 2168. |
Solve : MSDOS Print Redirection? |
|
Answer» I have a legacy system RUNNING on DOS, printer is not working. So I need to redirect LPT PORT from DOS system to another WINDOWS 10 system. LPT port of DOS system will go as input (COM) port of Windows 10. In this CASE how can I collect the print from DOS PC on Windows? DOS is printing TEXT files only. |
|
| 2169. |
Solve : Move command. Overwrite ? yes/no/all? |
|
Answer» WinXp Cmd prompt. |
|
| 2170. |
Solve : Minimize an already open window?? |
|
Answer» I'm trying to use my batch file, to close a previously opened window. for some reason I can't open it minimized via the batch file. The program is housed on a server i don't have direct access to. So it seems to me, finding a way to minimize it is the answer.What program ? ?...what is the server running OS ? ?...if it's not your server you will get no help here.I agree with Patio. More detail needed here. |
|
| 2171. |
Solve : How can I compress multiple depth subfolders?? |
|
Answer» Can anyone HELP me with a batch file to compress MULTIPLE DEPTH SUBDIRECTORIES?
Any help would be greatly appreciated. |
|
| 2172. |
Solve : How to run sed.exe in Windows10? |
|
Answer» On BSD, I've been running runsed with sedscr for many years. |
|
| 2173. |
Solve : How Can I get IP and MAC address for remote PCs over the network by batch file? |
|
Answer» Hi All,
but you didn't get my point, I want to get all Hostnames located inside the text file then process it by bat file then output to another text file SORTED looks like that Hostname: IP: MAC for each hostFirst , You should make an effort and show us your try with your own code ! May be this can help you to construct your own code : How to USE an IP Address to Find a MAC Address He doesn't try...he just wants people writing code for him... Not once has he posted anything he did himself. Quote from: Hackoo on December 31, 2020, 12:47:35 PM First , You should make an effort and show us your try with your own code ! Dear Hacoo Thanks for your gentle reply and here is my code echo off echo All Information >"Hosts Info.txt" echo. >>"Hosts Info.txt" For /f %%d in (hosts.txt) do ( echo. %%d >>"Hosts Info.txt" getmac /s %%d /v /nh >>"Hosts Info.txt" ping %%d |find "Ping statistics for" >>"Hosts Info.txt" echo._______________________________ >>"Hosts Info.txt" ) pause exit but it's so dummied as I don't know but a few things about the batch programming, so I'm trying to do my best and I can't deal ever with many things like ( "tokens & delims" , " ~ " , " 1% " , " find "," findstr" ) What is these things means and how we use it But I try to find what I want from some people's ideas and try to imitate them in some codes, but I do not reach the DESIRED result most of the time due to my ignorance of most of the language of the batch files but I'm still trying to learn - The previous getmac code give me the whole NIC MAC with manufacturere with many details For example: Ethernet Intel(R) Ethern 8C-Df-D5-4e-a8-72 \Device\Tcpip_{817345F1-e93E-44D7-B19a-70F0f4F73Ec4} and i want only tha mac address 8C-Df-D5-4e-a8-72 And The previous Ping code give me also the whole the Ping statistics result for Example : Ping statistics for 172.217.17.238: and i just need the IP only like that 172.217.17.238 And finally if you can to help me to put all the results to gether in one line you are highly appretiated and if you won't also you are highly appretiated for the previous & gentle help Ok, First, we should proceed to your problem step by step What result did you get when you type this command with your cmd ? Code: [Select]getmac /s localhost /v /nh /fo csv | find /I "N/A"Unfortunately after tried this code on my PC at home I didn't get anything even after saving the result into a text file as attached screenshot, so I'll go to my work tomorrow then I'll try the same code again on any workstation inside my domain and feed back to you with the result Quote from: Abo-Zead on January 02, 2021, 07:51:25 AM Unfortunately after tried this code on my PC at home I didn't get anything even after saving the result into a text file as attached screenshot, so I'll go to my work tomorrow then I'll try the same code again on any workstation inside my domain and feed back to you with the resultNo problem; can you post me the result of this command without find /I "N/A" I mean like this : Code: [Select]getmac /s localhost /v /nh /fo csvI got as result like this one : Code: [Select]"Ethernet","Broadcom NetLink (TM) Gigabit Ethernet","XX-XX-XX-XX-XX-XX","Support déconnecté" "Wi-Fi","Qualcomm Atheros AR5BWB222 Wireless Network Adapter","XX-XX-XX-XX-XX-XX","N/A" "Ethernet 2","TAP-Windows Adapter V9","XX-XX-XX-XX-XX-XX","Support déconnecté" "Connexion réseau Bluetooth","Bluetooth Device (Personal Area Network)","XX-XX-XX-XX-XX-XX","Support déconnecté"After using this code I got that result now "Ethernet","Intel(R) Ethernet Connection I217-LM","XX-XX-XX-XX-XX-XX","\Device\T cpip_{827317F1-C9XX-XXD9-BXXD-7XXX9BXXXXE4}" "Ethernet 2","TeamViewer VPN Adapter","XX-FF-A7-XX-XX-XX","Media disconnected" "vEthernet (Default Switch)","Hyper-V Virtual Ethernet Adapter","00-15-5D-XX-XX- 32","\Device\Tcpip_{AXXXXDE8-6B77-4XX3-A2XX-XXXF376BXX7F}" "vEthernet (External switch 1)","Hyper-V Virtual Ethernet Adapter #2","XX-XX-XX- XX-XX-XX","\Device\Tcpip_{XXXD4XXX-CXXF-XXDA-97XX-CXXA7946XXX}"Any Idea, How to reduce the output to required needed IP and MAC only Quote from: Abo-Zead on January 03, 2021, 01:31:18 AM Any Idea, How to reduce the output to required needed IP and MAC onlyTry this batch to EXTRACT only MAC and reduce the output result: Code: [Select]echo off Title Extracting only MAC Address from GetMac Command ( for /f "tokens=3 delims=," %%a in ('getmac /s localhost /v /nh /fo csv') do echo %%~a )>"%~dp0MAC-Address.txt" If Exist "%~dp0MAC-Address.txt" Start "" "%~dp0MAC-Address.txt" & Exit Quote from: Hackoo on January 03, 2021, 02:56:41 AM Try this batch to extract only MAC and reduce the output result: Thanks, Hackoo After test your code it works in my workplace but it doesn't work on my PC at home so maybe the problem in my OS at home Kindly how we put this code under for loop? as it does not work with me in my code below Code: [Select]echo off for /f %%i in (hosts.txt) do ( Title Extracting only MAC Address from GetMac Command ( for /f "tokens=3 delims=," %%a in ('getmac /s localhost /v /nh /fo csv') do echo %%~a )>"%~dp0MAC-Address.txt" ) If Exist "%~dp0MAC-Address.txt" Start "" "%~dp0MAC-Address.txt" & Exit also how we can put it with the Hostname and IP in the same row to look like that as I asked in my first question? Hostname: IP: MAC AddressRefer to this thread How to get MAC address of remote computer Suppose that you a have the inputfile with computers or ip address list, you can give a try with batch file : Hosts.txt Code: [Select]192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5 192.168.1.6 192.168.1.7 192.168.1.8 192.168.1.9 192.168.1.10 192.168.1.11 192.168.1.12 192.168.1.13 192.168.1.14 192.168.1.15 192.168.1.16 192.168.1.17 192.168.1.18 192.168.1.19 192.168.1.20IP-MAC-Scan.bat Code: [Select]echo off Set "Copyright=by Hackoo 2021" Title Get IP and MAC address for remote PCs over the network using batch %Copyright% Mode con cols=90 lines=12 cls & color 0A & echo. echo ******************************************************************************** echo Get IP and MAC address for remote PCs over the network %Copyright% echo ******************************************************************************** echo( if _%1_==_Main_ goto :Main :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 set "InputFile=%~dp0Hosts.txt" set "OutPutFile=%~dp0IP-MAC.txt" If Exist "%OutPutFile%" Del "%OutPutFile%" If Not Exist "%InputFile%" ( color 0C & echo "%InputFile%" does not exist. Please check it first ! Timeout /T 8 /NoBreak>nul & Exit ) Netsh interface ip delete arpcache >nul 2>&1 for /f "tokens=* delims=" %%H in ('Type "%InputFile%"') do ( Ping -n 1 %%H>nul for /f "tokens=2" %%M in ('arp -a %%H ^| find "%%H"') do ( echo %%H : %%M echo %%H : %%M>>"%OutPutFile%" ) ) If Exist "%OutPutFile%" Start "" "%OutPutFile%" & Timeout /T 1 /NoBreak>nul & Exit ::-------------------------------------------------------------------------------------Appreciate your effort Hackoo but after test this code in some workstation inside the domain it gives me this message ARP: Bad argument: %hostname% I don't know why?Hackoo After a lot of searches, I found the below code Code: [Select] ECHO OFF For /f %%a in (hosts.txt) do ( ping -n 1 %%a | for /f "tokens=1-4* delims=: " %%i in ('find "Reply"') do ( nbtstat -a %%a | for /f "tokens=1-2 delims=^=" %%x in ('find "MAC Address"') do ( echo [ %%a : %%k : %%y ]>> Host_IP_MAC.txt echo [ %%a : %%k : %%y ] ) ) ) and after testing I found it works only with all workstations working under WinXp only and the rest of the workstations working under Win7, 8, 8.1, and 10 doesn't work, so kindly help If you have an idea to fix this bug.I don't quite understand how you solved your problem? Like you, I have many different hostnames, but I do not know how to get information about all of them at once. Unfortunately, I do not understand the software part at all. This was done by my partner, who literally went on vacation two days ago. Therefore, I am literally at a dead end, I hope it will not be difficult for you to suggest a solution to my problem. I thought that I could somehow call all the hosts I needed using 192.168, but unfortunately I didn't succeed. So I stopped trying to do something by myself. Nowadays, literally any problem can be solved via the Internet, so I thought that my problem could also be solved. |
|
| 2174. |
Solve : Extracting string starting with and ending with specific strings? |
|
Answer» OK, this is totally over my head here. Never learned all this (for /f "tokens) stuff. |
|
| 2175. |
Solve : %~dp0 vs %cd%? |
|
Answer» Hello, It's been 4 years... So what? I stumbled upon this thread today and found both replies useful. Quote from: mplichta on March 23, 2012, 09:59:01 AM There is one more important distinction to note. Normally the command prompt, and therefore cmd files, don't support UNC paths. I don't think you are correct. This should work just fine Code: [Select]xcopy "\\server\share1\*.txt" "\\server\share2\" and this too: Code: [Select]pushd "\\server\share\software\adobe CS5" msiexec "\DP 32bit Basic\Build\DP 32bit Basic.msi" /q popd More specifically, cmd.exe (including executed .bat files, .cmd files, etc.) does not support the current/working directory to be a UNC path. pushd gets around this by assigning and switching to a drive letter that is mapped to the target path, and most other programs (commandline or not) work PERFECTLY fine with a UNC path. Quote from: patio on March 23, 2012, 10:00:55 AM It's been 4 years...Quote from: patio on March 23, 2012, 10:00:55 AM It's been 4 years... I wonder if this topic will be dredged up again in 2016. Judging by it's history...i'd say that's a safe bet... Seeya then...Not quite 2016 yet, but I found this very helpful. Quote from: patio on March 23, 2012, 10:00:55 AM It's been 4 years...Batch is slow... Quote from: foxidrive on October 18, 2012, 09:23:30 AM I wonder if this topic will be dredged up again in 2016.Close enough.This thread helped me out with a batch script at the end of last year. Thank you so much! Quote from: foxidrive on October 18, 2012, 09:23:30 AM I wonder if this topic will be dredged up again in 2016. Sonofagun....you were correct.... LOL Like the Matrix Oracle ...would you like a cookie It's had a good run - but I might be 6 foot under in 2020 I'm just here for 2017, don't mind me. Quote from: foxidrive on October 18, 2012, 09:23:30 AM I wonder if this topic will be dredged up again in 2016. Even after 4 years...... *** sigh *** Quote from: foxidrive on January 05, 2016, 03:01:11 AM It's had a good run - but I might be 6 foot under in 2020RIP my friend.As the former Dias de Verano, can I say (a little early) happy 10th anniversary to this thread! Tell good 'ol Diaz i said Hi...... He says hola, mi amigo! Quote from: Squashman on March 17, 2018, 10:03:07 PM RIP my friend.When did he pass away? Thursday Nov 3rd 2016. Don's Topic Dostips Topic Quote from: Geek-9pm on March 18, 2018, 02:16:42 PM When did he pass away?Shortly before you said how sad it was. Foxidrive Quote passed away on Thursday 3rd November 2016My memory is fading. Could somebody put a note in his profile? Quote from: foxidrive on January 05, 2016, 03:01:11 AM It's had a good run - but I might be 6 foot under in 2020Not quite 2020, yet, but I registered in late 2019 just to say that this thread was useful to me. I was trying to understand what pushd "%~dp0" ment, I googled it, and now I understand it because of this thread. Only 14 days from 2020 lol! thank you, contributors to this post, and a posthumous thank you and RIP to foxidriveRIP... I have been around PCs all my life. I have been in IT for 20+ years and have never came across %~dp0 before. No idea why. I am glad I came across this post to better understand this hidden gem. Thanks for the info everyone. This thread helped me about two years ago (august 2018 WTD), but DUE to thread policy I head to wait until 2020 to reply Thanks GUYS!! Quote from: patio on March 23, 2012, 10:00:55 AM It's been 4 years...It's been... another 4 years... I using a MiSTer FPGA to run a DOS core, and looking into batch scripting, but just cannot figure out how to get the path to the currently active directory. I cannot get %~dp0 to work either... but trying to experiment some more. I am trying with FreeDOS, DOS 6.22 and DOS 7.1. But I guess I have to make sure I did try all of them.%~dp0 and things like %cd% are part of the NT Extensions that were added to the command prompt with Windows NT4. the "cd" command by itself outputs the current directory, but I don't know a way you can get that into an environment variable without utilizing things like QBASIC.Somehow i knew in the back of my mind it would be Dias ressurecting this one... Who is that masked man ? ? Quote from: rajubhaiya on September 17, 2020, 04:21:44 AM
You are not the "former Dias de Verano". Hey Mike, hope all is well. Good to see you back.We can forget about 2020 right Quote from: Caldor on August 05, 2020, 07:54:58 AM It's been... another 4 years... Resurrection time! Works with MS-DOS 7 and I have no reason to think it won't work with (say) 6.22 Code: [Select]echo off >temp1.bat echo PROMPT SET _CD=$P >temp2.bat command /c temp1.bat call temp2.bat del temp1.bat del temp2.bat echo currentDir=%_CD% |
|
| 2176. |
Solve : Batch file needed to wrap entire text column in double quotes? |
|
Answer» Just JOINED here to ask this ! I have a TEXT file that has multiple lines without any QUOTES. I NEED a batch file that will append a single double QUOTE at the beginning of the first line (not on a separate line by itself , it must be the first character on the first line) I need the same for the very last line position also. So to end up looking like "One Two Three Four Five Six Seven" ...Therefore wrapping the entire column. I hope you guys can solve this for me as its been driving me nuts ! Thanks in advance !It is customary to post whatever code you have created so we can better see where you're going with this. In any case, my batch codes days are pretty much behind me, but I did come up with this: Code: [Select]echo off setlocal enabledelayedexpansion set count=0 set ifile=g:\wfc\testlib\hope.txt set ofile=c:\temp\hopeless.txt for /f %%b in ('type !ifile! ^| find "" /v /c') do set ubound=%%b for /f %%i in (!ifile!) do ( set /a count=!count!+1 if !count! EQU 1 ( echo ^"%%i >> !ofile! ) else if !count! EQU !ubound! ( echo %%i^" >> !ofile! ) else ( echo %%i >> !ofile! ) ) Change the ifile and ofile values in the set statements to match your environment. Happy Coding |
|
| 2177. |
Solve : Can we display the content of a variable that itself is the content of another ?? |
|
Answer» Hi all |
|
| 2178. |
Solve : Create strings using echo commands? |
|
Answer» So, I started messing around with a .bat file and started learning how to use variables, user input, show TEXT using the commands: echo,set,etc. |
|
| 2179. |
Solve : String Spaces,New Lines and Inserting Text? |
|
Answer» So. I have a string that I create WITHIN a file and I want to put spaces,new LINES and add some input in the code but it doesn't work. |
|
| 2180. |
Solve : Run CMD Commands in Batch Files? |
|
Answer» How do I run multiple cmd commands in a batch file? /K Run Command and then return to the CMD PROMPT. |
|
| 2181. |
Solve : How to launch windows program in DOS at OS selection screen?? |
|
Answer» HELLO members, How to launch windows program in DOS at OS selection screen during boot? To share the concern better, I have made a video taken from SOMEONE's computer and WISH to setup same at mine. Kindly have a look at the following link: https://youtu.be/YAO9OGsNBUw Please guide, advance thanks!!They have a Dual boot between Windows XP and MS-DOS. For some reason the MS-DOS Boot.ini entry is called "MICROSOFT Windows". I don't think you can run a Windows program from within Dos alone, but it appears that program in the video is some sort of Dos based program. Why don't you try adding that command to Autoexec.bat and SEE if it will load that way? |
|
| 2182. |
Solve : Combining multiple filepaths into one line? |
|
Answer» I would like to streamline some of the functions I do constantly. One of which is copying the filepaths of multiple files and making one line of text for example: |
|
| 2183. |
Solve : Equivalent of Unix eval in Windows? |
|
Answer» Hi, Thanx again... Have you typed FOR /? and read the help? Yes I read the FOR help. But I think you didnt get the real requirement. When I did del myset.cmd & FOR /F %i in ('sb-config --env') do echo SET %i >> myset.cmd It was printing 2 lines of "SET set" into the myset.cmd file. But this one: del myset.cmd & FOR /F "tokens=1,2" %i in ('sb-config --env') do echo SET %i %j >> myset.cmd It was printing the command output with a SET prepended to each line. But I dont want to prefix anything to the output of the command. The command "sb-config --env" output following lines: set STREAMBASE_HOME="D:\StreamBase\StreamBase.6.3" set PATH="D:\StreamBase\StreamBase.6.3\bin";%PATH% I just want to execute them. I already know that I can do sb-config --env > sbenv.cmd call sbenv.cmd del sbenv.cmd Is there any better ways of doing this. ie. without creating an temp cmd file. Thanks and Regards, Preeth I dont think it was appreciated that SET appeared in the output Try this FOR /F "tokens=1,2" %i in ('sb-config --env') do Call %i %j I am getting confused myself. What is the result of including sb-config --env in a batch script? or typing it at the prompt? From the original post Quote "sb-config --env" returns the commands to set some environment variables. The result is having multiples lines of SET commands.So you want to execute each line. What about this? Code: [Select]For /f "delims=" %%A in ('sb-config --env') do call %%A For /f "delims=" %%A in ('sb-config --env') do call %%A is working for me. Thanks GPL and Salmon. |
|
| 2184. |
Solve : How to suppres "command" window flashing? |
|
Answer» Hi, there, Hi, there, Not sure I understand. You have a Windows program that calls a batch file which launches a Windows program? Why not eliminate the batch file and have the first Windows program directly launch the second Windows program? What programs are you using? sosnov, Wlecome to CH. Lots of people here are willing to help you with a problem. We do not understand your problem. A DOS screen can be MINIMIZED to the task bar. But making it not visible on the task bar is a poor idea for most cases. However, if the task bar is annoying, or if it takes too much SPACE, you can hide it so that it shows only when the mouse is at the bottom of the screen. Or, it can be set so the any full screen application will cover it. Is that what you want? |
|
| 2185. |
Solve : I want to create a batch script which can search for .jpg and .jpeg? |
|
Answer» I want to create a batch script which can search for .jpg and .jpeg search for .jpg and .jpeg Quote once found they must get copied. Well, assuming you read the question, your output "proves" that your code doesn't work Here is what I got. echo off for /F %%a in ('mountvol ^| find ":\"') do ( dir %%a 1>nul 2>nul if not ErrorLevel 1 ( copy %%a*.jpg copy %%a*.jpeg ) ) This script searches the physical drive but does not search into the folders and subfolders, so can anyone modify the script and give me a script which will fully search the physical drive including folders and subfolders.I want to help you, but in my own way. For me to use your script would be a chore. My approach to this, and other jobs, is to consider the objective. First Step: Objective: Once the objective is know, it is time to create an abs tact idea or concept. Then create a method that is suitable. The objective has to be reasonable. The provided a script does not indicate a clearly stated objective. Second Step: Method. Batch MAY be a suitable method. A short, concise command is admirable, butcan be difficult to adapt. Breaking a hob into tasks can help. Third Step: Use restraint. The Operating system has some practical limits on what it can do at one time.In Batch there is a PROBLEM of DELAYED execution and extentions enbabled. Also placing an unlimited number of files of unknown size into one directory may crash the system. The FOR loop contains not only technical syntax problems but also weak logic. Do you understand the , TAKEN literally, your idea can make the Operating system unstable. It may even produce a fatal error. And there's more... but I will let others say.OKay then can yoiu help me with a single drive. Lets take with D Drive, there are few pictures that I need to get copied, will you help me with this please.before running this snippet, make sureto change the destfolder. Code: [Select]SETLOCAL EnableDelayedExpansion set destfolder=D:\copiedjpegs for /F %%a in ('mountvol ^| find ":\"') do ( for /f "tokens=*" %%P in ('dir %%a\*.jp*g /s /b') do copy %%P !destfolder! ) only problem I can think of for the above is that *.jp*g can match jpog and jpag and so forth; but these extensions aren't common file types so likely won't be encountered. Also, since it will search ALL drives, the destination folder will inevitably be searched; I believe it will error at that point but the loop should simply report the error (file cannot be copied onto itself) and continue. I'm also uncertain wether I need the EXCLAMATION marks or delayed expansion, since destfolder remains unchanged during the loop. that din't worked. Quote from: akki15623 on December 16, 2009, 12:43:01 PM that din't worked.explain. EDIT: it was a simple typo that I changed in my copy but not in the copy I posted. Code: [Select] SETLOCAL EnableDelayedExpansion set destfolder=D:\copiedjpegs for /F %%a in ('mountvol ^| find ":\"') do ( for /f "tokens=*" %%P in ('dir %%a*.jp*g /s /b') do copy "%%P" !destfolder! ) there was a slash between the %%a and the *.jp*g, which is not necessary since mountvol includes the slash. EDIT: Oh, and I forgot quotes. Quote from: BC_Programmer on December 16, 2009, 12:32:57 PM only problem I can think of for the above is that *.jp*g can match jpog and jpag and so forth Perhaps... Code: [Select]('dir /s /b %%a*.jp*g ^| find ".jpg ^| find ".jpeg" /s /b') Or explicitly test for the wanted extensions... Code: [Select]set destfolder=D:\copiedjpegs for /F %%a in ('mountvol ^| find ":\"') do ( for /f "tokens=*" %%P in ('dir %%a*.jp*g /s /b') do ( if /i "%%~xP"==".jpg" copy "%%P" !destfolder! if /i "%%~xP"==".jpeg" copy "%%P" !destfolder! ) ) Quote I'm also uncertain wether I need the exclamation marks or delayed expansion, since destfolder remains unchanged during the loop. You don't. Quote from: BC_Programmer on December 16, 2009, 12:43:17 PM explain. Worked perfectly...... Thanks, thank you very much buddy...... Quote from: akki15623 on December 16, 2009, 01:24:03 AM I want to create a batch script which can search for .jpg and .jpeg C:\batch>type bc1215.bat Code: [Select]SETLOCAL EnableDelayedExpansion set destfolder=E:\copiedjpegs E: dir /s /b *.jpg > jpgfiles.txt for /f "tokens=*" %%P in (jpgfiles.txt ) do copy %%P !destfolder! ) dir E:\copiedjpegs\ | more OUTPUT: C:\batch> bc1215.bat Directory of E:\copiedjpegs 12/16/2009 02:21 PM . 12/16/2009 02:21 PM .. 05/14/2005 03:44 PM 1,390,722 002.jpg 12/26/2002 11:26 AM 63,683 03.JPG 05/03/2006 01:05 PM 2,199,973 050206.jpg 02/03/2003 01:32 AM 20,443 1.jpg 02/03/2003 01:31 AM 11,601 10.jpg 02/03/2003 01:23 AM 11,178 11.jpg 02/03/2003 01:21 AM 16,492 12.jpg 11/02/2002 06:05 PM 84,884 14.jpg 12/29/2004 10:01 PM 10,039 1map.jpg 02/19/2006 01:02 PM 2,318,092 2-18-06.jpg 02/03/2003 01:10 AM 15,026 2.jpg 12/28/2004 10:57 AM 30,112 20_months.jpg 12/29/2004 10:01 PM 8,086 2map.jpg 02/03/2003 01:18 AM 199,266 3.jpg 12/28/2002 04:14 AM 30,008 4.jpg 11/12/1998 08:48 PM 62,325 457015.jpg 11/12/1998 08:50 PM 71,110 457030.jpg 11/12/1998 09:46 PM 104,355 487071.jpg 11/12/1998 09:46 PM 70,428 487072.jpg 02/03/2003 01:18 AM 5,437 5.jpg 11/12/1998 10:07 PM 57,326 577092.jpg 11/12/1998 07:52 PM 86,958 594008.jpg 12/29/2004 10:01 PM 10,039 5map.jpg 02/03/2003 01:16 AM 8,193 6.jpg 11/13/1998 02:45 AM 51,505 643047.jpg 11/13/1998 02:46 AM 55,217 643057.jpg 11/11/1998 10:25 PM 101,750 677023.jpg 11/12/1998 02:11 AM 82,308 682008.jpg 11/12/1998 02:25 AM 92,993 682097.jpg 04/28/2002 07:12 PM 25,813 7.jpg 03/29/2005 11:41 PM 104,563 70.jpg 11/12/1998 01:30 AM 31,173 719024.jpg 11/12/1998 01:32 AM 55,994 719038.jpg 11/12/1998 01:40 AM 63,905 719090.jpg 11/12/1998 01:41 AM 44,786 719098.jpg 11/12/1998 10:30 PM 75,614 762000.jpg 11/12/1998 10:39 PM 69,560 762055.jpg C:\batch> Quote from: BC_Programmer on December 16, 2009, 12:43:17 PM explain. Can you help me with one more thing. I will send the above script to my girlfriend PC, is there a way that you can modify this so that it can send all the pics to my e-mail???um... no I don't think so. you could zip them via the command-line but the attachment will be huge... and I don't know how to do SMTP/e-mail from batch. |
|
| 2186. |
Solve : need help: How to write a batch to combine more 100 text files to one text file?? |
|
Answer» Quote from: HELPMEH on December 15, 2009, 06:58:16 PM Hey bill, try reading next time. I meant to say I could not get the following code to work on my machine: echo off for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt The solutions offered here on the Hope Board are not just for the Original poster. Many readers can often use the information. I wonder if Helpme can show us the output for: echo off for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt Must we offer a new "ENDNUMBER" each time we run the code? I use XP. Will the above code run for XP? An example of the Output of all code offered will help the OP plus the readers. Thank you Helpmeh for your time and effort. You replace ENDNUMBER with the number in the last file. The OP perfectly understood, and it seemed very obvious to replace it. And no, I can not run it, as I am not on a computer. what bill (or joan or liz or mike or ??) meant is OP won't know the ENDNUMBER before hand unless he can find out from dir *.txt and change the code. Its probably BETTER not to use the for loop range + step method, but just use the output from dir file*.txt Code: [Select]for .... (dir file*.txt) do ( type .... >> output.txt ) how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank replace the "set I=1" for the number the file sequence starts Code: [Select]echo off :recurse set I=1 cd FOR /f "tokens=*" %%P IN ('dir /A-d /B *.txt') do (call :showfiles "%%P") echo. echo Filecount: %I% for /l %%a in (0,1,%I%) do type file%%a.txt >> endresult.txt :showfiles echo %1 set /a I+=1 goto :eof Quote from: BatchFileBasics on December 15, 2009, 08:17:51 PM how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank why not just do dir file*txt ? there's no need to call another loop to count total files. Of course, unless there other files with names like filetest.txt , fileblahblah.txt and you want to isolate those that have numbers following "file", which you could do that with dir file*txt | findstr /I "file[0-9]*.txt" Quote from: BatchFileBasics on December 15, 2009, 08:17:51 PM how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank Where is Output? Quote from: billrich on December 15, 2009, 09:18:42 PM Why don't YOU run it and put out any output it MAKES, instead of "Where is output?" over and over again. Sometimes you really sound like a broken record. Quote from: Helpmeh on December 16, 2009, 04:56:58 AM Why don't YOU run it and put out any output it makes, instead of "Where is output?" over and over again. Sometimes you really sound like a broken record. I don't think I WOULD have bought that record in the first place, let alone played it after it was broken. Anyhow, wasn't he banned? Why is he now unbanned? Quote from: Salmon Trout on December 16, 2009, 05:08:00 AM I don't think I would have bought that record in the first place, let alone played it after it was broken. Anyhow, wasn't he banned? Why is he now unbanned?New name...lowercase b is all it takes. Quote from: Helpmeh on December 16, 2009, 07:08:38 AM New name...lowercase b is all it takes. ------------------------------------- Show your code and show output and stop faking it. Quote from: billrich on December 16, 2009, 02:51:16 PM -------------------------------------1. I've shown my code, heck, YOU've even used it in your posts. 2. As I've said before, I don't have access to a computer. I am on my iPod. 3. How am I faking? Read the OP's post. The code worked great for him. Quote from: Helpmeh on December 16, 2009, 05:53:32 PM Read the OP's post. The code worked great for him. The problem is on my end. I could not get the code to work on my machine. I thought I could look at your code and output and figure what I was doing wrong. echo off for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt I might try again. Quote from: billrich on December 16, 2009, 06:08:13 PM The problem is on my end. I could not get the code to work on my machine.Did you change ENDNUMBER? You haven't posted anything but a copypasta of my code. Post the code in YOUR batch file. Quote from: billrich on December 15, 2009, 09:18:42 PM
why do i need output?I think bill is just frustrated because the code doesn't work for him. That happens to the best of us. We get impatient and angry. |
|
| 2187. |
Solve : Up dating/up grading DOS? |
|
Answer» How do I know if I have the LATEST DOS program? How do I up date or up GRADE DOS?Where do find a copy?1. How do I know if I have the latest DOS program? |
|
| 2188. |
Solve : Xcopy /d check? |
|
Answer» Hi there |
|
| 2189. |
Solve : white spaces in path while using start command? |
|
Answer» his %TM% variable was set to a folder name. refer to the ORIGINAL post. The assumption being made is that, although the great Billrich doesn't have this particular folder on his drive, the OP, who defined the criteria upon which everybody (aside from the great Billrich, of course) is making suggestions. the fact that the OP says: Quote set TM="Ticket Folder" basically MEANS that these folders do not actually exist on their machine either, and rather they are providing this code as an example of what they need, which they expressed earlier. There are in fact two issues the OP was having; one was the use of quotes around the folder name, which Salmon Trout explained requires a set of "" to define no title before the quotes around the actual folder name. The folder name itself, as presented by the OP above, is acquired by a path (not necessarily C:\fold1\fold2, but rather that is being used as an alias for the actual folder name and to indicate to those of us with cognitive capabilites that they intend to use this sort of command on folders in the heirarchy) which is built using the TM environment variable. the TM variable is, in his above example, being set to "Ticket Folder" this in and of itself presents another issue; the proper assignment should be, as Helpmeh, another PWWPA (Post Who Was Paying Attention) pointed out, without quotes. INSTEAD, the final command should be Code: [Select]set TM=Ticket Folder start "" "C:\fold1\fold2\%TM%" Now, to clarify again; the folders will probably not exist on anybody elses machine, and in fact since they are simply abstractions of the actual problem and not true folder names on the OP's machine they probably don't exist there. This of course makes it difficult to locate such abstractions on ones PC, especially when you set the variable to the wrong value. But not to worry, the concept is simple to explain. When the OP specified Fold1\fold2\ etc, they are not in fact, speaking of actual folders by this name, but rather they are explaining that they will work with multiple folder names- or more precisely, that the actual names of the folders aren't important. The important point is explained earlier in the post, which is that they are having issues with the start command and using quotes. The examples given also suggest that they have not yet had experience using Environment variables, which, unlike loop variables on the command line (one percent sign preceding) or loop variables in a batch file (two percent signs preceding) require a percent sign on either side of the variable name. Again, having the proper data in the variable is of the utmost importance, and setting it to some arbitrary value is hardly the best way to test the method, especially when the setting given my the OP clearly indicates it is used to specify a single folder name within a folder hierarchy. Considering the length of this post, I can make the apt prediction that by ignoring much if it you'll be able to continue to post your illogic and additionally make comments about how unnecessary the girth of my post was. The fact is your understanding of the concepts involved is the issue, not the length of my post, and your complete avoidance of that issue is what prevents you from learning these new things as they are presented to you, a statement made on several occasions my multiple users.Paraphrasing slightly for the new folks: billrich is a twice banned very stupid troll who keeps coming back to ruin threads with his trash. Quote from: Salmon Trout on December 08, 2009, 12:21:44 AM Paraphrasing slightly for the new folks: billrich is a twice banned very stupid troll who keeps coming back to ruin threads with his trash.Twice?! Quote from: Helpmeh on December 08, 2009, 03:13:02 PM Twice?! I though he must have been banned as JaneDoe or whatever he was calling himself. [Opens new tab) Joanlong I mean. Quote from: Grimbear13 on December 07, 2009, 09:49:26 AM I'm trying to make a startup process at work. I need it to open several programs in a certain order. The problem I keep running into is white spaces in the directories or the folders I need opened. Grimbear, How did you solve the problem of not finding the TM variable and/or folder?trollboy still doesn't get it. Quote from: Salmon Trout on December 08, 2009, 03:16:54 PM I though he must have been banned as JaneDoe or whatever he was calling himself. [Opens new tab) Joanlong I mean. he was also banned as Miketaylor after he sent me a sick (very sick) PM Where is Grimbear? Grimbear, How did you solve the problem of not finding the TM variable and/or folder?He's completely crazy. Quote from: Grimbear13 on December 07, 2009, 09:49:26 AM I need it to open several programs in a certain order. The problem I keep running into is white spaces in the directories or the folders I need opened. Grimbear, I apologize that the thread was unable to remain on topic. Good luck with your project Quote from: billrich on December 09, 2009, 09:57:37 AM I apologize that the thread was unable to remain on topic. Well, it was you, the banned loony, who helped drive it off topic, with your ridiculous posts, so maybe you should just STFU? Why are you still here, by the way? Sorry for not checking this one sooner. This was something that wasn't critical for anything in particular so I actually forgot about it ! But now that I read it thank you so much for the support and I'm going to try some of the stuff that you all mentioned, namely the first set of quotes to declare title and then the full literal path. The variable there was just an attempt to force the folder to open something with a white space because I was hoping that through a variable it would take the literal string. Also i guess I should have mentioned what I was trying to do if I didn't this is a program to run at startup to open the 3 folders that I work out of at work, they need to be opened in sequence so I'm going to have to put a delay between each one because some open faster than OTHERS (they're on different drives). It's a nominally simple task, but my unfamiliarity with batching complicates things . I'm hoping the start command is the proper command to have the folders opened. Thanks again for all the replies |
|
| 2190. |
Solve : Regasm.exe from command line? |
|
Answer» Hi there for %%x in (\\%1\c$\test1\entities\*.dll) do ELIMINATE the /s switch. This will allow the message box text to presumably get redirected to the log file. Quote \\%1\c$\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe "\\%1\c$\test1\entities\function.dll" /codebase >>"file.log" Check out this link where you can set the SecurityPermissionAttribute in the source code. Good luck. Thanks for the response That was very helpful of you Quote from: Sidewinder on December 16, 2009, 04:58:16 PM Eliminate the /s switch. This will allow the message box text to presumably get redirected to the log file. This response was in error. It's true the /s switch and redirection are mutually exclusive, however redirection only works for the STDOUT datastream which is generally found in DOS or NT command line programs. Regsvr32 is a Windows program that probably uses a Windows function to format it's output to a window. Further testing showed that even errorlevels are always zero, whether the registration fails or succeeds. Consider trying one of the Windows Scrpt Languages where you can run regsvr32 externally from the script, wait on return, and check the return code. Sorry for any confusion. regsvr32 shows it's output VIA Messagebox. However, it does return an Exit code. For example- I created the following script to check: Code: [Select]echo off regsvr32 /s C:\windows\system32\vbscript.dll echo errorlevel is %ERRORLEVEL% regsvr32 /s nonexistent.dll echo errorlevel is %ERRORLEVEL% when I run as a non-admin, I get: Quote errorlevel is 5 5 is the windows error code for "permission denied" and 3 is the windows error code for "file not found". When I run as an administrator, I get: Quote errorlevel is 0 so, regsvr32 returns an error level that is either 0 (for success) or a windows error code. Quote from: BC_Programmer on December 17, 2009, 03:14:04 PM so, regsvr32 returns an error level that is either 0 (for success) or a windows error code. It's a bit ODD. When I ran regsvr32 from the command line, then checked the return code, it always came up zero whether it was successful or not. When run from from a batch file, I got the same results as BC. Oh well, at least the OP has a method to run his script. |
|
| 2191. |
Solve : Maintaining the file name in a piped find? |
|
Answer» That's not breaking it because that WORKS fine in the ORIGINAL one that I have.Alternative, using GNU awk. |
|
| 2192. |
Solve : Windows 7 won't recognize my old DOS programs? |
|
Answer» I SUPPOSE it was inevitable, but my new Windows 7 won't load Multimate or my Nutshell Database which I've used since the 80s. The error message suggests I contact the software manufacturer for a program compatible with 64 bits, but it's been out of business for twenty years. Does anyone have a suggestion? ONE of the drawbacks to a 64 bit OS is it's inability to work and play well with some OLD apps. You can try running them in the various compatibility modes or a virtual machine, but in the end 64 bit is not as friendly as 32 bit. Quote from: Allan on December 17, 2009, 06:01:53 AM One of the drawbacks to a 64 bit OS is it's inability to work and play well with some old apps. You can try running them in the various compatibility modes or a virtual machine, but in the end 64 bit is not as friendly as 32 bit. Replace$(Quote,"friendly","Backward compatible",vbtextcompare) Okay, this time you lost me. replace the word "friendly" with "backward compatible". Windows X64 isn't as backward compatible as the 32-bit versions. It only allows for running PROGRAMS that are a mere 15 years old or so.Wait. If you have a very old program you may not be concerned about speed. So why not just run it in a vertebral machine? Cant you do that will old DOS binaries? EDIT; My Bad. I just read this the other day and forgot it. Quote Versions of Windows NT for 64-bit architectures (x64 and IA-64) do not include the NTVDM and are unable to run DOS or 16-bit Windows APPLICATIONS. This is because an x86-64 CPU in its full 64-bit mode cannot go to virtual mode without a hard reset. Virtual mode is not part of the x64 specification; the CPU needs to be running in x86 mode. |
|
| 2193. |
Solve : help - batch file to send automated email when windows service stops? |
|
Answer» The official recommendation for the Windows scripting engine is to use double slashes for switches intended to be read by the engine (cscript.exe or wscript.exe) and single slashes for options intended to be read by the script. The help visible when you type wscript /? (or more PROPERLY wscript //?) at the prompt shows 2 slashes for the switches available, although one will work in a simple case where the script itself is not supplied with any slashed parameters, as you have noticed.great salmon I am impressed In addition to the above I point out that you can modify various script engine options: you can set the default scripting engine to be either cscript or wscript you can set the default logo behaviour to be //nologo or //logo type either cscript //? or wscript //? at the prompt to see how. Quote from: 29april on December 04, 2009, 02:52:03 PM hi, I need to create a batch file that sends an email automatically when a windows service stops. Another way to approach this would be to monitor the service and send the email when the service status changes to STOPPED. Rather then manually run a batch file every 10 minutes or use the scheduler, this script will run in an infinite loop monitoring the service. Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("Select * From __InstanceModificationEvent " _ & " Within 1 where TargetInstance ISA 'Win32_Service'") Do While True Set objLatestProcess = colMonitoredProcesses.NextEvent If LCase(objLatestProcess.TargetInstance.NAME) = "" Then 'Name of service quoted; do not use display name If objLatestProcess.TargetInstance.State = "Stop pending" Then Call SendMail End if If objLatestProcess.TargetInstance.State = "Stopped" Then Call SendMail End if End if Loop Sub SendMail() Set cdo = CreateObject("CDO.Message") With cdo .Subject = "Service Down" 'email subject line quoted .From = "" 'your email address quoted .To = "" 'recipient email address quoted .TextBody = "" 'email body text quoted .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 'your ISP SMTP server address .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Configuration.Fields.Update .Send End With Set cdo = Nothing End Sub FILL in the information where noted, save script with a VBS extension and run from the command prompt as cscript scriptname.vbs Good luck. Sidewinder, once the script discovers the service is in the stopped state, will it keep sending emails every 10 minutes? sidewinder won't it require password for sending the mails I mean if i add in the field From="[email protected]" then will it send the email without the password here ?? Quote from: Salmon Trout on December 05, 2009, 08:47:22 AM Sidewinder, once the script discovers the service is in the stopped state, will it keep sending emails every 10 minutes? No. The script only sends an email when an event changes the service state to stopped or stop pending. Apparently, services and processes act differently in that processes terminate and flush out of memory while services are forever and may simply stop running. Quote from: Bukhari1986 on December 05, 2009, 09:09:36 AM sidewinder Depends on the ISP. I got it to work as posted, but if a username and password are required (security breach) there are CDO configuration items for just that purpose. The OP never even mentioned the service name and for all we know the email may be going through an internal network where username and password are not required. The link below is old material. It dates back to Windows 98. OLEXP: How to Send Outlook Express Mail from a Command Line I executed the below script but nothing happens. If the service is stopped I get a dialog box with the wscript.echo command, if it is started, nothing happens. emails are not being sent out either (I am able to send independently from command prompt). Is there a way I can spool on the entire script to a log file and find out what the issue is? do you guys see anything wrong with the below script? PLEASE let me know. Thanks for ur support. strComputer = "." Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service") For Each objService in colRunningServices If objService.DisplayName = "Licensing Service" And objService.State = "Stopped" Then WScript.Echo "Licensing Service is Stopped" Call SendMail End If Next Sub SendMail() Set cdo = CreateObject("CDO.Message") With cdo .Subject = "Service Down" 'email subject line quoted .From = "[email protected]" 'your email address quoted .To = "[email protected]" 'recipient email address quoted .TextBody = "Test" 'email body text quoted .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost" 'localhost .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Configuration.Fields.Update .Send End With Set cdo = Nothing End SubI couldn't see anything wrong, but I couldn't get it to run either, even with valid values. Question: why is the smtpserver set to localhost? Are you running your own mail server? or are you using an ISP? Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service") For Each objService in colRunningServices If objService.DisplayName = "Licensing Service" And objService.State = "Stopped" Then WScript.Echo "Licensing Service is Stopped" Call SendMail End If Next Sub SendMail() Set CDO = CreateObject("CDO.Message") With cdo .From = "[email protected]" .To = "[email protected]" .Subject = "Service Down" .Textbody = "Test" .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp mail server" .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 ' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "userid" ' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" ' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Configuration.Fields.Update .Send End With End Sub If using an ISP, check with them for the smtp server name and the port to use (this information is probably on their website). If you need to use authentication, uncomment the three configuration statements and fill in the values appropriately. Yeah, I know having the userid and password in the script is a security breach, but that is whole other subject. Good luck. or maybe there's something wrong with the schema site from M$. |
|
| 2194. |
Solve : Overwriting Folders? |
|
Answer» Hi there "I have a code in my batch file which renames a folder if it exists." It would be difficult to rename a folder when it does not exist. ( the worse problem is an error message. ) ( fix the rename folder and then worry about the no folder error message. ) The one line of code above to rename a folder does not provide enough information for us to work with. Where is the folder? What is the CURRENT name of the folder? Are the folders overwritten automatically? Must you save the information in the current folder? Would a backup utility work? Or plain copy or xcopy? It might be easier to work with the files inside the folder? Please provide all the code for the "rename the folder process"If you WANT to rename the folder on the second run (MGT exists) do you want to retain the existing MGT-1 folder? One standard way that is often used to avoid name clashes is to USE the epoch number - the number of seconds since 00:00:00 Jan 1st 1970 ZULU, ignoring leap seconds, example: 1261089513 (2009-12-17 22:38:33Z) This is also called "Unix Time" The STREAMING videos on the RTVE (Spanish TV) video on demand website use this as a filename but modify this by adding milliseconds to the end. Example: 1258808030808.flv However YYYYMMDDhhmmss or some variant should work OK. alternative: if you can download GNU win32 tools (coreutils) (see my sig), you can create timestamp with epoch using date command Code: [Select]C:\test>gnu_date +%Y%m%d%H%M%s%N 2009121816011261123265179033100 then you can rename your files uniquely. see gnu_date --help for more info.You can do datestamp & epoch stuff in Visual Basic Script too. And get at it in a batch Code: [Select] echo off echo wscript.echo DateDiff("s", "01/01/1970 00:00:00", Now())>Now2Epoch.vbs echo wscript.echo DateAdd("s", wscript.arguments(0), "01/01/1970 00:00:00")>Epoch2Date.vbs for /f "delims=" %%E in ('cscript //nologo Now2Epoch.vbs') do set NowEpoch=%%E echo Epoch number now : %NowEpoch% REM and back the other way... for /f "delims=" %%D in ('cscript //nologo Epoch2date.vbs %NowEpoch%') do set EpochDateTime=%%D echo Date and time : %EpochDateTime% Date & time format returned by Epoch2Date will be in your local format settings. Code: [Select]Epoch number now : 1261126966 Date and time : 18/12/2009 09:02:46Now that Dias de verano has posted, the solution for Overwriting Folders is perfectly clear. We can tell how pleased the OP is by the feedback from the original poster. All new readers can quickly overwrite their old folders. p.s. Why would anyone not understand: "for /f "delims=" %%D in ('cscript //nologo Epoch2date.vbs %NowEpoch%') do set EpochDateTime=%%D echo Date and time : %EpochDateTime%" Quote from: billrich on December 18, 2009, 07:17:26 AM Why would anyone not understand: Indeed. Why not? It is actually fairly obvious. |
|
| 2195. |
Solve : symbols? |
|
Answer» i wanna use ms-dos symbols like symbols to make a list i found a site for it if i try echo 210 it is 210 and not a piece of a list english is hard for me i'm japaneseI'm sorry for what Salmon said, we usually deal with people who speak English normally and are just too lazy to do it properly. I think you may be using Unicode, but the numbers won't do what you want in a batch file. Try this: copy and PASTE (or insert) the desired symbols in Microsoft Word. When you select save as, choose to save it as a plain text format. Select the MS-DOS option when prompted and select ok. Open the file in Notepad and copy and paste the desired symbols into your batch file. he wants to know how to display the ASCII CHARACTER for a given character code; as far as I'm aware there is no way of doing this easily via batch.sorry i don't understandHere in the Western WORLD we do not use Unicode. The symbols we can make from the keyboard are from 128 to 255. Some examples: 128 = Ç 129 = ü 130 = é 144 = É 150 = û 165 = Ñ 170 = ¬ 175 =» 221 =▌ 222 = ▐ 245 = ⌡ 245 = ÷ These were made with the alt key and the number pad. Quote from: Geek-9pm on December 12, 2009, 10:56:06 AM Here in the Western World we do not use Unicode. Actually, all versions of windows NT (NT,XP,2000,Vista,7) are based on unicode. Windows has never used ASCII either; it's always (except maybe in versions before 3.0) been the ANSI character SET. the symbols aren't QUITE the same. the command prompt however emulates the ASCII characters. Control+B gives friendly little smiley face. Quote from: BC_Programmer on December 12, 2009, 11:41:19 AM Actually, all versions of windows NT (NT,XP,2000,Vista,7) are based on unicode. Windows has never used ASCII either; it's always (except maybe in versions before 3.0) been the ANSI character set. the symbols aren't quite the same. thanks this where i'm searching for little question if i press ctrl+a or c is that a dos symbol too?ok thanks by the way this is the program i use it is very hard on me, to understandhttp://www.petesqbsite.com/selections/express/issue21/freepascal.png Quote from: pds on December 13, 2009, 04:31:01 AM ok thanks by the way this is the program i use it is very hard on me, to understandhttp://www.petesqbsite.com/selections/express/issue21/freepascal.png hey pds you're japanese too and your link is't active :/ |
|
| 2196. |
Solve : Need to load an old PC with MS-DOS with no cd drive.? |
|
Answer» I am trying to load an old!!!! LAPTOP that has no cd rom drive with just ms-dos. I have found several versions but they are all images for loading with a cd-rom. I can not figure out how to get it to install with just the floppies. I think I have all of the components but know how to put them on floppies to make it boot and install from just the floppies. Can anyone HELP? This is needed for an old program for a fire department to run an old radio system. Don't ask |
|
| 2197. |
Solve : How to zip files in Batch...? |
|
Answer» Here is the script.... http://www.winzip.com/index.htm Dear Billrich, I know the procedure how to zip manually. I clearly MENTIONED that I need the JPEgs to be zipped through Batch File automatically. Please help me with what code should I use in batch file?? Quote from: ghostdog74 on December 17, 2009, 07:54:16 PM Also, i have told you to download and use zip in that post, so if you are not that lazy, do that. Dear Ghostdog74, I am not lazy, I am posting this thread continously because, I don't no the procedure how to add in my batch file. That's why I mentioned the code in my thread, to teach me where and what code should to be use in batch script. I would really appreciate, if you add the zip command in my batch script and EXPLAIN me how it will work, so that I can learn something from you. Thanks. Quote from: akki15623 on December 17, 2009, 10:21:22 PM I am not lazy,then tell us which zip utility have you decided to use and whether you have tried anything after reading their docs. Quote from: ghostdog74 on December 17, 2009, 11:34:33 PM then tell us which zip utility have you decided to use and whether you have tried anything after reading their docs. I have winzip, I installed that many months ago, I am trying to learn batch scripting since 2 days, I don't no how to use the command Quote from: ghostdog74 on December 17, 2009, 11:34:33 PM whether you have tried anything after reading their docs. I din't look at the docs, as I don't no what batch script is, so I din't took so care at it. I am now interested in batch script and need help in understanding. Can you please explain me the zip command and tell me how to use that, when I need something to zip through batch script. Quote from: akki15623 on December 17, 2009, 07:42:51 PM
Download the Command-Line version of 7-Zip (http://www.7-zip.org/download.html) Use the following command: 7za.exe -a -tzip bigfile.zip D:\copiedjpegs\*.jp*g Explanation: 7za.exe = executable -a = command to add files -tzip =use the zip format bigfile.zip = to this file (can exist, or it creates a new file D:\copiedjpegs\*.jp*g = files to be zipped and you don't need to copy them to the desktop first... |
|
| 2198. |
Solve : Do you know how DOS read a file?? |
|
Answer» Can you EXPLAIN how DOS read a file? Still don't know what you mean. You want to know how an operating system works? That's what I think. How the '.bat' extension is reading your text, idk tbh. BRIf I'm guessing right. He's wondering how a batch file is read. WELL, a batch file interpreter (there are different ones in different systems) reads the commands. Then it executes those commands that it reads. If it finds an ERROR in those commands in THROWS out a message. |
|
| 2199. |
Solve : Batch 'For' Problem? |
|
Answer» Hi everyone, I was under the assumption I had to state what I want taken / read from the .txt file. Wrong? Depends. If you want the whole line, use "tokens=" Tried it, doesn't make a difference. Have you tried leaving echo on and watching to see how the variables expand? here's the output: dir /ad /b d:\*.* 1>d:\temp\test.txt set drvpath=C:\Windows\inf setlocal ENABLEDELAYEDEXPANSION for /F "tokens=" %x in (d:\temp\test.txt) do (set drvpath=!drvpath!;c:\windows\s upport\drivers\%x ) endlocal del d:\temp\test.txt set drvpath drvpath=C:\Windows\inf As you can see they don't expand at all I'm not bound to that way either. If one of you can point me in the right direction I'm just trying to accomplish this: list of folders > registry key in the form of folder1;folder2;folder3 and so on.1. Move Setlocal Enabledelayedexpansion to before you set drvpath. 2. Remove Endlocal. 3. The "tokens=1" ensures that if a line in the text file has spaces, you will only capture up to the FIRST space. THANKS A LOT FOR YOUR HELP!!! This is how it works in the end: setlocal ENABLEDELAYEDEXPANSION dir /ad /b d:\vms > d:\temp\test.txt set drvpath=%systemroot%\inf for /f "tokens=*" %%x in ( d:\temp\test.txt ) do ( set drvpath=!drvpath!;c:\windows\support\drivers\%%x ) set drvpath Quote set drvpath this is more usual Code: [Select]echo %drvpath% But that's just a stylistic thing. Glad it works. By the way, you do know that you can avoid using a temp file? Use for /f and enclose a command in single quotes, and the command output will be PARSED, line by line, as if it was in a file. And put the loop on one line? Code: [Select]setlocal enabledelayedexpansion set drvpath=%systemroot%\inf for /f "tokens=*" %%x in ('dir /ad /b d:\vms') do set drvpath=!drvpath!;c:\windows\support\drivers\%%x echo drvpath=%drvpath% |
|
| 2200. |
Solve : Not Deleting BatchFile? |
|
Answer» How do I get the del command to work! . |
|