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.
| 8601. |
Solve : Manipulating file/folder location in BAT files? |
|
Answer» All, This location is stored in the %1 value as (example) X:\folder1\folder2\longfoldername3\file.ext. I want to separate the folder location of the file and the filename itself. How can I grab X:\folder1\folder2\longfoldername3 as one variable and file.ext as another variable? See FOR /? If %1 is a filename, whether just the filename e.g. afile.ext or a path and filename eg d:\folder\subfolder\afile.ext then... %~1 - expands %1 removing any surrounding quotes (") %~f1 - expands %1 to a fully qualified path name %~d1 - expands %1 to a drive letter only %~p1 - expands %1 to a path only %~n1 - expands %1 to a file name only %~x1 - expands %1 to a file extension only %~s1 - expanded path contains short names only %~a1 - expands %1 to file attributes of file %~t1 - expands %1 to date/time of file %~z1 - expands %1 to size of file These can be combined... N.B. The file need not exist, an imaginary filename is still processed just the same, although items impossible to resolve, such as size, date/time, etc expand to blanks. This is a folder... Quote S:\Backup\Test\stringlen>dir This is filestuff.bat Quote @echo off This is the output of the command:- filestuff "sfor.cmd" ... Quote parameter passed %1 is "sfor.cmd" Holy crap thank you... |
|
| 8602. |
Solve : Hard drive Identifying in DOS 6.2? |
|
Answer» Here is the problem. |
|
| 8603. |
Solve : sinister things? |
|
Answer» i have noticed that many PEOPLE that goes on this forum and comes to this SECTION ALWAYS has some sinister thoughts like hacking a game or hacking into the school system so im suggesting that whoever post asking for help about hacks should be Yeah, not fair. Sometimes they don't know what they are really talking about until someone tells them.Why not re-size that sig so the goofy scrollbar isn't there ? ?OK there is one in place i cant find the post on it right now but if i find it or maybe GX or fed know where it is they might post the link unlovedwarrior |
|
| 8604. |
Solve : s3 upload batch script? |
|
Answer» Hi, |
|
| 8605. |
Solve : Batch File to get MAC Addresses? |
|
Answer» Hey guys can anyone help me create a batch file that will get the mac address off multiple machines and save it to a network file? you can use getmac. see getmac /? for more info. Also: I think that tool would be available via a resource kit for W2K and earlier (it's included in XP Pro and up). (just checked, it's in the NT4 resource kit and no doubt is in the w2k one). I doubt they are running an OS before XP on any of the machines anyways, though. The batch method will work with NT4 and 2000 (not as sure about NT4). getmac would be the better solution regardless- it's designed for the very purpose required. O yea should of mentioned its for XP and Win7 Quote from: BC_Programmer on January 04, 2011, 10:07:19 PM I may be wrong, but i see no options of ipconfig that can query a set of remote addresses. if OP has 60 desktops to process, then ipconfig may not work as well as getmac. Here is what I ended up with and will work just fine for what were doing. Code: [Select]echo ------------------------------------------------ >>\\server\Common\Public\getmac\MV-mac.txt echo ------------------------------------------------ >>\\server\Common\Public\getmac\MV-mac.txt echo %date% >>\\server\Common\Public\getmac\MV-mac.txt echo %COMPUTERNAME% >>\\server\Common\Public\getmac\MV-mac.txt echo %username%>>\\server\Common\Public\getmac\MV-mac.txt ipconfig /all|find "Physical Address" >>\\server\Common\Public\getmac\MV-mac.txt for /f "tokens=2 delims=:" %%i in (\\server\Common\Public\getmac\MV-mac.txt) do @echo The MAC Address is %%i Quote from: Fiala06 on January 04, 2011, 10:33:03 PM Here is what I ended up with and will work just fine for what were doing. so you have to run it on EVERY machine ? if you have a list of ip address or computer names of those 60 machines, you can use getmac with /S to query them all without having to go to every machine and run it.Quote from: ghostdog74 on January 04, 2011, 10:28:51 PM I may be wrong, but i see no options of ipconfig that can query a set of remote addresses. if OP has 60 desktops to process, then ipconfig may not work as well as getmac.Quote I have a lab of 60 desktops and would like to run a batch file on each machineNot remote. Of course a option that means they don't have to run it on each machine would be easier. Especially since it is part of the OS's in use. (and you really only need one machine that has getmac to get the various addresses)Quote from: ghostdog74 on January 04, 2011, 10:48:30 PM so you have to run it on EVERY machine ? if you have a list of ip address or computer names of those 60 machines, you can use getmac with /S to query them all without having to go to every machine and run it. Well either way I have to touch them all. These are all new computers with an image I use. There all setup with DHCP so I'll have no idea what the IP's are. We need the mac address's so we can reserve address's on our servers for each INDIVIDUAL machine. Retracted suggestion after re-reading last post. |
|
| 8606. |
Solve : Bat file ICALS enable inheritance? |
|
Answer» Hi |
|
| 8607. |
Solve : Getkey.com Oddity? |
|
Answer» I'm not quite sure why this is (it hasn't happened on my other computer before) but when I use getkey.com in my code, I get a "File not found" error. It appears that the error actually comes from getkey. I don't have getkey.you should look carefully at the batch script again.oh, YES. It does work fine. Now I have getkey.com and now that I have it, what will I do with it?why do you want to run code that you don't understand? That is some obscure batch/DOS HACK (to hide password entry) that i, for one, would not want to maintain. Also, don't ever use batch to prompt for password. Its useless. Whoever can open the batch file can bypass this.I suggest you use START / RUN / CMD.EXE Then make its home directory wherever your script is. 1. Use DIR and confirm that getkey.com exists there as expected. a) Perhaps for some reason when you ran the script the output went to a different folder / partition / drive. b) Perhaps you have some security protection which quarantines or blocks any executable created by a batch script. 2. Assuming that getkey exists, how big is it. I find that by default it is exactly 137 bytes on my system - THE NON-DEFAULT ALTERNATIVE IS 274 BYTES. By default my CMD.EXE starts life in ANSI output mode, but when I put on the command line CMD /U I get Code: [Select]C:\Documents and Settings\Dad>CMD /U Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Dad>and now when this runs the script (which is still ANSI) the redirected output is in UNICODE which is twice as long. To see the options for launching CMD.EXE invoke CMD /? It says a lot about "extensions", and also about registry keys that control it. Perhaps there is something special about your system that caused your script to be executed in Unicode mode. N.B. It is possible your that when your script is executed, the system defaults may cause UNICODE/ANSI output when you execute by a double click in Windows Explorer, and the converse ANSI/UNICODE when you invoke the script from the command line of CMD.EXE launched from START / RUN. No way will I try to run a unicode variant of getkey.com - it may give the error you have seen, or it may do unlimited damage. A few decades AGO I had a DOS 3.ish machine with high powered tools EDLIN and DEBUG. I was comfortable at that time to use EDLIN and DEBUG to create and adjust things like getkey.com. I had a 1 inch thick stack of fanfolded printer listing with all the entry points into the DOS OPERATING System, and also all the special places in the BIOS. I remember there were magic numbers that could be used with DEBUG to launch the BIOS into a format of the Hard Drive to alter the size of the sectors and the number of sectors per track - BUT I ALWAYS CHICKENED OUT. I am astonished that the "magic numbers" that are redirected into the getkey.com file still do in Windows XP and CMD.EXE what they used to do in DOS command.com. Do all the ancient EDLIN scripts for hundreds of old COM things still work as well for XP, how about Vista and Windows 7, and what about Windows 8 ? Alan Quote from: ghostdog74 on January 08, 2011, 01:30:02 AM why do you want to run code that you don't understand? That is some obscure batch/DOS hack (to hide password entry) that i, for one, would not want to maintain. Also, don't ever use batch to prompt for password. Its useless. Whoever can open the batch file can bypass this.I used it before (on my desktop) so that the user could press a button and the script would respond depending on which button was pressed. It would work as a password type script, but not well. @ALAN Yes, it does exist. I check on my desktop and with DIR. It is also 137 bytes and 4,096 bytes on disk. I'm just going to restate something - It's GETKEY.COM that gives the File not found error, not the script.These are your mistakes :- You NEVER told us what the error message was, You never said that Getkey ISSUED the error. I had assumed the error message was from the O.S. trying to locate GetKey and failing. Perhaps you should post the exact message. e.g. I have no GetKey and CMD.EXE shows me Code: [Select]D:\_T\D3\Reg\V2>getkey 'getkey' is not recognized as an internal or external command, operable program or batch file. Is that the error message you get ? Are you using CMD.EXE or COMMAND.COM ? The other possibility is that getkey.com is using magic hex values to work its voodoo, and it assumes that various subroutines will be accessible at certain special places. Perhaps (as I always feared) these subroutines may be missing or in slightly different locations, possibly as a special tweak by the Laptop maker to make way for battery power management ? Regards Alan Helpmeh: can you copy a version of the getkey program as created on the machine where it works to the one where it doesn't or perform a file compare between them? Quote from: ALAN_BR on January 08, 2011, 11:37:00 AM You never said that Getkey ISSUED the error. He said it in the first post "It appears that the error actually comes from getkey." The actual, verbatim message would certainly have been nice. Especially since saying "file not found" came from getkey is sort of vague. Here is the dissasembly of the resulting executable(getkey.com), anyway: Code: [Select] code SEGMENT ASSUME CS:code, DS:code ORG 100h strt: PUSH 3144h POP AX SUB AX,3073h PUSH AX POP DI IMUL [DI+48h],DL PUSH AX XOR [DI+78h],DL INC DI PUSH DI POP AX XOR AL,61h JS J00148 JNS J0014A IMUL [DI+69h],AH INSW OUTSB DB (66h) DB (65h) IMUL [BP+6Bh],CH INSB DB (64h) DB (64h) INSW DB (65h) INSW IMUL [BP+SI+61h],CH OUTSB INSW OUTSB DB (64h) OUTSB POPA DB (64h) INSW OUTSB DB (64h) OUTSB JO J0019B BOUND [BP+0Dh],CH OR CH,[BX+SI+68h] JO J001A3 BOUND [BP+70h],CH INSB PUSH 68h OUTSW J00148: JS J001B9 J0014A: INSB OUTSB PUSH 6961h DB (67h) IMUL [SI+70h],AH INSB INSB OUTSB BOUND [BP+DI+64h],CH OUTSB PUSH 6B6Ch DB (66h) PUSH 666Ch INSB DB (65h) DB (66h) BOUND [SI+66h],CH DB (66h) POPA PUSH 5566h DB (65h) BOUND [SI+66h],AH POPA PUSH 6668h IMUL [BX+6Bh],CH PUSH 0A0Dh INSB DAS PUSH CX OUTSB DEC BX INC BP INC AX DEC AX INC DX XOR SS:[BX+SI+2Eh],CX OR AX,000Ah code ENDS END strt Aside from the fact that this dissassembly is probably different from the actual source assembly (particularly the lack of comments which is not surprising) It pretty difficult to read. As ghostdog said, it's pretty dumb to be accepting passwords in a batch, even if you use a tool like this. It's still in plain text after all, so anybody can get the password simply by viewing the file. Oftentimes a "defense" for this is that "well, they probably won't look in the file" That's a rather weak defense of it. Basically: the above is a mess of Assembly that only works on 16-bit operating systems or systems that can emulate 16-bit. I know this because 64-bit doesn't emulate 16-bit (except via a VM where it works fine) and it just shows a dialog saying "hey, retard, you can't run 16-bit programs on a 64-bit OS". "But" you say- "I just want to get it working on both machines". Well, then you better learn ASM or get somebody who knows ASM to figure out what the program is doing and how the heck it's causing a "File not found" error. (and perhaps explain that error a little better, is it simply "File not found" or does it give the error ALAN_BR describes? In the latter case it's not getkey.com issuing the error at all so you've been accidentally tossing out that red herring the whole time without realizing it. Quote No way will I try to run a unicode variant of getkey.com - it may give the error you have seen, or it may do unlimited damage.No MATTER how carefully crafted the ASM, the protected nature of the NTVDM (as well as the fact that it is in fact a virtualization environment) it cannot do any sort of damage. (that I can think of) in this case, the "damage" is limited to the corrupted getkey.com (which is virtually the same as the original with a null byte thrown in every while) just sorta throws the cursor AROUND randomly in the DOS window until you stop it. Which is actually pretty extraordinary, since most of the time when you run some semirandom bit of faff as code it just barfs out a illegal operation: Invalid Instruction pretty early on. It's probably because all it does is pad in a bunch of zeros which are somehow valid, or something. -With the NTVDM, "dangerous" instructions (like directly accessing the hard disk) will cause faults and the DOS executable will be forced closed. (not always the case for 9x, though, since it truly runs on a DOS subsystem, although 9x is still pretty heady when it comes to DOS programs messing about with FAT32 or VFAT drives and complains about Long file name preservations and whatnot. Quote A few decades ago I had a DOS 3.ish machine with high powered tools EDLIN and DEBUG.I wouldn't really call a cheap assembler "high power", especially compared to the various other assemblers available at the time. I'd be more inclined to say "useful" in the same way that a knife is useful to scoop ice cream when you have nothing else, whereas TASM and the other Assemblers where the Ice cream scoops. That being said, the "knife" version was free and while it's a bit annoying to use a knife to scoop ice cream it can be done. in fact on the whole it's weird(cool) that they included something like that(debug, I mean)- but it certainly was useful. Come to think of it though a lot of what people were doing with DEBUG could be just as easily done in BASICA, which was included with early versions as well. (OTOH, you can't run BASICA programs now because (for space reasons) it's default save format was binary. I couldn't remember if DEBUG let you use actual ASM or just the hexcodes- so I checked it let's you use ASM, which is useful, but only the most basic instructions... (which was enough for things like determining wether SHARE was running: Code: [Select]N ISSHARE.COM A 100 MOV AX,10000 INT 2F MOV AH 4C INT 21 R CX 9 W Q which you could save to a file and then save to debug. Code: [Select]DEBUG<ISSHARE.ASM and POOF! you have ISSHARE.COM. Anyway, best you could do was essentially the "Magic numbers" thing. Throw values into specific memory locations, call an interrupt, and then inspect the same random locations or possibly some other set of random locations. Thing is, it is extremely low level; even though the memory locations can be found by looking through it, these memory locations often have nothing to do with DOS itself and more to do with inspecting other programs (for example, wether SHARE is loaded). Interestingly enough, the "ISSHARE" ASM program broke fairly quickly, when MS integrated the DOS SHARE redirector right into windows for workgroups; the debug script result basically looks in specific locations that it knows that SHARE messes about with and should contain certain values, but SHARE.VXD didn't so it pretended it wasn't loaded. Quote I had a 1 inch thick stack of fanfolded printer listing with all the entry points into the DOS Operating System, and also all the special places in the BIOS.Probably would have been better to get the actual manuals, rather then printing out some stuff from BBS's -I mean no offense of course, but that is a rather small stack, (no doubt useful, but perhaps too concise) and (of course your memory may have faded with time, so they may well have gotten the following correct) "DOS entry points" are called "DOS interrupts" and "special places in the BIOS" could be any number of things (but generally also BIOS interrupts) Mostly the important bits were the Interrupts, and each interrupt usually used the various Registers to perform tasks. (I have no idea how debug puts stuff in the registers, or even if it could) Quote I remember there were magic numbers that could be used with DEBUG to launch the BIOS into a format of the Hard Drive to alter the size of the sectors and the number of sectors per track - BUT I ALWAYS CHICKENED OUT.Interrupt 13H. Not sure why you'd chicken out... of course it would be silly to expect a drive format to preserve the data, but the worst case scenario would probably be having to format again afterwards. (of course, if you thought that it would simply change the format without formatting the drive itself then it's a good thing you decided not too! Quote I am astonished that the "magic numbers" that are redirected into the getkey.com file still do in Windows XP and CMD.EXE what they used to do in DOS command.com.pretty much all the script does is move the cursor around and accept a bit of input. the NTVDM was practically designed specifically to let 16-bit programs like that work. Quote Do all the ancient EDLIN scripts for hundreds of old COM things still work as well for XP, how about Vista and Windows 7, and what about Windows 8 ?depends what they do. Any x64 (or IA-64) OS isn't going to run the COM files anyway; 32-bit versions will run them with limitations, some interrupts are entirely off-limits (such as I believe everything in 13H) in fact those were even limited to some degree by windows 9x) some others just cause the NTVDM to say the program performed an illegal operation and will be terminated. Windows 8 is purported (I doubt it though) to be 64-bit only and if that's the case it won't be able to run any 16-bit software at all. BC, the dissembler is if little value. We need the real source code to see what went wrong. Does anybody else here really want the original source code? Is it available? |
|
| 8608. |
Solve : Outputting the Number of Files Copied and the Total Number of Lines Copied? |
|
Answer» I am attempting to WRITE a batch file that copies the data in all files with the specified criteria into one file (the date is included in the filename for the example below). I would like to output to the Audit.csv file the number of files copied and the total number of lines in all of the files (not including the first line of each file). I am using Windows 7. This is what I have so far. This is what I have so far. And what were the results? I'm not aware of any switches for the copy command that will produce a line count. My best guess would be the bulldozer approach, manually copying each line of each file to the combined file and doing the counting along the way. It's not pretty but the logic is sound. Code: [Select]@echo off ::Get date variable from user :: set /p dte=Enter the file date to copy as mmddyy: :: Start with new files :: if exist c:\mcr\combined_%dte%.csv del c:\mcr\combined_%dte%.csv if exist c:\mcr\audit_%dte%.csv del c:\mcr\audit_%dte%.csv ::Output each line of the files to the combined file :: for /f "tokens=* delims=" %%i in ('dir /b c:\mcr\%dte%*.*') do ( for /f "tokens=* delims=" %%j in (c:\mcr\%dte%%%i) do ( echo %%j >> c:\mcr\Combined_%dte%.csv set /a tLines+=1 ) set /a tFiles+=1 ) ::Write the current date & time to audit file :: echo %date% %time% %tLines% %tFiles% >> c:\mcr\audit_%dte%.csv Quote ... and the total number of lines in all of the files (not including the first line of each file). I wasn't sure why this was needed so I'll let you subtract the tFiles variable from the tLines variable just prior to to outputting the audit record. If you have long file names with embedded spaces or special characters you may need to use quotes in the for statements. Good luck. Count the number of lines in a file; doesn't skip blank lines, or lines starting with a semicolon like FOR does Code: [Select]For /f "tokens=1* delims=:" %%A in ( ' findstr /N /R ".*" "filename.ext" ' ) do set lines=%%A %lines% contains the number of lines in the file Code: [Select]@echo off setlocal enabledelayedexpansion if exist test.txt del test.txt for /l %%N in (1,1,10) do echo Line %%N blablabla>>test.txt echo.>>test.txt echo ; line starting with a semicolon>>test.txt for /l %%N in (13,1,20) do echo Line %%N blablabla>>test.txt echo test.txt begin echo -------------- type test.txt echo -------------- echo test.txt end echo. for /f "tokens=1* delims=:" %%A in ('findstr /N /R ".*" "test.txt"') do set lines=%%A echo findstr counted %lines% lines set flines=0 for /f "delims=" %%L in (test.txt) do ( set /a flines=!flines!+1 ) echo FOR /F counted %flines% lines echo. Code: [Select]test.txt begin -------------- Line 1 blablabla Line 2 blablabla Line 3 blablabla Line 4 blablabla Line 5 blablabla Line 6 blablabla Line 7 blablabla Line 8 blablabla Line 9 blablabla Line 10 blablabla ; line starting with a semicolon Line 13 blablabla Line 14 blablabla Line 15 blablabla Line 16 blablabla Line 17 blablabla Line 18 blablabla Line 19 blablabla Line 20 blablabla -------------- test.txt end findstr counted 20 lines FOR /F counted 18 lines Sidewinder - I tried your code and entered 102510 at the prompt. Filenames are 102510_ABC and 102510_DEF. I'm getting "The system cannot find the file c:\mcr\102510102510_ABC" and "The system cannot find the file c:\mcr\102510102510_DEF" Any ideas as to why this is happening?Sometimes you just have to look at things from a different angle, so I turned my monitor upside down. Actually I went back to your basic structure, shamelessly stole borrowed the counting lines code from Mr. Trout, did a little tweaking and came up with a result not nearly as ugly as the first. Code: [Select]@echo off setlocal set indir=c:\mcr set outdir=c:\mcr :: Get date variable from user :: set /p dte=Enter the file date to copy as mmddyy: :: Delete any PREVIOUS files :: if exist "%outdir%\combined_%dte%.csv" del "%outdir%\combined_%dte%.csv" if exist "%outdir%\audit_%dte%.csv" del "%outdir%\audit_%dte%.csv" :: Copy the files to combined file :: for /f "tokens=* delims=" %%i in ('dir /b "%indir%\%dte%*.*"') do ( type "%indir%\%%i" >> "%outdir%\combined_%dte%.csv" set /a tFiles+=1 ) :: Count the lines :: for /f "tokens=1* delims=:" %%i in ('findstr /N /R ".*" "%outdir%\combined_%dte%.csv"') do set tLines=%%i :: Write the current date & time & totals to audit file :: echo %date%,%time%,%tFiles%,%tLines% >> "%outdir%\audit_%dte%.csv" Some of the code is left over from testing but should not create any problems. Good luck. Sidewinder - Thank you so much. It works perfectly. And thanks to you also Salmon Trout.Sidewinder, well done, but don't forget that starting a COMMENT with the unofficial, undocumented, unsupported, DEPRECATED double colon breaks code if used inside parentheses... |
|
| 8609. |
Solve : Dir question? |
|
Answer» In DOS I have WP5.1 and have a document INSIDE that directory but that file shows up in the root directory when I pull up dir at the prompt. Why does it do that ? That file should be in the WP directory. What is WRONG ??Quote from: DAL818 on JANUARY 12, 2011, 03:30:30 PM In DOS I have WP5.1 and have a document inside that directory but that file shows up in the root directory when I pull up dir at the prompt. Why does it do that ? That file should be in the WP directory. What is wrong ? Two copies of WP in two locations will most likely not hurt. Which copy LOADS? If all works well, leave alone. Ask WP support. Quote from: DAL818 on January 12, 2011, 03:30:30 PM In DOS I have WP5.1 and have a document inside that directory but that file shows up in the root directory when I pull up dir at the prompt. Why does it do that ? That file should be in the WP directory. What is wrong ?? Either you have two copies of the file, or you are running dir (without PARAMETERS) from within the WP5.1 directory. |
|
| 8610. |
Solve : Lost boot up password? |
|
Answer» Hi, I bought a Dell Inspiron 910 Mini from a family that the kids had put in the password and forgot what it was, great deal, I thought I could figure it out to no avail, Dell will not HELP me because IAM not the original owner and the family I bought it from wont or cant help either, is there anything I can do? ,Thank YouIs this BIOS password or Windows Password? Hi Thanks, It is the start up password as soon as It turns on, I had to fix the ram and thought my troubles were over, but surprise. Essentially, you have bought a brick. No proof of legal ownership, no BIOS password reset. I am sure you are telling the TRUTH, of course, but I wish I had a dollar for every time I heard the "kids reset the password" story. |
|
| 8611. |
Solve : using " as delim? |
|
Answer» I want to make simple converter and what i need to do: One more thing if coming to replacing characters, would there be way to replace whole string of characters into single char (for using few types of delimiters)? The syntax for string replacement is: Inside a loop where you are using delayed expansion (and hence using exclamation marks for variables) Code: [Select]set string=!string:A=B! Or elsewhere using percent signs Code: [Select]set string=%string:A=B% A is any sequence of one or more characters that you wish to search for in %string% and B is zero or more characters that you wish to put in A's place. Thus if %string1% is: I like cats set string2=%string1:cat=dog% would result in %string2% now containing I like dogs Notice that I used a NEW string (string2) in the SET statement. If you use the same variable name (e.g. set string=%string:hot=cold%) the string in the variable is modified but if you use a new variable (e.g. set newstring=%oldstring:man=woman%) then a new string is formed reflecting the change and the old string is preserved. If the replacement consists of a zero length string (i.e. nothing) then the search term is deleted so that if you did this Code: [Select]set string1=Mary had a little lamb set string2=%string1:little =% then you are searching string1 for little followed by one space and replacing it with nothing (there is nothing between the equals sign and the right-hand variable DELIMITER) and string 2 is therefore: Mary had a lamb Quote from: me, above A is any sequence of one or more characters that you wish to search for in %string% and B is zero or more characters that you wish to put in A's place. Note that if either sequence contains one or more of certain special control characters e.g. < > & % ! (there are more) then you have to take certain PRECAUTIONS to avoid the script barfing (crashing) at that point. |
|
| 8612. |
Solve : Batch File to Get fully qualified domain name? |
|
Answer» Does any one Know how to WRITE a batch FILE to get fully qualified domain NAME. Not the Hostname. I figured it out.... ;D Please POST the code.Domain name?I wouldn't mind getting my hands on this code too.. could ya post it?Quote from: NetRock on January 12, 2011, 04:20:23 PM I figured it out.... ;D Please post the code?testMaybe you should "test" your way out of here, Bill? |
|
| 8613. |
Solve : Run a batch file before Windows User logon? |
|
Answer» I run a program called PerfectDisk. essentially it is an alternative to Windows XP "Defrag". One option is to defragment metafile data on restart. My guess is that it performs this prior to loading windows services or as a service, but before the any User logon. I say this because my attempt to run a batch file from another batch file when placed in the Startup folder is too late in the boot process. Normally I try not to have posters download anything, but in this case it's safer than hacking the registry and turning your PC into a brick. Been hackin' the registtry for years, so if it is necessary then we can go there. But for now I will take your lead and read....the information on the links provided.Well, According to the startup sequencing RunServicesOnce - This key is designed to start services when a computer boots up. These entries can also continue running even after you LOG on, but must be completed before the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce registry can start loading its programs. This seems to be where I need to run the bat file or executable. But since there are currently no entries I can not figure out safetly how to create one. Sdelete may require services or functionality that has not been started when the RunServicesOnce key kicks in. If you use regedit, find the key in the left panel, highlight it to see all existing values, right click the right panel, add a new STRING value, pick a name for your key, and in the data field enter the fully qualified path to your program. If you use reg from the command LINE type reg add /? for details. Note: the regkey data type should be REG_SZ. Quote My final hope is to run a batch file(SDOS.BAT) that calls out an executable file(Sdelete.exe) You may have to run Sdelete.exe directly without the batch wrapper. The cmd processor (required for batch files) may be unable to start this early in the boot cycle. Quote SDelete needs access to certain files before they are locked by Windows. Just asking, but if Windows protects files it needs to operate, why are you deleting them? CYA: Backup your Registry before proceeding. Quote from: Sidewinder on January 08, 2008, 05:26:18 AM Just asking, but if Windows protects files it needs to operate, why are you deleting them? Many files, such as internet explorer history, the temp directory, temporary internet files should be able to clear completely, but files such as the index.dat is hard to securely delete as it is locked by the time you logon. This is just an example of some files that I would like to clean up.I apologize for restarting a 2 year old topic, but I had just a quick question regarding the software earlier posted. Quote The Startup Control Panel will give you some limited access to the registry startup functions. If I were to download that and place a batch file in the RunServicesOnce or RunServices (the batch file being a custom login file) would is disrupt the startup process of the computer and harm it?Quote from: Rilez on January 13, 2011, 08:21:56 PM If I were to download that and place a batch file in the RunServicesOnce or RunServices (the batch file being a custom Don't know your OS but is there any reason that this login script cannot be attached to Group Policy? Otherwise this link may provide some additional information using some tools from the 2003 Resource Kit. Good luck. My OS is Windo.ws 7 that link does help, but the question remains, if I were to put a simple batch file there to run before windows logon screen would it harm my computer. (Also, its an Acer 5532 if its important)Don't honestly know if it would harm your computer. Call me crazy, but I thought login scripts were run after a user logged-in and it could be determined what script (if any) would run for this user. It might help everyone if you posted the batch file. This is the Login file. I copied from a script someone released on YouTube. (I did not create the file) It just has simple login capabilities along with remote options (like I stated earlier). [recovering disk space - old attachment DELETED by admin]The batch code you posted appears to be safe. There are a couple of del commands you may want to check out but nothing particularly malicious. I suspect the code would run perfectly on the author's machine, but not anybody elses. There are also references to other batch files and executables that you may or may not have on your system. Most login scripts I have ever seen or written are used to setup a user environment (map network drives, attach printers, empty temp directories etc.) Generally they are "once and out" in that they run from top to bottom without any user intervention. There is no reason to even try to run this script before Windows User logon. Better to put this in the startup folder; even better start over and customize it for your machine/network. You can try using this link as a template. Good luck. [opinion] The batch code posted should be the poster child of what not to do when writing batch code. There are no indents, no whitespace, no comments, constructs which are difficult to follow and a menu 60 lines long. It was a mind numbing experience. [/opinion] Quote from: Sidewinder on January 15, 2011, 08:08:27 AM The batch code posted should be the poster child of what not to do when writing batch code.[/opinion] That code is about as bad as I have ever seen. Utterly without merit. It contains classics like this Code: [Select]set /p newname="Enter new username:" if "%newname%"=="%newname%" goto inputname :inputname and this Code: [Select]goto next :next It is what many people do when they first discover batch scripting. They write an 882 line batch script with menus to run Notepad. |
|
| 8614. |
Solve : Script for launch program and close a window? |
|
Answer» Script for launch a program and close a window |
|
| 8615. |
Solve : hiding a partition? |
|
Answer» I'm playing around with an old PC & am trying to set it up as dual boot W95b (OSR 2.1) & W98SE. I've got W95 installed to C: but need to hide C: so I can install W98 to D: |
|
| 8616. |
Solve : Please Help! Batch File to find and replace config values urgently required? |
|
Answer» Quote from: hitman126 on January 20, 2011, 03:58:44 AM There is however ONE minor problem I've noticed. The OPENING and closing ApplicationSettings tags have three sets You didn't show the opening and closing ApplicationSettings tags before. Script below contains code to ignore these. Hey ! Are you sure about the SPACES in the urls? example... Quote "WEBSERVER 1" They don't look right to me. Code: [Select]@echo off setlocal enabledelayedexpansion set inputfile=MyConfigUpdate.txt set outputfile=MyConfigUpdate-changed.txt if exist "%outputfile%" del "%outputfile%" for /f "delims=" %%A in (%inputfile%) do ( set "string=%%A" set string=!string:"=$! set change=1 echo "!string!" | find "applicationSettings">nul && set change=0 for /f "tokens=1-6 delims=$" %%B in ("!string!") do ( set token1=%%B set token2=%%C set token3=%%D set token4=%%E set token5=%%F set token6=%%G REM <arg key="MyApp1Root" value="http://localhost:9005/config"/> REM I would like to replace the word localhost with "WebServer 1", echo !token2! | find "MyApp1Root">nul && set token4=!token4:localhost=WebServer 1! REM <arg key="MyApp2Root" value="http://localhost:9012/config"/> REM I would like to replace the word localhost with "AppsServer 2" echo !token2! | find "MyApp2Root">nul && set token4=!token4:localhost=AppsServer 2! REM <arg key="WWWRoot" value="http://DBServer:9012/config"/> REM I would like to replace DBServer with "DatabaseServer 3" echo !token2! | find "WWWRoot">nul && set token4=!token4:DBServer=DatabaseServer 3! if !change! equ 1 ( echo !token1!"!token2!"!token3!"!token4!"!token5!>>%outputfile% ) else ( echo !token1!!token2!!token3!!token4!!token5!>>%outputfile%" ) ) ) REM show results echo %inputfile% type "%inputfile%" echo %outputfile% type "%outputfile%" Code: [Select]MyConfigUpdate.txt <applicationSettings> <add key="MyApp1Root" value="https://localhost:9001" /> <add key="MyApp2Root" value="http://localhost:9012" /> <add key="WWWRoot" value="http://DBServer.myCompany.com" /> <add key="app.MyTelesalesRootUrl" value="http://localhost:9501" /> <add key="app.MaximumCustomerSearchResults" value="100" /> </applicationSettings> MyConfigUpdate-changed.txt <applicationSettings> <add key="MyApp1Root" value="https://WebServer 1:9001" /> <add key="MyApp2Root" value="http://AppsServer 2:9012" /> <add key="WWWRoot" value="http://DatabaseServer 3.myCompany.com" /> <add key="app.MyTelesalesRootUrl" value="http://localhost:9501" /> <add key="app.MaximumCustomerSearchResults" value="100" /> </applicationSettings> |
|
| 8617. |
Solve : Using path variable in FOR /R... loop? |
|
Answer» is there any quotes or bracket tricks to do this? |
|
| 8618. |
Solve : Perform Action Based on Hour Age of File? |
|
Answer» I need a DOS Script that will look at a directory for the latest file with extension XXX. It will determine how many hours old the file is. And then I will echo back a response if the the file is XX hours old. Thanks in advance. JoshWhat have you done so far? |
|
| 8619. |
Solve : batch file, unzip and then rename?? |
|
Answer» Hello All, |
|
| 8620. |
Solve : Bath file auto answer problem? |
|
Answer» Hi, all! |
|
| 8621. |
Solve : copy files current user on other pc? |
|
Answer» I am trying to make a batchfile which copy's the my documents etc. from the currently logged in user on a other pc to a server. Whatever i try the output is de current user logged in where i type this batchfile so: you can try running "qwinsta" using psexec. I never heard of qwinsta but indeed you are right. When i run qwinsta the users logged in is displayed in the cmd prompt. But how di i make use of the username displayed? The batchfile must be run AUTOMATICALLY without need to SWITCH to the username. How can i do this in a batchfile? |
|
| 8622. |
Solve : How to make .cmd create a shortcut and write data to it? |
|
Answer» Im trying to make a batch or cmd make the missing or corrupt file if it does work Example: |
|
| 8623. |
Solve : External command? |
|
Answer» How to use external command?type command and press enterI SAID NOTHING... I said nothing...You could try adding more RAM. |
|
| 8624. |
Solve : Need Help with Command line on making folder hidden in a bat file? |
|
Answer» Im trying to make a password protected folder it went fine until i tryied to rehide the folder in the .cmd heres what i got The hide shortcut dosent seem to work any ideas? Did it ever work? Code: [Select]@echo off Echo.Please Enter Pass to continue.... :action set /p pass=Password: set userinp=%pass:~0,100% if /i "%pass%"=="W" goto success echo.incorrect goto action The user is instructed to enter 'pass', but the if statement makes a compare to 'w'. Misleading the user is not recommended. Code: [Select]:success Echo.Welcome MillerGram echo.To rehide Folder type hide attrib -h -s Hidden set /p passa=: set userinp=%pass1:~0,100% if /i "%passa%"=="hide" goto hide echo.what was that? pause>nul cls goto success If the user should actually get here (see above), nothing particularly wrong in this section, just sloppy. Using set /p allows for a prompt message; you don't need the echo command. Code: [Select]:hide attrib +h /d /s Hidden goto success This is OK for what it does. Questions: What are these: set userinp=%pass:~0,100% Userinp is prompted for but never used There is no exit point to the logic. Once the user finally gets out of the :action tag, they get stuck bouncing around the :success and :hide tags. Using passwords in a batch file is self-defeating. At some point the code will have to compare the user input to the actual password. Anyone with an editor or knows how to use the type command will be able to see how to move around in the logic. You might consider making your code more generic. Prompt for the folder name, test if it exists, then proceed to hide/unhide it. Lose the passwords. Keep it simple. Just a thought. Thank You So Much Still Got Tons To learn Like I DINT already know that |
|
| 8625. |
Solve : Please help me...? |
|
Answer» That still doesn't explain why you want to shut down windows. Like I SAID I have plenty of batch files that do exactly that; none of them shut down windows.Quote from: BC_Programmer on January 26, 2011, 08:00:18 PM That still doesn't explain why you want to shut down windows. Like I said I have plenty of batch files that do exactly that; none of them shut down windows. If it's late at night, or I'm in a rush, I want to be able to let MBam for example, run a FULL scan and then shut down once the log file opens (when it's done). Once I start back up I will TEND to the logfiles. Hope I got where I was going with this. Add: Well, shutdown, sleep, Lock, or even just log out and sleep all together, all I wanted to do is have a configurable command appropriate for doing something after that program has opened. Nothing special.WHICH IS IT? ONE post you're talking about making a batch file for games. the next your blathering about Malware bytes.Quote from: BC_Programmer on January 26, 2011, 09:21:49 PM WHICH IS IT? This is SPECIFICALLY for MalwareBytes!! Good day *snoring*... |
|
| 8626. |
Solve : is it a bug?? |
|
Answer» Can SOMEONE tell me what's going on with this? C:\Documents and Settings\user\Desktop>testBut, if I double click the bat file to open, I get this: Quote y I'm pulling my hair out trying to figure out what's wrong. The outer if statement (simplified for troubleshooting) also has something to do with it, but I need it. Code: [Select]@echo off IF 1==1 ( SET /P _ans= echo [%_ans%] SET _ans IF /i "%_ans%" == "y" ( echo yes ) ) pause This may HELP. I added a prompt messages. Not sure why you wouldn't have one when requesting input. Also what is the purpose of the outer if statement? Code: [Select]@echo off if 1==1 ( set /p _ans=Prompt goes here: call echo [%%_ans%%] set _ans call if /i "%_ans%"=="y" ( echo yes ) ) pause Code: [Select][quote author=Sidewinder link=topic=115488.msg771696#msg771696 date=1296228053] what is the purpose of the outer [b]if[/b] statement? Since the test "IF 1==1" will always be satisfied I fail to see the point of it. What's with all that CALL stuff? IGNORING the redundant outer IF test... phatpaul, clearly you have noticed the problem of setting and expanding VARIABLES inside parentheses, but equally clearly you are not aware of the solution - delayed expansion. Google for more information. Code: [Select]setlocal enabledelayedexpansion if 1==1 ( set /p _ans=Prompt goes here: echo [!_ans!] if /i "!_ans!"=="y" ( echo yes ) ) |
|
| 8627. |
Solve : List all files that have the extension .doc? |
|
Answer» I need help WRITING a dos command to list all the .doc files in my directory. OS: Linux variant They want help writing a DOS command.To run in a Linux variant?Quote from: Dusty on January 28, 2011, 12:58:24 AM To run in a Linux variant? I don't recall them saying that. If I was to request help with sudo or ANOTHER Linux command, would I be told to post in the windows forum simply because I have placed windows as my OS in my profile?Quote from: BC_Programmer on January 28, 2011, 03:15:16 AM I don't recall them saying that. Linux is his OS, but Microsoft is his homework, I think. Quote from: SALMON Trout on January 28, 2011, 10:26:27 AM Linux is his OS, but Microsoft is his homework, I think.What a way to learn! |
|
| 8628. |
Solve : Verifying the batch file compelted successfully? |
|
Answer» Is there a way to check for a RETURN string after issuing commands through a bat FILE. |
|
| 8629. |
Solve : Make a batch file delete in exit a.k.a when you press X on top right of screen? |
|
Answer» Is it even possible to make a batch file delete self when you exit USING the big x on the top right of the SCREEN? Is it even possible to make a batch file delete self when you exit using the big x on the top right of the screen? Can a man commit SUICIDE after he has been KILLED by lightning? Ok i get it it cant be done Quote from: millergram on January 29, 2011, 04:00:45 PM Ok i get it it cant be done The problem is that when you click the X you interrupt the batch script before it finishes so that it cannot execute a line containing a command to delete itself. |
|
| 8630. |
Solve : Help with command line arguments? |
|
Answer» Hello everyone. I'm trying to create a batch file which accepts a few commandline arguments. My problem is that I do not want to check for %1 or %2 etc, but for %* which means that the user should be able to specify the arguments regardless of their order. the user should be able to specify the arguments regardless of their order Why? You are making the script unnecessarily complicated, and batch language is very bad at this sort of thing. However you can use FOR to split the parameters up, assuming that each contains no spaces. This example uses numbers for the FOR metavariables; if you want more than ten (0-9) you'll have to use letters. The example assumes 3 parameters are expected Code: [Select]@echo off for /f "tokens=1-3 delims= " %%1 in ("%*") do ( set parameter1=%%1 set parameter2=%%2 set parameter3=%%3 ) set check=0 if "%parameter1%"=="" set /a check+=1 if "%parameter2%"=="" set /a check+=1 if "%parameter3%"=="" set /a check+=1 if %check% gtr 0 echo Wrong number of parameters & goto end echo parameter 1 is %parameter1% echo parameter 2 is %parameter2% echo parameter 3 is %parameter3% :end Quote You mentioned FOR so I deduce this is not about MS-DOS. You should be aware that in Windows bath scripting the double ampersand (&&) is not a simple command separator (like in Unix). It is an errorlevel test. "Command1 && command2" means "execute command1 and if the errorlevel from command1 is zero, (and only if) then execute command2". The standard command separator where you want more than 1 command on a single line is the single ampersand (&) for example command1 & command2. Also you don't need to put the colon before the label identifier in a goto statement, and using all capital letters is not compulsory. I'm aware of that, I'm just used to use this and since it works for my cases I never bothered with this. Thanks for reminding it me. As for the capital letters I simply prefer them for the dos commands. Quote Why? You are making the script unnecessarily complicated, and batch language is very bad at this sort of thing. Well, even so I have to use batch for this since it's the only language I'm familiar with. Here is what I'm trying to achieve. I need to be able to parse 2 commandline arguments but without having to use them in a specific order. So I can't check for the first or the second argument specifically. There must be a way to filter all the arguments with FIND and set the two vars I need. My situation is more like this: Accept all days as one argument and all months as another one. If none of these are used then error out. The second part is easy I know it's difficult and that batch isn't the best way to do it, but I have to stick to it, unfortunately.Code: [Select] @echo off setlocal enabledelayedexpansion set errormessage=1 day and 1 month not supplied REM split parameters into two tokens for /f "tokens=1-3 delims= " %%1 in ("%*") do ( set parameter1=%%1 set parameter2=%%2 ) REM check for blank arguments set check=0 if "%parameter1%"=="" set /a check+=1 if "%parameter2%"=="" set /a check+=1 if %check% gtr 0 echo %errormessage% & goto end REM check for 1 day and 1 month set days=0 set months=0 for %%A in (%parameter1% %parameter2%) do ( echo %%A | FINDSTR /I "Monday Tuesday Wednesday Thursday Friday Saturday Sunday">nul && ( set /a days+=1 set day=%%A ) echo %%A | findstr /I "January February March April May June July August September October November December">nul && ( set /a months+=1 set month=%%A ) ) if not %days% equ 1 echo %errormessage% & goto end if not %months% equ 1 echo %errormessage% & goto end echo day: %day% echo month: %month% :end Like I have told you 10 times already, you are the best! This is what I was looking for. Except for a minor change I need to make. I want to handle the case where no arguments are specified (or one of the two isn't) a little different, use the default values in this case (Monday/January in our example). But also keep the check for invalid arguments like it is now. Thank you very much, without your help I would be lost in the ocean Try this Code: [Select]@echo off setlocal enabledelayedexpansion set monthlist=January February March April May June July August September October November December set daylist=Monday Tuesday Wednesday Thursday Friday Saturday Sunday set DefaultDay=Monday set DefaultMonth=January REM split parameters into two tokens for /f "tokens=1-3 delims= " %%1 in ("%*") do ( set parameter1=%%1 set parameter2=%%2 ) set days=0 set months=0 for %%A in (%parameter1% %parameter2%) do ( echo %%A | findstr /I "%daylist%">nul && ( set /a days+=1 set day=%%A ) echo %%A | findstr /I "%monthlist%">nul && ( set /a months+=1 set month=%%A ) ) if %days% equ 0 set day=%DefaultDay% if %months% equ 0 set month=%DefaultMonth% echo day: %day% echo month: %month% Thanks for your reply. Now, this approach is using the default values correctly and it's cleaner. But there's a problem with the FINSTR command. If I use "Mondayy" it will return this value. I think this can be solved by using \ etc. That's why I want to make it error out if any of the two arguments is not one of those in the list so that it doesn't use the default silently but only when one or none of the arguments is specified.Could you tell me why it is so important that the parameters need to be presented in any order? I think I must be MISSING something, but couldn't shift be used for this in some capacity?Quote from: BC_Programmer on January 30, 2011, 10:45:20 AM I think I must be missing something, but couldn't shift be used for this in some capacity? Shift will get over having more than the 9 arguments allowed by the %1 to %9 parameters. Here we only have a fixed number. I am not sure if the OP is using "months" and "days" as generic examples for them, and whether there are going to be more than 2 in the finished script. We don't actually need to split %* - %1 and %2 will do just fine. Quote from: Salmon Trout on January 30, 2011, 09:51:29 AM Could you tell me why it is so important that the parameters need to be presented in any order?I need to eliminate the case where someone uses the arguments in the wrong order. Currently I only have 2 arguments, but if it works I think I will be able to extent it for more Your last code is ALMOST what I need, I just need it to check for invalid arguments and error out. I'll see if I can make FINDSTR to work only with the specific string and not any string that contains the words in the list. Thank you very much for your help. |
|
| 8631. |
Solve : Sudoku glitch? |
|
Answer» This has REALLY GOT me stumped. I created a sudoku-solving script (still in the works) that's getting a really weird issue. 4_153_68_(By the way, this is the answer I got when I ran the script)Quote 4 2 1 5 3 9 6 8 7 But I get a weird issue when I try this puzzle: (which can be solved, ACCORDING to http://www.sudokusolver.co.uk/) Quote 7_4_2__96Issue: Quote 7 _ 4 _ 2 _ _ 9 6 <-- No spots filled, even though it pauses (meaning it's done) And for some other puzzles, it messes up and says one of the numbers is "_=". Puzzle: Quote 4_3__9168Result: Quote 4 2 3 5 7 9 1 6 8 Anyway, here is the script I'm using: Code: [Select]@echo off setlocal enabledelayedexpansion set line0=4_153_68_ set line1=639____51 set line2=_7_6412_9 set line3=___152_74 set line4=782___915 set line5=14_798___ set line6=2_7486_9_ set line7=39____768 set line8=_16_735_2 ::set num=0 ::for /f "delims=" %%A in (sudoku4.txt) do set line!num!=%%A & set /a num+=1 for /l %%L in (0,1,8) do ( for /l %%C in (0,1,8) do ( set l%%Lc%%C=!line%%L:~%%C,1! ) ) :re call :display for /l %%L in (0,1,8) do ( for /l %%C in (0,1,8) do ( if !l%%Lc%%C!==_ ( set l%%Lc%%Cposs=123456789 for /l %%Z in (0,1,8) do ( for %%P in (!l%%Lc%%Z!) do ( set l%%Lc%%Cposs=!l%%Lc%%Cposs:%%P=! ) ) for /l %%Z in (0,1,8) do ( for %%P in (!l%%Zc%%C!) do ( set l%%Lc%%Cposs=!l%%Lc%%Cposs:%%P=! ) ) ::check box if %%L LEQ 2 ( if %%C LEQ 2 ( set box=1 ) else if %%C LEQ 5 ( set box=2 ) else ( set box=3 ) ) else if %%L LEQ 5 ( if %%C LEQ 2 ( set box=4 ) else if %%C LEQ 5 ( set box=5 ) else ( set box=6 ) ) else ( if %%C LEQ 2 ( set box=7 ) else if %%C LEQ 5 ( set box=8 ) else ( set box=9 ) ) ::echo %%L,%%C is in !box! if box==1 for %%P in (!l0c0! !l0c1! !l0c2! !l1c0! !l1c1! !l1c2! !l2c0! !l2c1! !l2c2!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==2 for %%P in (!l3c0! !l3c1! !l3c2! !l4c0! !l4c1! !l4c2! !l5c0! !l5c1! !l5c2!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==3 for %%P in (!l6c0! !l6c1! !l6c2! !l7c0! !l7c1! !l7c2! !l8c0! !l8c1! !l8c2!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==4 for %%P in (!l0c3! !l0c4! !l0c5! !l1c3! !l1c4! !l1c5! !l2c3! !l2c4! !l2c5!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==5 for %%P in (!l3c3! !l3c4! !l3c5! !l4c3! !l4c4! !l4c5! !l5c3! !l5c4! !l5c5!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==6 for %%P in (!l6c3! !l6c4! !l6c5! !l7c3! !l7c4! !l7c5! !l8c3! !l8c4! !l8c5!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==7 for %%P in (!l0c6! !l0c7! !l0c8! !l1c6! !l1c7! !l1c8! !l2c6! !l2c7! !l2c8!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==8 for %%P in (!l3c6! !l3c7! !l3c8! !l4c6! !l4c7! !l4c8! !l5c6! !l5c7! !l5c8!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! if box==9 for %%P in (!l6c6! !l6c7! !l6c8! !l7c6! !l7c7! !l7c8! !l8c6! !l8c7! !l8c8!) do set l%%@c%%Cposs=!l%%@c%%Cposs:%%P=! ping localhost -n 1 > nul call :length !l%%Lc%%Cposs! if !len!==1 ( set l%%Lc%%C=!l%%Lc%%Cposs! goto re ) ) ) ) pause exit :length set #=%1 set len=0 :lenloop if defined # (set #=%#:~1%&set /A len += 1&goto lenloop) goto :eof :display cls echo. for /l %%L in (0,1,8) do ( set line= for /l %%C in (0,1,8) do ( set line=!line! !l%%Lc%%C! ) echo !line! ) As you can see, it solves the puzzle in the code fairly quickly, but like I said, it doesn't work for some. I've tried 5 different puzzles, but those are the issues I get.Oh dear... a sodoku solver in batch? Well, the first thing that leaps out at me is that there is no way you are using all the different algorithms which are required to reliably solve sodoku puzzles. Brute force/CRME will solve some, but not all; I can't really tell but I'm pretty sure you are only doing a brute force attempt to solve, and aren't performing any checks for lone rangers or twins. For your first "weird" issue puzzle, my program gives me this: I have no idea if it's right or not. I'm surprised it even looks like it worked, I would have practically bet money that it either crashed or only half-filled the board- I guess I don't have a lot of faith in any of my old VB6 programs anymore... As for your puzzle that "messes up"... it's not even a valid puzzle. the 5th column has two fours in the initial setup. the "result" still has two fours, but no doubt the fact that there were two fours has caused the equals sign issue. I wouldn't have even noticed if my program didn't PREVENT me from selecting four for the second instance . You can discount that "problem" entirely since it's not even a valid puzzle to start with. any other problems are almost certainly because you are only using CRME (Column-Row Minigrid Elimination) and aren't dealing with Lone Rangers or twins; I gave up on mine when it couldn't complete some of the "hard" puzzles from a puzzle book; no doubt I need to implement triplets to get those to be solved problem-free. Wow, I'm surprised I didn't realize that the puzzles were wrong originally. I realized that I wouldn't be able to solve every puzzle, but thanks for your help anyway.Here's a very good example of what you're talking about BC. Puzzle: Quote __91_7_42 Solution from the script: Quote 6 3 9 1 5 7 8 4 2 Solution from the script (and me): Quote 6 3 9 | 1 5 7 | 8 4 2Mine solved it! yay. Sorry I'm just surprised at how well it seems to work. What's really weird, my script should have solved the puzzle I just posted... Quote
|
|
| 8632. |
Solve : Copying MANY Files from a DOS Laptop? |
|
Answer» Hi, |
|
| 8633. |
Solve : concatenate list? |
|
Answer» I'm using this batch file : @dir/w %1 > c:\File_list\filelist.txt which gives me this Volume in drive C is OS Volume Serial NUMBER is XXX-XXXX Directory of C:\DELL [.] [..] ATAPI.EXE DELLBUTN.HTM DELLCIRC.ICO E-WTRMRK.GIF [r069r] SOL_CENT.JPG USBS3KB.REG UWAKEOFF.exe UWAKEON.exe 8 File(s) 271,522 bytes 3 Dir(s) 130,348,281,856 bytes free and edit it to give me something like this C:\DELL ATAPI.EXE DELLBUTN.HTM DELLCIRC.ICO E-WTRMRK.GIF SOL_CENT.JPG USBS3KB.REG UWAKEOFF.exe UWAKEON.exe This is an example of a small folder, I'm normally dealing with larger numbers. Is ther a quicker way to ge this, or nearer this, full path plus LIST of files with NO details. thanksReplace dir /w with dir /b. Iif you don't want directories (folders) to be listed USE the /a-d switch. It's all in the DIR help which you can access by opening a command window and typing DIR /? Code: [Select]F:\Dtest>dir /w Volume in drive F is IDE02 Volume Serial Number is E0E2-3A64 Directory of F:\Dtest [.] [..] avih_aac.bin avih_adpcm.bin avih_jpeg_hufftables.bin avih_mp3cbr.bin avih_ms_adpcm.bin avih_noaudio.bin avih_pcm.bin avih_ulaw.bin copying.txt FccMap.default.ini FccMap.ini lame_enc.dll libfaad2.dll libMAD.dll Mp4Cam2AVI.exe playlist.asx settings.ini xvidcore.dll [_help] 18 File(s) 2,162,525 bytes 3 Dir(s) 96,652,644,352 bytes free Code: [Select]F:\Dtest>dir /b /a-d avih_aac.bin avih_adpcm.bin avih_jpeg_hufftables.bin avih_mp3cbr.bin avih_ms_adpcm.bin avih_noaudio.bin avih_pcm.bin avih_ulaw.bin copying.txt FccMap.default.ini FccMap.ini lame_enc.dll libfaad2.dll libMAD.dll Mp4Cam2AVI.exe playlist.asx settings.ini xvidcore.dllThanks, I did GET as far as this but perhaps I didn't make the question clear enough. the reference to concatenate in the subject line was to whether the file list can have the full path in the FIRST (or last) line. For instance, can I write to the file once and then with the full path only without overwriting. C:\DELL ATAPI.EXE DELLBUTN.HTM DELLCIRC.ICO E-WTRMRK.GIF SOL_CENT.JPG USBS3KB.REG UWAKEOFF.exe UWAKEON.excreate file, overwriting any file with same name Code: [Select]dir /b > list.txt create file if it does not exist, append to file if it already exists Code: [Select]dir /b >> list.txtThanks, that's what I was looking for. |
|
| 8634. |
Solve : The wrong language in my MS_DOS.? |
|
Answer» I have bought a new hard drive for my 'Medion' laptop. I put the new hard drive into the laptop, went into fdisk and partitioned the drive so I could put the recovery files into d: drive and then let the laptop program its self with the support disc. When I STARTED the laptop to program itself it start to communicate to me in German, it was using English before the new drive, I have tried to change it back to English, but every thing I try fails to work. Does anybody know whats wrong here, I would be grateful for any ideas. Thankyou. Colo.Doesn't make sense....HDD's are blank and you do NOT need the software that came with it... |
|
| 8635. |
Solve : Scheduled Task That Cannot Hang? |
|
Answer» Would appreciate some help here. Is it possible to create a DOS Batch script that runs as a Scheduled Task (and executes Excel and ACCESS macros) so that it always exits; i.e., can never get hung? I understand that setting the scheduled task parameter that tells it to end if running longer than x hours doesn't always work. Thanks.Quote from: sumdumgai on January 25, 2011, 01:58:45 PM I understand that setting the scheduled task parameter that tells it to end if running longer than x hours doesn't always work. Thanks. First I've heard of this. Have you tested this out? Both Access and Excel can execute macros when opened. Access at one time used AutoExec and Excel used Auto_Open. Check your help files specific to your versions. The batch file does not actually execute the macros. You must open Access and Excel via the batch file, and let each application execute the starting macro. Good luck. Yes, I've tested this. Even when this parameter is set, if Excel (or Access) is running a macro and for instance if an error occurs that requires a user acknowledgement (like an 'OK '), then the task remains open (and hung). You'd need the process PID or some other identifier to kill the task.If the macro throws an error, the application goes into a wait state and execution clock stops waiting for your response. VBA supports variations of the on error instruction which allows you to programmatically decide what to do when an error is thrown. I suspect the default action is to put up a window with the error message and line number. By setting up an on error routine, you can override the default and perhaps completely ignore the error, or even shutdown the macro without halting. This link has more information. Good luck. Quick resolution to prevent that would be an On Error Resume Next at the top of each macro routine; (and removal of any existing "On Error GOTO 0")When I saw the title I was reminded of something. Isn't asking for a program that "cannot hang" just what Alan Turing proved in 1936 couldn't be done? That is, that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist. Quote from: Salmon TROUT on February 02, 2011, 01:48:37 PM When I saw the title I was reminded of something. Isn't asking for a program that "cannot hang" just what Alan Turing proved in 1936 couldn't be done? That is, that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist. the proof was more that it was impossible, by analyzing the code of a program, to determine wether that program "halts" and in what cases it does so. (The specific source where I read this I cannot recall- but it presented most of it's material using Pascal, and the idea was expressed by presenting pascal programs that had "halt" instructions execute in certain CONDITIONS; while it's possible for a program to determine wether another program "halted" when it was merely a "halt" instruction, the problem became INTRACTABLE as the cyclomatic complexity rose. I can't remember very much about the specifics of that particular chapter. Of course in this case, the "hang" is only a hang in the context of a scheduled task, since it is asking for user-input. |
|
| 8636. |
Solve : How to change resolution and run old Windows program from batch file? |
|
Answer» It works! At last! Thank you so much BC and I'm sorry I got the terminology wrong. Your solution should be tagged and archived here for anyone else who RUNS into the same THING. It is an extremely useful answer to a really irritating problem. |
|
| 8637. |
Solve : Batch file start executable problem? |
|
Answer» Hi, |
|
| 8638. |
Solve : Dos Command? |
|
Answer» I get a DOS command after the start of the motherboard en read as FOLLOWS: |
|
| 8639. |
Solve : Dos harddrive failure? |
|
Answer» I'm trying to boot an harddrive into dos 6.22, i format the harddrive after booting into dos 6.22 form a disk, i run format c:/s. after that if i reboot on the disk, a can acces the harddrive, and see the command.com, but i can't boot on the harddrive, i always receive the message "hard drive FAILURE" If you ran the format then C: is empty... He used the /s switch. If I recall, doesn't that transfer system files, and make the formatted disk bootable? ... or is supposed to? I wonder if there was some error message. That's right Willy....forgot about the /s switch... It should indeed be bootable. The drive may have gone South... DLoad the Free diagnostics from the HDD manuf. site...run the long test.Quote from: patio on February 03, 2011, 07:06:55 AM That's right Willy....forgot about the /s switch... What I was wondering, and have not taken time to look up.... way back my memory, isn't there something about DOS 6.22 and hd size limit? Was it 2GB? (and I'm assuming that the drive in question here is larger than that) That's what I was wondering about, when I asked about error messages. I just can't remember what happens with 'large' hard drives. Could using a 'large' hd be the poster's problem? Quote The drive may have gone South... That too. Well he didn't mention the size...i'll guess we have to wait... The 2G was a FAT limitation....not neccessarily confined to DOS...Quote from: patio on February 03, 2011, 08:42:19 AM Well he didn't mention the size...i'll guess we have to wait... Ah! That's it. Quote not neccessarily confined to DOS... But... DOS used FAT. Well... I don't mean to obfuscate the issue. I was reaching.. looking for possibilities. Let's see what he has to say, when he returns. I'd still like to know if there was any error message. Thanks Here's the message: Quote i always receive the message "hard drive failure" We:ll see...thats why i suggested HDD diagnostics.Quote from: patio on February 03, 2011, 09:04:12 AM Here's the message: Sorry... I was referring to : "i run format c:/s" ... I wondered if that command behaved normally, or if it showed some error. Would DOS 'lie', and report hard drive failure if it tried to boot from a hd, and only got part way through it? And I agree... it sure can't hurt, in the process of elimination, to do the hd diagnostics. More precision: Hi, what I'm trying to do is to "repair" and old industrial computer from siemens running on a PLC setup. This computer is a 386 with a phoenix 1.02 BIOS. I try to USE an 2G hard drive. the broken one was a 3G, larger than the configured BIOS setting TYPE 17 (40Mb), but it was working!! i'm pretty shure tha the 3g was running in dos6.22 because a "setver" command was in the config.sys hope it will help I'm running this program now to repair all the "bad" sectors on a freshly formatted 20GB hard drive. It's not a free program but so far, it's fixing every bad sector. Read the User testimonials. I also used it to repair industrial PLC's (A-B). FAT16 MAX volume size is 2GB. Your 3GB drive may have unallocated the last 1GB which is no problem.Quote from: Computer_Commando on February 03, 2011, 04:59:07 PM FAT16 max volume size is 2GB. specific Operating systems (DOS, win9x for example) limit FAT-16 to 2GB, because they use a 32K maximum cluster size; unsigned short (16-bit) gives us 65,536 clusters; with 32K clusters that gives us 2,147,483,648 bytes (2GB); with 64K sized clusters, it goes up to 4GB. 64K is the largest possible cluster size, and can be used by at the very least NT4 (don't know about other versions) For the purposes being described, though, this is all irrelevant. In fact, such limitations are wholly redundant since they successfully issued a format command. The DOS Format command isn't going to format a drive larger then capacity; and I don't think fdisk will allow you to create a partition larger then 2GB anyways. personally I've never had much luck with the /s switch on format. I always end up using sys C:... or perhaps it's force of habit. Quote from: gibson1965 on February 03, 2011, 01:47:52 PM the broken one was a 3G, larger than the configured BIOS setting TYPE 17 (40Mb), but it was working!! I think it does, gives us some context. So If I understand this correctly, you have the "new" 2GB installed using TYPE 17? I'd run a sys C: after booting from the floppy, just to be sure. Maybe "start over" by using fdisk and deleting all partitions and recreating them. (or, it, I should say). the new hard drive may simply not be compatible as a Type 17; you might be able to use type 47 (user) and put in your own disk geometry; but you'd probably be better off swapping through a few different types until you get something that works reliably. Quote from: WillyW on February 03, 2011, 09:24:04 AM I wondered if that command behaved normally, or if it showed some error.This- did the format complete successfully? after the format it will state "System transferred"; did this occur? Quote Would DOS 'lie', and report hard drive failure if it tried to boot from a hd, and only got part way through it?No. The error is being reported by the BIOS; a MACHINE of that era would often state hard disk failure simply because it couldn't boot from the drive. (DOS doesn't report serious hard disk errors at all; usually the best you can hope for is a hang) Quote from: BC_Programmer on February 03, 2011, 08:37:24 PM ... you might be able to use type 47 (user) and put in your own disk geometry; but you'd probably be better off swapping through a few different types until you get something that works reliably.That's what I was going to suggest. |
|
| 8640. |
Solve : Run multiple command in a batch file? |
|
Answer» Hi all, WORKS... It's to do with the way the command interpreter expands variables. Using a percent sign (%) in a batch file requires that two percent signs (%%) be specified. For example, the command to display "5%" from a batch file would be : ECHO 5%% A single percent sign on a line is treated as a "nul" character in a batch file. For example: ECHO % is processed as ECHO ECHO a%b is processed as ECHO ab If a command contains two percent signs, the command interpreter will treat any characters between them as an environment variable to be expanded. For example, if the SET command shows that the current environment variables are COMSPEC=C:\COMMAND.COM PATH=C:\DOS PROMPT=$P$G B=C then ECHO %PATH% is processed as ECHO C:\DOS ECHO a%b% is processed as ECHO aC ECHO a%b b%a is processed as ECHO aa If there are no characters between the two percent signs, one percent sign is stripped off and the other will remain. This is why a FOR command that echos the name of each file with a .COM extension would be FOR %V IN (*.COM) DO ECHO %V but if the same command is placed in a batch file, the following is required: FOR %%V IN (*.COM) DO ECHO %%V Perfect i have understood all. Now i have an other problem related to the same batch. I need to launch the for command on a file that isn't in the same directory where the batch run. I have TRIED to modify the batch from: Code: [Select]for /f "tokens=1-2 delims=." %%i in ('dir *.rar /b') do ren "%%i.%%j" "%%i0330.%j" to: Code: [Select]for /f "tokens=1-2 delims=." %%i in ('dir C:\temp\*.rar /b') do ren "%%i.%%j" "%%i0330.%%j" But i receive the error "The System cannot find the file specified". This time where is the problem ? P.S. Sorry if i asked stupid thing but i am a newbie... Code: [Select]for /f "delims=" %%i in ('dir /b C:\temp\*.rar') do ren "%%~dpnxi" "%%~dpni0330%%~xi"I apologise, the above won't work, but this should... Code: [Select]for %%i in ("C:\temp\*.rar") do ren "%%~dpnxi" "%%~ni0330%%~xi" explanation FOR %%variable IN (set) DO command. Using FOR without the /F switch and therefore no tokens/delims block, (set) can be a set of one or more files, wildcards can be used. There are FOR variable modifiers... in this case we use ~d, (drive) ~p, (path) ~n (name) ~x (extension) so if (set) is a file or files, then: %%~di is the drive letter (with a colon) %%~pi is the path %%~ni is the file name %%~xi is the file extension (including the dot) They can be combined so that %%~dpnxi is the full drive letter, path, name and extension of a file. You need to supply this to REN if the file in QUESTION is not in the current directory. Type FOR /? at the prompt for the command help. |
|
| 8641. |
Solve : Talking to IIS 7 (Windows 7, 2008)? |
|
Answer» Hi, |
|
| 8642. |
Solve : Unzip Windows script? |
|
Answer» Hi, Again. I appreciate you explaining intoptions variable, as that was going to be my next question. I have no idea how you saw that coming. Oh, I just had a feeling... also I decided it was a useful thing to mention. Quote I have one more question. If I have the .vbs file and the .zip file on the same folder, why doesn't the relative path (i.e. just the filename (file.zip) does not work? Is there any way to acheive that? I imagine it does not work because the file copy routine you are calling probably requires a full path for the source folder (zip file really). If you wish to use a script's own folder path then you can get that from WScript.ScriptFullName. Surely that is in your book? Option Explicit Dim folderPath01 Dim Zipfile Dim ZipfileFullPath Dim ScriptPath Dim ScriptFullName Dim Objshell Dim objSource Dim objTarget Dim intOptions Dim CopyOption ScriptFullName = WScript.ScriptFullName ScriptPath = Left (scriptFullName, InStrRev ( scriptFullName, WScript.ScriptName) - 1) folderPath01 = "C:\AV\" Zipfile = "test.zip" ZipfileFullPath = ScriptPath & Zipfile CopyOption = 256 DummyValue = UnzipFolder(folderPath01, ZipFileFullPath, CopyOption) Function UnzipFolder(FoldPath, ZipFileName, IntOptions) Set objShell = CreateObject( "Shell.Application" ) Set objSource = objShell.NameSpace(ZipFileName).Items() Set objTarget = objShell.NameSpace(FoldPath) objTarget.CopyHere objSource, intOptions End Function |
|
| 8643. |
Solve : REGEDIT in .bat file? |
|
Answer» Quote from: BC_Programmer on February 06, 2011, 09:30:42 AM While I don't doubt that the circumstance is similar, I would be more likely to attribute it to somebody trying to GET a game they shouldn't be running on at least one school computer... generally FRENCH Classes aren't taught in a computer lab Oh but they most surely are, At my school we did lot's of excercises at the computer lab Yes, in plenty of schools a room with COMPUTERS in it is used as an audiovisual resource for many subjects as well as for teaching computer related topics. wow. That certainly explains why so many kids have trouble with their penmanship; the school I went to only had I think 7 computer labs; 2 were solely for computer courses; and 4 were "rented" by other classes. (which of course could very well be french). But generally classes like french, Math, Science/Social STUDIES, etc weren't taught in a computer lab- they were taught in a "normal" classroom. Even then, I (as ironic as this may sound) hated it. I much preferred to write out my essays by hand; this feeling was only reinforced when the first time I did hand in a printed-out version I was accused of plagiarism . I don't think I ever handed in ANOTHER type-written essay through the rest of high school after that. Not that I felt badly about it; after all seeing the handwriting/printing of fellow students it looked like my writing might have looked in 4th grade. I liked working with computers, but I didn't like doing my work on computers (if that makes sense); for a similar reason I hated the fact that I grade 12 math required a graphing calculator; more so that it was used for nearly everything. I ended up just writing TI-BASIC programs to do my assignments for me after I understood how it was done, which somewhat defeated the purpose of the assignments themselves... I've retained most of it I think, aside from Synthetic division, since I've ended up using most of it for my programs (Trigonometry has a strong tendency to show up when it's not wanted for example) |
|
| 8644. |
Solve : How to re activate DOS commands in Win XP SP3?? |
|
Answer» hey, |
|
| 8645. |
Solve : [need help] unzip the binary file copy /b in bat/vbs? |
|
Answer» hello everyone, then i rename "result.jpg" to "result.zip"Quote from: mroilfield on February 06, 2011, 07:33:11 AM You do realize that just remaining the file from "result.jpg" to "result.zip" doesn't make it a zipped file right? If it isn't an actual zipped file then no matter what you do you won't be able to "unzip" it. Read his post. You can use the COPY command with the /b switch to join a jpg and a zip together into a third file, which you can give any extension you like. If you give it a .jpg extension, a jpeg viewer will see the jpg part and display it normally. It will not see the zip part. If you change the extension to .zip, an archive manager (Winzip, WinRar, etc) will see the zip part, but not the jpg, and process it normally. Thus you could hide a zip in a jpg or vice versa. What he does not seem to realise is that using wildcards and copying multiple jpegs and then multiple zips will not result in multiple hidden but accessible files. Only the first jpg and the first zip will be available, and only to a Zip program. Also that unlike proper Zip archive apps, the VBS unzip ROUTINES 1. Are really "copy from compressed folder" routines, and require compressed folders to be enabled. 2. Unlike WinZip, etc, won't like the fake "compressed folder" (zip file) resulting from the copy, and will copy nothing. Quote from: polle123 on February 06, 2011, 04:57:03 AM
thank you very much...my problem solve now....i use RAR file and everything solve.... ACTUALLY im do a program security call "4 gate folder security" like this :- first folder do a basic security like hidden folder or partition drives second folder do medium security like change extension of folder third folder do hard security like desktop.ini write extension of control panel(every time someone click it, it will go to control panel, if someone rename the file it will never change) forth folder do very hard security like hidden file inside jpg maybe next time i'll add one more security with make a password in the rar file.. |
|
| 8646. |
Solve : have installed ms dos but can't get cd rom drive recognized? |
|
Answer» Hard drive reformatted-so only MS Dps installed through old floppies. Have been UNABLE to get D drive (CD rom) to be recognized-even though the light does go on. |
|
| 8647. |
Solve : So, I wanna automate some processes....? |
|
Answer» Hello, Hello, I hate these "hide the truth" type threads. Why do people do this? Coyly mention a "certain little program" which they "will call Myprog.exe". What's wrong with saying what it is really CALLED? Is it a dirty little secret? I believe this thread starter may be Billrich. Just in case it isn't, the answer is, put the consecutive command lines in a text file and save it with a .bat or .CMD extension. For Linux use .sh |
|
| 8648. |
Solve : how to open files on cmd? |
|
Answer» I am a beginner and was wondering how i can open jpeg files or avi files on cmd. I would also like to know how to open folders too... What do you mean by "open" them? Make them appear in a viewer or video player? And when you say "open" a folder, do you mean open it in Windows Explorer? S.T. - how come my moggy got into your image He must have been on vacation in Spain, at the Jardín Botánico in Valencia, visiting the famous colony of 50+ CATS that live there, fed by the staff and supported by donations from local people and visitors who "adopt" a cat. Perfect! thanks salmon trout! can i use the "Start "" "c:\path\to\folder"" in a batch file to open images using windows explorer?Quote from: maymon123 on February 09, 2011, 10:02:04 AM can i use the "Start "" "c:\path\to\folder"" in a batch file to open images using windows explorer? Open images in Windows Explorer? What do you mean? sorry, windows "picture and fax viewer". I would like a batch file to open a picture using that program...Quote from: maymon123 on February 09, 2011, 10:28:41 AM sorry, windows "picture and fax viewer". I would like a batch file to open a picture using that program... Is it the default picture viewing program? yes Quote from: maymon123 on February 09, 2011, 10:35:25 AM yes Did you do what I said above? UMM..... i tried... but how do i NAVIGATE through folders in cmd.... i am in the c drive, so "C:\>" SHOWS up, how do i open a folder on the c drive (Documents and settings)? I want it to be "C:\documents and settings".Quote from: maymon123 on February 09, 2011, 10:49:16 AM umm..... i tried... but how do i navigate through folders in cmd.... i am in the c drive, so "C:\>" shows up, how do i open a folder on the c drive (Documents and settings)? I want it to be "C:\documents and settings". C:\>cd "Documents and Settings" [hit Enter] Why do you want to do this? It seems like a lot of trouble for you. Oohh... thats it.... sorry, i love command prompt and i haven't used my computer for a while, due to school... so i forgot everything i knew... sorry.Thanx for all the help! |
|
| 8649. |
Solve : prompt in bat? |
|
Answer» hi there, |
|
| 8650. |
Solve : cmd in japanese? |
|
Answer» I was just WONDERING if there is any WAY to change cmd into Japanese and BACK to english... |
|