Explore topic-wise InterviewSolutions in .

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.

2801.

Solve : Please explain me?

Answer»

I did write the following C code. I was able to use the TCC complier.
Output is displayed.


C:\>type pas.c

Code: [SELECT]#include<stdio.h>

void main()
{

int line,c,n,x;
void pasc(int);

printf("\n\nEnter the no. of rows: ");
scanf("%d",&line);

printf("\n\n\n");
printf("\nPascal's triangle :\n");

for(x=line-1;x>=0;x--)
printf(" ");
printf(" 1\n\n");

for(n=2;n<=line;n++)
{
for(c=line-n;c>=1;c--)
printf(" ");
pasc(n);
printf("\n");
}


}
void pasc(int n)
{
int R;
long fact(int);
for(r=0;r<=n;r++)
printf("%3ld ",fact(n)/(fact(n-r)*fact(r)));
}

long fact(int v)
{
if(v==1||v==0)
return(1);
else
return(v*fact(v-1));
}Output:

C:\>pas.exe


Enter the no. of rows: 9




Pascal's triangle :
1

1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

C:\>Quote from: marvinengland on June 20, 2010, 07:40:25 PM

I did not write the C code. I was able to use the TCC complier.
Output is displayed.

I did not write the C code in the post above .
I was able to use the TCC complier.
Output was displayed.
2802.

Solve : Need help making Batch program?

Answer»

Hello,

I'm making a batch program, and there are a few things that I need help with that I haven't been able to find on-line anywhere. They are:

1) in DOS, how would I write, "if a=b and c=d then sign in"?
2) is there a WAY, to make a CHARACTER typed, display as an X or * or SOMETHING? (This is for a password entry line.)
3) When using the "Net Send" command, can the sender designate the height, width, color, or orientation of the message pop-up?

These are the only QUESTIONS I have for now. I appreciate any help that you guys have!

Sincerely,
kyle_engineer

#1
Code: [Select]@echo off
set a=5
set b=5
set c=7
set d=7

if %a% EQU %b% (
if %c% EQU %d% echo ok)

#2
Code: [Select]@echo off
echo hP1X500P[PZBBBfh#b##[emailprotected]`$fPf]f3/f1/5++u5>hide.com

:retry
set /p userid=Enter UserId:
set /p password=Enter password: <nul
for /f "tokens=*" %%i in ('hide.com') do set password=%%i
if /i %password%==password goto next
cls
echo Try again. You are not logged in!
goto retry

:next
echo. & echo You are logged in!
del hide.com

#3 The net send help does not turn up any parameters for setting the height, width, color, or orientation of the message.

Note: #2 doesn't replace passwords with X or stars. The method is not secure and is only for demo purposes. By the way, the password is password. If you have XP Pro, you can use the ScriptPW object in any COM aware script language. Powershell also has methods for encrypting/decrypting passwords.

Good luck. Awesome! Thanks Sidewinder! I kinda surprised I didn't think of using the EQU function.

Sincerely,
kyle_engineer

P.S.
Do you know of any really good online references to use for study/debugging DOS? I haven't really been able to find anything other than the usual command lists (which usually don't have the best explanations).

2803.

Solve : path to run a batch script?

Answer»

Hi,
I am trying to run a batch program by giving the absolute path.

But it is not working.

For eg., c:\> d:\dir\test.bat

This doesn't work

But if GO directly to the dir ie.,

D:\dir> test.bat or D:\dir\test.bat

This works ( ie if i EXECUTE from the same Drive d: )

Why this happens.

I am finding problems while scheduling it on windows7


Quote from: bang_dba on June 20, 2010, 05:56:55 AM


I am trying to run a batch program by giving the absolute path.

But it is not working.

For eg., c:\> d:\dir\test.bat

This doesn't work



One problem might be the use the command "dir" as a folder NAME:

d:\NEW\test.bat
or
c:\>D:
D:\>cd new
D:\new\> test.bat





2804.

Solve : How to read inputs from a file & process the program?

Answer»

i am having file in which list of IP addresses are mentained,
and on all those ip-addresses i WANTED to schedule a perticular program,
How do i read the input file IP-addresses one-by-one, to schedule a program on all IP-addresses at a time,

Input.txt contains
10.48.118.x
10.48.118.y
10.48.118.z
&AMP; so on......

wanted to schedule following program on client IP-addresse's
cd\
C:
MKDIR \\10.48.118.x\c$\new_folder
copy test \\10.48.118.x\c$\new_folder\
for /L %h in (0,4,20) do AT \\10.48.118.x %h:00 /interactive /EVERY:m,t,w,th,f,s,su "C:\new_folder\process_para.exe"I couldn't test this because of network addressing differences. Let us know how you make out.

Code: [Select]cd\
C:
for /f %%v in (input.txt) do (
mkdir \\%%v\c$\new_folder
copy test \\%%v\c$\new_folder\
for /L %%h in (0,4,20) do AT \\%%v %%h:00 /interactive /EVERY:m,t,w,th,f,s,su "C:\new_folder\process_para.exe"
)

Good luck. Dear SIDEWINDER,
Thanks a lot!!!
this works great!!!

2805.

Solve : How to read username of computer?

Answer»

Like reading HOSTNAME, DATE &AMP; time of the COMPUTER, How to read the username of the computer?- which user has logged-in?Most versions of Windows HOLD the current user name in an environment variable called... %username%Dear Salmon Trout,
Thanks a lot!!!
This works great!!!

2806.

Solve : One more Batch File ?. Launch Shortcut Key sequence via Command Line??

Answer»

One more Batch File Question:

Can I trigger a SHORTCUT key sequence from a batch file (command line), as if a key combination had been pressed (EX. CTRL+ALT+B)?

Thanks Guys (and GALS). Appreciate it.Quote from: AaronStarr on June 16, 2010, 11:50:02 PM

Can I trigger a shortcut key sequence from a batch file (command line), as if a key combination had been pressed (ex. CTRL+ALT+B)?

I don't think so. VBScript has a sendkeys method that may be helpful. Is this shortcut key sequence needed to launch a program? Let us know.



Basically, I was wanting to use hotkeys that I have set up (w/ my 'HotKeyControl' program) to trigger things. Some for STARTING programs, yes.

Where's a good place to learn about VBScript? Is it difficult? And what type of (authoring/?compiling?) programs do you need for that?

Thanks.Scratch the questions above about VBS Scripts. I found some info on the net.
2807.

Solve : accessing CD Rom?

Answer»

While in command prompt, I can not get in to the CD rom drive, it keeps saying INVALID drive. I need to get in to the cd rom for i can install Windows XP (rebuilding computer).....I'm lost as what the problem is?Actually you will not find the same drive as you found while using CD drive on XP

So, I would suggest you to put a little bit more effort.

Try

C:
Dir
if there you can see your FILE fine. If not then proceed another letter

D:
dir

E:
Dir

F:
Dir

I am sure you will get one drive that is assigned for CD.
Make sure you enter the CD into CD drive.


If this helps let me know and give me thanks.C: is the hard drive. and i have tried D, E, F & G for the cd rom & it keeps saying invalid drive.Is the CD drive recognised in "My Computer"?

MerlynI don't have Windows installed yet, so there is no "my computer" to see if its recognized in or not. It is recognized in BIOS however.Quote from: bikerlbf406 on June 16, 2010, 07:50:04 PM

While in command prompt, I can not get in to the CD rom drive, it keeps saying invalid drive. I need to get in to the cd rom for i can install Windows XP (rebuilding computer).....I'm lost as what the problem is?


There shouldn't be a prompt. if you are getting a Prompt, you did something wrong.

Installing XP is as simple as booting to the CD-ROM. If you are booting instead to a MS-DOS boot disk (which interestingly is what most VERSIONS of windows make when you check "make a system disk" in the format dialog, which makes it absolutely useless), then you won't be able to access either the hard drive or the CD-ROM drive. (you can get CD-ROM access if you install a CD-ROM driver via config.sys, but seriously, that's more trouble then SIMPLY booting to the disc).The hard drive I have installed have a copy of XP on it; however it is corrupted with files missing, so it will not load. It does load to MS-DOS command prompt though. I've changed the BIOS to boot to the CD-Rom instead of the hard drive, however when I do that, it then says system halted & won't do anything else. Quote from: bikerlbf406 on June 17, 2010, 02:16:28 AM
It does load to MS-DOS command prompt though.

One problem.

Windows XP doesn't have a "command prompt" that can run at boot-up.

Quote
I've changed the BIOS to boot to the CD-Rom instead of the hard drive, however when I do that, it then says system halted & won't do anything else.

Sounds like a hardware issue, actually.I cant explain whats happening; however it boots up to MS-DOSBetter suggestion would be purchase a Bootable XP CD.

I think you are not using that. Cause bootable dosen't need to be located for the setup file.

I have been installing XP for many years. So, I never had problem. I am sure you written it from the computer. And you forgot to copy the boot.ini file.

Now, days you can use bootable USB drive to install windows. So, the best would be use bootable CD or USB drive.

Else you wil running in loop and never get to an end.

Regards

VishalThank you for for replies. After the last one & some investigation I realized that I wasn't GOING to get anywhere doing what I wanted, without buying a new cd. I was able to get around it though, by simply finding another old hard drive that I had around, alot smaller though, that had a full version of Windows ME on it. I just put the hard drive i wanted in as a slave & installed XP to it that way. Everythings working smoothly now. Thanks again.
2808.

Solve : Batch File: One Prog won't run (start /d), but all others do.?

Answer»

I have a Start Up .bat file I wrote.

Example:

start /d "C:\Windows\System32" notepad.exe
start /d "C:\Program Files\WordWeb 6" wweb32.exe
start /d "C:\Program Files\Convert" Convert.exe

The first two programs start fine, but the third program (convert.exe) will never start from the batch file (It starts fine, normally).

Any thoughts?Quote from: AaronStarr on June 16, 2010, 11:45:28 PM

The first two programs start fine, but the third program (convert.exe) will never start from the batch file (It starts fine, normally).

How do you know it never starts from the batch file? Does it throw an error? Does convert.exe run in Windows or the CMD shell? Does convert.exe create a log file you can check for more information? What do you mean by it "starts fine normally"? Define normal.

NEED more information, but it does seem curious. By *normally*, I mean that it runs fine if I run it from, say, the Start Menu shortcut link (or by double clicking it from its .exe). So I know it works. I just can't get it to run/start from a .bat file for some reason. It doesn't even show up in Windows Task Manager Processes as RUNNING hidden (when run from a .bat).

Does that clarify better?

Thanks.Are you sure that convert.exe is actually in that folder (C:\Program Files\Convert) and not some sub folder?

Why are you using the /d switch? Is there some special reason you can't do this?

Code: [Select]start "C:\Program Files\Convert\Convert.exe"Yes. Convert.exe is located in the right place (C:\Program Files\Convert\Convert.exe).

I learned to USE the /d switch For when you start a program (I don't even know what it does exactly). Is it not NECESSARY?

I figured out another way to make it work, though... Using a vbs script.

[[ The *special reason* to do it?... Yes, I could manually start it myself. But I wanted to start several programs together with the click of one mouse button. Programs that I use for work... to start up my 'work environment'. ]]

Thanks for your help.You misunderstood my question. Why don't you start convert.exe from a batch file (not "manually") with a line like this...

Code: [Select]start "C:\Program Files\Convert\Convert.exe"
That is, start followed by a space then the program drive letter, path, and filename (all in quotes because of the space in 'Program Files')

Have you tried this?

The /d switch changes to the directory that is named; you would do this if you wanted to actually be in that directory for some reason. If you did not need that specifically, you would use the FORM that I described above.


Ok... gotcha.

And thanks, also, for correcting me about the /d switch. Don't need it now, but might in the future (now that I know what it's for).
2809.

Solve : hide this one!?

Answer»

is it possible to hide this message "Could not found c:\test.xls"
when the file I want to delete does not exist
...echo is off and &GT;nul is already input in the code
any suggestion please?
thanks in advance!if exist C:\test.xls del C:\test.xlsthanks for the reply! I'll try that oneYou were part way to your goal with >nul. There are two streams that console programs use (1) stdout and (2) stderr. Just using >nul redirects stdout but not stderr. The del command uses stderr for its error message.

stdout:

Code: [Select]command>nul
command 1>nul
are equivalent

stderr:

Code: [Select]command 2>nul
redirect both:

Code: [Select]command>nul 2>nul
or

Code: [Select]command 1>nul 2>nul


so this (below) will SHOW no output whether or not c:\test.xls exists:

Code: [Select]del c:\test.xls>nul 2>nul

nice one! both of YOU had a great code, this is really a BIG help to my system! almost PERFECT!!! thank you so much!almost? what else is wrong with it?

2810.

Solve : Get to Other Bookmarks in Firefox using NirCmd??

Answer»

Hello. I'm not getting assistance with my question here:

Get to Other Bookmarks in Firefox using NirCmd? . . . https://www.computing.net/answers/office/get-to-other-bookmarks-in-firefox-using-nircmd/21151.html

To summarize, I would like to use NirCmd in a .BAT FILE to get to "Other Bookmarks" in Firefox, like how you can use Ctrl+Shift+B

It seems like you could run this code, and it would work, but you have to open the "Library" skin twice, in order for it to "work" (you have two "Library" skins open):

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

"C:\Program Files (x86)\NIRCMD\nircmdc.exe" exec show "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -chrome "chrome://browser/content/places/places.xul"
"C:\Program Files (x86)\NIRCMD\nircmdc.exe" exec show "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -chrome "chrome://browser/content/places/places.xul"

"C:\Program Files (x86)\NIRCMD\nircmdc.exe" win activate title "Library"

"C:\Program Files (x86)\NIRCMD\nircmdc.exe" sendkey pagedown down
"C:\Program Files (x86)\NIRCMD\nircmdc.exe" sendkey enter down
"C:\Program Files (x86)\NIRCMD\nircmdc.exe" sendkey pagedown up
"C:\Program Files (x86)\NIRCMD\nircmdc.exe" sendkey enter upIt works for me with the second "open Firefox" line commented out (or removed). Only one "Library" window open. I have my Nircmd files in a different folder from you, but I don't think that makes any difference.

I am not surprised you got few answers in that other place, since your question is way off-topic, as the forum is for questions about Microsoft Office.

Click image to zoom it.

Is that roast beef at the bottom of the pic ? ?...
Quote from: patio on December 31, 2017, 05:46:47 PM

Is that roast beef at the bottom of the pic ? ?...

It's part of some girl's dresses in the bottom left of a painting called 'A Tale from the Decameron' by John William Waterhouse (my wallpaper at the the time).

Quote from: patio on January 01, 2018, 07:10:38 AM

I knew you were being frivolous, but it's such a nice painting, I thought it would liven up the thread a bit, especially since the OP seems to have lost interest.
It is nice...I remember when i had a slideshow of M.C. Esher drawings as my wallpaper....i never got any work done...Salmon, can you try that .BAT file . . .

. . . but make sure that neither the Firefox browser, nor a copy of the Library "skin" is open.

I think that what you'll see is that it will open the Library "skin" to "All Bookmarks", but NirCmd won't do anything.

. . . ie. The sendkeys will not "act on" the Library "skin"

From what I'm seeing, NirCmd needs one of the above two "already open" in order for it to be able to workHey, you're right. If you only start one nircmd exec show Firefox, the send key stuff does not work, but if you start two, it does work on the second one.

However, if I start two Library windows, then kill the first one, the send keys stuff works on the second one.

"C:\utils\nircmdc.exe" exec show "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -chrome "chrome://browser/content/places/places.xul"
"C:\utils\nircmdc.exe" exec show "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -chrome "chrome://browser/content/places/places.xul"

REM Wait for Firefox to get going
REM You could use a SLEEP command here INSTEAD if you have sleep.exe
:loop
tasklist /v | find "Library" && GOTO next
goto loop
:next

REM On my system I needed at least 5 milliseconds of sleep
REM Maybe 10 or 100 would be safer
REM Using the sleep.exe with the -m option
REM In the Windows 2003 Resource Kit Tools
REM https://www.microsoft.com/en-us/download/details.aspx?id=17657
REM sleep -m 10

REM Taskkill will terminate the first window it finds with the title "Library"
REM which will be the first one you started then exit, leaving the second one running
taskkill /FI "WINDOWTITLE eq Library"

"C:\utils\nircmdc.exe" win activate title "Library"
"C:\utils\nircmdc.exe" sendkey pagedown down
"C:\utils\nircmdc.exe" sendkey enter down
"C:\utils\nircmdc.exe" sendkey pagedown up
"C:\utils\nircmdc.exe" sendkey enter up




Here's what I figured out. There's too much to put here, so, I've put it on a 4-page PDF on my Google Docs:

4 Ways to get to Firefox "Other Bookmarks", from slowest to fastest
The following are 4 macros that I have in Excel 2010.
The first two just use VBA.
The second two use NirCmd.

https://drive.google.com/open?id=1eche0L-qHRWVA_yEh0JiL1k5SNK4HpCt
2811.

Solve : Sort a Phone List by Last Name.?

Answer»

Quote from: Squashman on January 07, 2018, 03:48:34 PM

Can you do a quick TEST with the Powershell code I posted. I think it will be around the same time as Dave's Jsort.

88,800 names
input: sorted Z-A
output: sorted A-Z
GNU sort 0.40 sec
Benham jsort 6.13 sec
Powershell 8.49 sec
Batch method 664.99 sec (11 min 4.99 sec)


Technically this is a Powershell one-iner, but I broke it down to 4 physical lines for readability. If you type this at the Powershell command prompt, just keep typing when the line wraps.

Code: [Select](Get-Content .\PHONE.txt) -replace '(.*?\d{3})\s(.*?)', '$1-$2' |
ConvertFrom-Csv -Delimiter ' ' -Header First,Last,Phone |
Sort-Object Last |
Format-Table * -AutoSize

You can change the path and file name in the first line.


Technically this is a Powershell one-liner. I broke it into 4 physical lines for readability. If you do type this in a Powershell window, type all 4 lines as a single line and just keep typing when the line wraps. The interpreter will understand.

Code: [Select](Get-Content .\phone.txt) -replace '(.*?\d{3})\s(.*?)', '$1-$2' |
ConvertFrom-Csv -Delimiter ' ' -Header First,Last,Phone |
Sort-Object Last |
Format-Table * -AutoSize

The path and file name can be changed as needed.

It did it, but it ECHOED the sorted output to the console.

Powershell has cmdlets for outputting to a file, however in this case redirection might be the simpler way to go.

Code: [Select](Get-Content .\Phone.txt) -replace '(.*?\d{3})\s(.*?)', '$1-$2' |
ConvertFrom-Csv -Delimiter ' ' -Header First,Last,Phone |
Sort-Object Last |
Format-Table * -AutoSize -HideTableHeaders > .\Phone.new

If the preference is to have the headers in the output file, remove the -HideTableHeaders parameter from the Format-Table cmdlet.

Added a timer:

Code: [Select]$t = Measure-Command {
(Get-Content .\Notabs_names-rev-sorted.names.txt) -replace '(.*?\d{3})\s(.*?)', '$1-$2' |
ConvertFrom-Csv -Delimiter ' ' -Header First,Last,Phone |
Sort-Object Last |
Format-Table * -AutoSize > out.txt
}
echo "Time: $t"
Result:

Code: [Select]Time: 00:00:13.2834694
The script is clearly doing more work than just sorting: for example it is justifying the columns (input file: 2.6 MB output file: 7.8 MB)

Python

88,800 names
0.138 seconds!

Code: [Select]python sortfile.py > sorted.txt
2018-01-10 21:24:18.494000
2018-01-10 21:24:18.632000

Code: [Select]from __future__ import print_function
from datetime import datetime
import csv
import operator

tstart = datetime.now()
reader = csv.reader(open("Notabs_names-rev-sorted.names.txt"), delimiter=" ")

for line in sorted(reader, key=operator.itemgetter(1)):
print(" " . join(line))

tend = datetime.now()
print (tstart)
print (tend)Better Python (27)

Code: [Select]from __future__ import print_function
from datetime import datetime
import csv
import operator
tstart = datetime.now()
f = open('output.txt', 'w')
reader = csv.reader(open("input.txt"), delimiter=" ")
for line in sorted(reader, key=operator.itemgetter(1)):
print(" " . join(line), file=f)
f.close()
tend = datetime.now()
print ("Elapsed", tend - tstart, "seconds")
88,800 names, 5 runs:

Code: [Select]Elapsed 0:00:00.172000 seconds
Elapsed 0:00:00.156000 seconds
Elapsed 0:00:00.172000 seconds
Elapsed 0:00:00.157000 seconds
Elapsed 0:00:00.172000 seconds
Here are 88,800 names sorted randomly:



[attachment deleted by admin to conserve SPACE]Here's the other, 88,800 names sorted alphabetically by column (2) in reverse ORDER. I notice that the sorted file compresses better.




[attachment deleted by admin to conserve space]It's quicker to sort the reverse-sorted file than the randomly sorted file.

Code: [Select]reverse 0:00:00.156000 seconds
random 0:00:00.265000 seconds
2812.

Solve : Remove the part of the multiple files?

Answer»

What would the the code to remove the date part of MULTIPLE FILES in a folder and rename in a DOS batch FILE.

Input file WTIN_PEG_SE_abc-en-us_2017-12-20T024722674Z.pdf
Output should be WTIN_PEG_SE_abc-en-us.pdf

This should WORK for multiple files in the folder.


Answered on DosTips.

2813.

Solve : Batch file to autoselect option after 1 minute?

Answer»

Hi all. Many years ago I had a similar question and it was answered. I can't find my old profile or the old post. I have code from another person in the forums and now I want to add a line so that it auto selects "N" after 60 seconds. I remember the command being so easy.

Code: [Select]:choice
set /P C=Are you sure you want to continue[Y/N]?
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice
I have tried the choice.exe but I can't seem to get choice.exe working. Please help.
Code: [Select]choice /C YN /D N /T 6 /M "Are you sure you want to continue?"Thanks for the response, how do i code a response? I press Y or N and the bat file CLOSES. I've put pause in so the batfile should stop. I currently have.

Code: [Select]if /D "y" goto :imhere
if /D "n" goto :imnotherefrom CHOICE /?

Quote

The ERRORLEVEL environment variable is set to the index of the
key that was selected from the set of choices. The first choice
listed returns a value of 1, the second a value of 2, and so on.
If the user presses a key that is not a valid choice, the tool
sounds a warning beep. If tool detects an error CONDITION,
it returns an ERRORLEVEL value of 255. If the user presses
CTRL+BREAK or CTRL+C, the tool returns an ERRORLEVEL value
of 0. When you use ERRORLEVEL parameters in a batch program, list
them in decreasing order.
Quote
if /D
I don't recognise the /D switch for IF.
Quote from: BC_Programmer on January 16, 2018, 11:32:19 AM
from CHOICE /?
Reading is FUN!Quote from: Salmon Trout on January 16, 2018, 12:36:32 PM
I don't recognise the /D switch for IF.

Quote from: Squashman on January 16, 2018, 02:09:02 PM
Reading is FUN!

thanks guys but I think you missing the point. My first post, the code works fine. I don't really want to use choice.exe but if I have to use it then how do i make my bat file work? Squashman gave me a code using choice.exe and it works. Now where do I go from there? I've even tried taking out the top line of my code and inserting squashman's code and using the /I switch but it doesn't work because obviously it can't find c.

There is a way to not use choice.exe and I would prefer that way but if i have to use choice.exe, how do I select a choice so the bat file runs the commands after Y and N?Quote from: BC_Programmer on January 16, 2018, 11:32:19 AM
from CHOICE /?

Of course I haven't forgotten about you. How do I program the bat file to carry on and select y or n? When I press Y or N the bat file closes. Can you show me the code?I finally found the correct solution on google after a long time of searching. Here is my complete bat file. Please note the Error as proposed by bc_programmer.

Code: [Select]@ECHO OFF

:choice
choice /C YN /D N /T 60 /M "Are you sure you want to continue?"
IF errorlevel 2 goto :somewhere_else
IF errorlevel 1 goto :somewhere
pause
goto :choice
2814.

Solve : Batch file to create folder following the name of specific file then move files?

Answer»

save below line as myvbs.vbs
change line 13 to the target folder also
---------------------------------------------------------
Option Explicit
On Error Resume Next
Dim T
dim fs
dim folder
dim files
dim FILE
Dim oFSO
Dim X

Set fs = CreateObject("Scripting.FileSystemObject")
'Directory you WANT sorted
Set folder = fs.GetFolder("c:\myvbs\")

Set files = folder.Files
For Each file in files
If file.name = "myvbs.vbs" Then
rem wscript.echo "oops found myself"
Else
T = Mid(file.name,1,len(file.name) - 4)
MD(T)
Set oFSO = CreateObject ("Scripting.FileSystemObject")
X = folder & "\" & T & "\"
oFSO.MoveFile file.name,X & file.name
End IF
Next

Private Function MD(X)
Dim objFS, objFol
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFol = objFS.CreateFolder(X)
End functionLooks like your code is creating a folder for each file name. Which is not what the user asked. Of the set of three files, there should only be one folder created and the three files moved to that folder. Also, why not just use .GetBaseName(strPath) instead of stripping the extension with -4. MANY file extensions these days are no longer dot 3.it would be more efficient if it didnt try to make a folder each time, but the outcome is the same. good point with getbasename.
i have cleaned it up a little bit and added what you said , also filename is irrelevant now as long as it has a .vbs extension , and it will just run in the folder it is in.
___________________________________

Dim T , fs, folder, files, file ,X , objFol
Set fs = CreateObject("Scripting.FileSystemObject")
Set folder = fs.GetFolder(WScript.ScriptFullName & "\..")
Set files = folder.Files
For Each file in files
If Not file.name = Wscript.ScriptName Then
T = fs.getbasename(file.name)
Set objFol = FS.CreateFolder(T)
X = folder & "\" & T & "\"
FS.MoveFile file.name,X & file.name
End IF
Nextnot even a thankyou for solving this problem after a YEAR Quote from: jakel on January 17, 2018, 05:14:58 AM

not even a thankyou for solving this problem after a year
If you are here for teh th4nxx you are in the wrong place.
2815.

Solve : Date when used as folder name spanning multiple directories?

Answer»

Trying to get my batch to not span to multiple directories and scratching my head as to why its doing this.

When I look at the %date% I get this format:

C:\Users\user1>echo %date%
SUN 01/14/2018

Which I replace / with - at the start of the batch

C:\Users\user1>echo %date:/=-%
Sun 01-14-2018

Here is what I put together so far. And it passes the data to:
C:\test2\sun 01\14\2018\
in which I would like the data to be in a path such as:
C:\test2\sun 01-14-2018\
Initially I thought it was flipping the / to \ to make for the folder creation depth, but even with / replaced with - in %date% its still doing the same thing. This is probably a pretty easy thing to correct but stuck after 45 minutes on this and google isnt a help at this point.

Code: [Select]echo off
cd\.
cd test2
set datefix=%DATE%
set datefix=%DATE:/=-%
cls
@echo. Running Backup
@echo.
@echo.
@echo. Backup ... Creating Folder with todays date
@echo.
for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
mkdir %datestr%
@echo.
@echo. Backup ... Folder Created with todays date
@echo.
@echo. Backup ... XCopying Important Data to new backup location for %date%
@echo.
xcopy c:\test1\*.* "c:\test2\%datestr%\*.*" /s/d/y/h
@echo.
@echo. Backup ... Important Data has been BACKED up
@echo.
pause
On my last attempt at trying to get this to work it breaks %date% and dumps the data directly to C:\test2\ with replacing date with datefix. I assumed in the first batch above that it would keep to the formatting of replacement of / with - but it didnt seem to, so I thought maybe I am overlooking the fact that date in the for loop needs to be replaced with datefix which is taking the identity of %date% but with the / to - replacement in formatting with the batch below that copies data to C:\test2\ but doesnt create the folder with todays date.


Code: [Select]echo off
cd\.
cd test2
set datefix=%DATE%
set datefix=%DATE:/=-%
cls
@echo. Running Backup
@echo.
@echo.
@echo. Backup ... Creating Folder with todays date
@echo.
for /f "tokens=1* delims=" %%a in ('datefix /T') do set datestr=%%a
mkdir %datestr%
@echo.
@echo. Backup ... Folder Created with todays date
@echo.
@echo. Backup ... XCopying Important Data to new backup location for %date%
@echo.
xcopy c:\test1\*.* "c:\test2\%datestr%\*.*" /s/d/y/h
@echo.
@echo. Backup ... Important Data has been backed up
@echo.
pausePlease don't think the comments are meant to be criticisms! In that vein, if you do @echo off at the top of the batch script, you don't need all those @ symbols at the start of lines, and you only need a dot after echo if you are making a newline, although I know some people use them as insurance against certain errors stopping a script.

Hope this works. Note: my locale uses dd/mm/yyyy date format

I have put some informative echoes in.

@echo off
REM do it once at the top

REM commented out for my local testing
REM cd\.
REM cd test2

cls

REM This is what DATE /T produces anyhow
set datefix=%DATE%
echo Date var before: %datefix%

REM You swapped the slashes for hyphens
set datefix=%datefix:/=-%
echo Date var after: %datefix%

echo Running Backup
echo.
echo.
echo Backup ... Creating Folder with todays date
echo.

REM You don't need this
REM You can't magick a variable into a command
REM for /f "tokens=1* delims=" %%a in ('datefix /T') do set datestr=%%a

REM This is today's date with hyphens
echo making folder: %datefix%

REM Remove echo at start when you want to do it for real
echo mkdir %datefix%

echo.
echo Backup ... Folder Created with todays date
echo.
echo Backup ... XCopying Important Data to new backup location for %date%
echo.

REM Remove echo at start when you want to do it for real
echo xcopy c:\test1\*.* "c:\test2\%datefix%\*.*" /s/d/y/h

echo.
echo Backup ... Important Data has been backed up
echo.
pause

a test...

Date var before: 14/01/2018
Date var after: 14-01-2018
Running Backup


Backup ... Creating Folder with todays date

making folder: 14-01-2018
mkdir 14-01-2018

Backup ... Folder Created with todays date

Backup ... XCopying Important Data to new backup location for 14/01/2018

xcopy c:\test1\*.* "c:\test2\14-01-2018\*.*" /s/d/y/h

Backup ... Important Data has been backed up Something I forgot about is that if a file name, folder name or path has any spaces, it needs to be enclosed in double quotes like this
mkdir "%datefix%". So if your date format is like this "Sun 14/01/2018' this might be necessary.
Thanks Salmon!

So all I really needed to do was

set datefix=%date:/=-%

mkdir "%datefix%"


So cool that its that simple. I had quite the mess going on.

I got pointed in wrong direction I guess from this example: https://stackoverflow.com/questions/5485853/how-to-create-a-folder-with-name-as-current-date-in-batch-bat-files

And I should have looked at the comments at the bottom of it. I didnt expect a best answer being flawed.

From the issue I had with it I figured I needed to substitute forward slash for hyphen and then it should work, but that FOR loop was a problem. As well as I got a little creative trying to magic a variable into a command within that to try for force my way to success of trial and error. HIT it with a bigger hammer, when a hammer wasn't needed, but same result because it was incorrect!

It works awesome...

Now to add on to this.

My NEXT step is going to be to add where I compare between a NAS and Last Backup Location and only new files and changed files saved to New Backup by Date Folder location. I might be back here with more questions on that part of it. The way you are getting the date is region dependent. So your script MAY not be portable to other computers.
You could considering getting the date in a format that will always be the same.

Code: [Select]for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"This will always give you the date and time as YYYYMMDDhhmmss.
LocalDateTime=20180115121353.383000-360 Hey Squashman ... Thank you for your addition on this subject. Never played with WMIC and so now doing some research into its abilities and limitations. Pretty cool you can poll the OS for localdatetime and set formatting in batch.

Microsoft is very vague on WMIC but just started looking into it: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/wmic.mspx?mfr=trueYou could call out to Powershell as well to get the date and time in the defined format that you want.Quote from: Squashman on January 15, 2018, 11:14:36 AM

The way you are getting the date is region dependent. So your script may not be portable to other computers.
You could considering getting the date in a format that will always be the same.

Code: [Select]for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"This will always give you the date and time as YYYYMMDDhhmmss.
LocalDateTime=20180115121353.383000-360
Can slice that up

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set wmictime=%%a
echo wmictime is %wmictime%
REM Good ol' column ruler for monospace fonts
REM Batch strings start at 0
REM 1 2
REM 0123456789012345678901234
REM wmictime is 20180118091634.523000+000
set yyyy=%wmictime:~0,4%
set mm=%wmictime:~4,2%
set dd=%wmictime:~6,2%
set hh=%wmictime:~8,2%
set mn=%wmictime:~10,2%
set ss=%wmictime:~12,2%
set mss=%wmictime:~15,3%
set utcoffset=%wmictime:~21,4%
echo yyyy %yyyy%
echo mm %mm%
echo dd %dd%
echo hh %hh%
echo mn %mn%
echo ss %ss%
echo mss %mss%
echo utc %utcoffset%
echo yyyy-mm-dd-hh-mn-ss.ms_utcoffset: %yyyy%-%mm%-%dd%-%hh%-%mn%-%ss%.%mss%_%utcoffset%

Result...

wmictime is 20180118093042.091000+000
yyyy 2018
mm 01
dd 18
hh 09
mn 30
ss 42
mss 091
utc +000
yyyy-mm-dd-hh-mn-ss.ms_utcoffset: 2018-01-18-09-30-42.091_+000
2816.

Solve : Looking for a way to maintain path in this backup method?

Answer»

Stepping back even more...

When you start in with batch scripting, there comes a "lightbulb moment" (it happened to me) when you realize that you don't NEED all those intermediate files.

Instead of this

REM Redirect lines of console output of some_command to a file
some_command > output.txt

then later

for /f "delims=" %%A in (output.txt) do (
PROCESS lines of output.txt
)

You can just do this. You can get FOR /F to process the output of a program or command, by surrounding the command with single quotes:
The spaces between the single quotes and the command are not mandatory; I use them for clarity

for /f "delims=" %%A in ( ' some_command ' ) do (
swallow and process lines of console output of some_command
)

So you can just process the lines of output of your original Xcopy command (the one which generates Files2Copy.txt in your batch (1) )

Thus you could eliminate batch (1) and batch (2) altogether. You can take care of the logging as well with echo >> lines in the loop.



General tip: when FOR processes lines, it ignores and silently skips over any line that starts with a semicolon. (you can change this)
How does this work?

@echo off
cls
setlocal enabledelayedexpansion

set datefix=%date%
set datefix=%datefix:/=-%
set source=c:\test3
set destin=c:\test2\%datefix%

set logdir=c:\test2\%datefix%
if not exist "%logdir%" md "%logdir%"
if exist "%logdir%\files2copy.txt" del "%logdir%\files2copy.txt"

REM Original command to get Xcopy list
REM Compare current data test3 to last backup at test1 and create list of files to write to c:\test2\%date% in batch3
REM xcopy "c:\test3\*.*" "c:\test1\*.*" /s/d/y/h/l>c:\testing\Files2Copy.txt
REM pause

For /f "delims=" %%F in (' xcopy "c:\test3\*.*" "c:\test1\*.*" /s/d/y/h/l ' ) do (
set sfile=%%F

REM Do the logging
echo !sfile! >> "%logdir%\files2copy.txt"

set "dfile=!sfile:%source%=%destin%!"
for /f "delims=" %%A in ("!dfile!") do set destdir=%%~dpA

if exist "!sfile!" (
if not exist "!destdir!" echo Creating directory "!destdir!" & md "!destdir!"
COPY "!sfile!" "!destdir!"
) else (
echo Source file "!sfile!" does not exist!
)
)

REM Write Log of what files were backed up to dated folders at isolated partial archive backup location
REM copy c:\testing\files2copy.txt "c:\test2\%datefix%\*.*"

REM Mirror Complete Source to Complete Local Backup
xcopy c:\test3\*.* c:\test1\*.* /s/d/y/h
pause
Oh cool you combined it all... I will check that out and test it
When I wrote "How does this work?" I meant, "How well does this work", as in "does this single batch below replace the three that you were using before, and duplicate their functionality?"

[UPDATE] I saw your edit.

Quote

[UPDATE] I saw your edit.


As I was half awake the light bulb finally came on after some extensive typing and I looked back and saw that you had combined it all into one. Then had a duh moment and quickly corrected via edit to my shorted response ever here at CH

Took it initially as to "how does this work?" in which I didnt look at the differences in the script where you combined it all, then the lightbulb moment was I better check back at the script and see if thats my last 3rd batch or something you edited because the question is rather odd in the context that I ran with initially. Then I felt dumb that I didnt see that initially and ran with wrong context haha.

Time for more coffee for me

Now testing. It looks correct to me. Nothing stands out as incorrect.Works Perfect! Thank You

Made a minor change to use same path as destin for logdir pointing logdir to %destin% . I was almost going to replace all the %logdir% with %destin% and remove [ set logdir = ] but decided to leave that be in case I ever wanted the path of the logging to go elsewhere [ set logdir=%destin% ] can easily be changed for an alternate path and its easier to read and follow with the naming convention you have vs reuse of %destin% in an area of the script that would make it look odd.

Now to just remove the pause from tail end of it and add it to scheduled task on both computers.

@echo off
cls
setlocal enabledelayedexpansion

set datefix=%date%
set datefix=%datefix:/=-%
set source=z:
set destin=c:\archiveshadowcopy\%datefix%
set logdir=%destin%

if not exist "%logdir%" md "%logdir%"
if exist "%logdir%\files2copy.txt" del "%logdir%\files2copy.txt"

For /f "delims=" %%F in (' xcopy "z:\*.*" "c:\zcopy\*.*" /s/d/y/h/l ' ) do (
set sfile=%%F

REM Do the logging
echo !sfile! >> "%logdir%\files2copy.txt"

set "dfile=!sfile:%source%=%destin%!"
for /f "delims=" %%A in ("!dfile!") do set destdir=%%~dpA

if exist "!sfile!" (
if not exist "!destdir!" echo Creating directory "!destdir!" & md "!destdir!"
copy "!sfile!" "!destdir!"
) else (
echo Source file "!sfile!" does not exist!
)
)

REM Mirror Complete Source to Complete Local Backup
xcopy Z:\*.* c:\zcopy\*.* /s/d/y/h
pause
On the second computer I paid more attention to what was happening and saw that it chokes on the last line from files2copy.txt, but continues chugging along and completes, so I guess to remove that error message I could add the removal of last line from files2copy.txt by using the method I have in the second batch file written into this current batch to write to xfiles2copyx.txt , then run with that file which wouldnt have a line that is invalid to the copy instruction of file count.

When I put together the initial batches for each group of instructions, I expected the batch to fail on hitting the file count. I never tested leaving it in there. So it was interesting that it didnt crash the batch it simply rejected the file count and moved on.

Source file "37 File(s)" does not existI took your lead on where the log should go from this in your batch (3)

REM Write Log of what files were backed up to dated folders at isolated partial archive backup location
copy c:\testing\files2copy.txt "c:\test2\%datefix%\*.*"

... as c:\test2\%datefix% is the same as %destin%, I hard coded it but that meant it persisted after changes you made. Sorry for the confusion.

I have noticed something else... I made it so each time the new all-in-one batch is run, it blanks the log file and starts a new one, so that if you run it more than once on the same date, you will only see the last run's log results, so you might want to remove this line

if exist "%logdir%\files2copy.txt" del "%logdir%\files2copy.txt"

Quote from: DaveLembke on January 19, 2018, 11:34:00 AM
On the second computer I paid more attention to what was happening and saw that it chokes on the last line, but continues chugging along and complete, so I guess to remove that error message I could add the removal of last line and the xfiles2copyx.txt method written, then it runs with that file which wouldnt have a line that is invalid to the copy instruction.

Source file "37 File(s)" does not exist

That's just the error message I coded in to the IF block surrounding the copy operation. It isn't really necessary to show that in the console. See below.

Anyhow, here's an update....


@echo off
cls
setlocal enabledelayedexpansion

set datefix=%date%
set datefix=%datefix:/=-%
set source=z:
set destin=c:\archiveshadowcopy\%datefix%
set logdir=%destin%

if not exist "%logdir%" md "%logdir%"
if exist "%logdir%\files2copy.txt" del "%logdir%\files2copy.txt"

For /f "delims=" %%F in (' xcopy "z:\*.*" "c:\zcopy\*.*" /s/d/y/h/l ' ) do (
set sfile=%%F

REM Do the logging
echo !sfile! >> "%logdir%\files2copy.txt"

set "dfile=!sfile:%source%=%destin%!"
for /f "delims=" %%A in ("!dfile!") do set destdir=%%~dpA

if exist "!sfile!" (
if not exist "!destdir!" echo Creating directory "!destdir!" & md "!destdir!"
copy "!sfile!" "!destdir!"
REM ) else (
REM echo Source file "!sfile!" does not exist!
)
)

REM Mirror Complete Source to Complete Local Backup
xcopy Z:\*.* c:\zcopy\*.* /s/d/y/h
pause


Quote from: DaveLembke on January 19, 2018, 11:34:00 AM
When I put together the initial batches for each group of instructions, I expected the batch to fail on hitting the file count. I never tested leaving it in there. So it was interesting that it didnt crash the batch it simply rejected the file count and moved on.

Source file "37 File(s)" does not exist

That's because if exist "!sfile!" checks if that line corresponds to a real, actual file.(As I mentioned above (U need cofffee!!!)

Time for another coffee break. haha Thank You Did you see this?

I have noticed something else... I made it so each time the new all-in-one batch is run, it blanks the log file and starts a new one, so that if you run it more than once on the same date, you will only see the last run's log results, so you might want to remove this line

if exist "%logdir%\files2copy.txt" del "%logdir%\files2copy.txt"
Thanks.. I only run the backup once a day, but just in case it is run more than once I removed that so it will append to the log file. Decided to make it more user friendly for altering paths, so that the 4 paths just need to be set (Source, Full_Local_Backup, Archive, and Logging ) *In bold are changes made.

Might even set the log file name and make it dynamic below too. Undecided on that.


Quote
@echo off
cls
setlocal enabledelayedexpansion

REM Passes current Date in [ Fri 01-19-2018 ] format to datefix then datefix substitites / for - with :/=-
set datefix=%date%
set datefix=%datefix:/=-%

REM Source Drive that all data backed up comes from
set source=z:

REM Path for full local backup
set Full_Local_Backup=c:\zcopy

REM Destination for Archive Data
set destin=c:\archiveshadowcopy\%datefix%

REM Logging Destination specified after logdir=
set logdir=%destin%

if not exist "%logdir%" md "%logdir%"

For /f "delims=" %%F in (' xcopy "%source%\*.*" "%Full_Local_Backup%\*.*" /s/d/y/h/l ' ) do (
set sfile=%%F

REM Do the logging
echo !sfile! >> "%logdir%\files2copy.txt"

set "dfile=!sfile:%source%=%destin%!"
for /f "delims=" %%A in ("!dfile!") do set destdir=%%~dpA

if exist "!sfile!" (
if not exist "!destdir!" echo Creating directory "!destdir!" & md "!destdir!"
copy "!sfile!" "!destdir!"
REM ) else (
REM echo Source file "!sfile!" does not exist!
)
)

REM Mirror Complete Source to Complete Local Backup
xcopy "%source%\*.*" "%Full_Local_Backup%\*.*" /s/d/y/h
pause
Hello salmon ... I dont need to see message about file count. ((( Update: Just realized when i pulled up this page and selected ALL it somehow showed the last item on page 1. So I thought this was a recent question as seen in pic. Time for more coffee )))

Some updates to this that dont really affect what was created is that I added another location that isnt in a hidden directory and gave the users the ability to have access to a copy of what is archived in c:\archiveshadowcopy at a location of c:\shadowcopyarchive. No one but me knows about the hidden full local backup at c:\zcopy and the archive by date at c:\archiveshadowcopy . I figured I would trust the 12 users to have access to a copy of the archive data which they have been instructed not to use any files here as active documents to build on from until a copy of whatever file they need is moved away from C:\shadowcopyarchive to their workspace on the NAS. I was going to flag all data as read-only, but decided to hold off on that because the users arent skilled enough to flip it back to read/write permissions. So going to see how it goes with read/write enabled archive space.

If they foul up their archive by accidentally deleting something or altering something, I still have the hidden hands off location to get the original data from. The users are very excited that any data saved before 2am is recoverable in the future as for lots of users have lost data before.

The setup is just 2 computers SHARING a low cost NAS for our union here. And because of my skills I was asked to make things better. Data integrity was the first importance to make corrections to. There were users not even using the NAS at times and data stored locally etc, it was a big mess. I set everyone up with their own user accounts and mapped space to their private folders and shared folders on the NAS, and set the default save locations to point to the NAS so that they have to intentionally tell it to save elsewhere.

So the backup solution I have in place is to use the extra space on the workstations in hidden folders to mirror the NAS data, then implement this batch that you helped greatly with to establish an archive that can be navigated by dated folders to have access to older versions of files if need be. Because everyone who has access to the computers is trusted and everyone is aware that their data can be seen by others who have the computer access, having everyones data accessible in one location in the archive where NORMALLY they only see their W: drive as their space isnt an issue. Each user has a folder in the archive that is named for easy identification.

One last final piece to the project will be to set up a google drive and have that mirror to the Z: drive, but it would need to be selective in what if backed up to the cloud as for we have more than 15GB of data. This way if there was ever a fire etc, the most important recent data isnt wiped out.

[attachment deleted by admin to conserve space]
2817.

Solve : Batch file - check if program is running and switch to it?

Answer»

Are there commands to check if a program is already running, and give an external program focus?

Specifically I'm trying to achieve this logic in a batch file?

Code: [Select]If Firefox is running
give Firefox program focus and close this batch file
else
Start firefox, give it focus and close this batch file
Many thanks
Batch files cannot give a Window focus, however they can LAUNCH a program which by default will have focus.

Your OS is undefined, so I can only GUESS that this might work:

Code: [Select]@echo off
tasklist /fi "imagename eq firefox.exe" > nul
if errorlevel 1 start firefox
exit

Hope this helps.

Note: You may have to fix up any paths required.Thanks for your reply, Sidewinder.
I'm WinXP - sorry for not updating during registration!

When I run the tasklist command it in a batch file it doesn't trigger the errorlevel=1 statement. If Firefox is not running, the tasklist command seems to return a 'command cannot be run' style message to NUL and returns 0 as the error code rather than flagging it as an error.

It's been a while since I've done some serious Batch file work, but if I were to send all the output from a tasklist command to a text file, what dos commands could be used to search that file for the text string 'firefox.exe'?
i.e.
Code: [Select]@echo off
tasklist > temp.txt
[open temp.txt and search for 'firefox.exe' text]
If Firefox text not present start Firefox
exit
Answered my own question with the help of http://www.easywindows.com/easydos/edmessages/560.html

Code: [Select]@echo off
set tempfile=bdw.txt

del %tempfile%
tasklist > %tempfile%
type %tempfile% | find /i "firefox.exe"
if errorlevel 0 if not errorlevel 1 goto IsRunning
start firefox

:exit
del %tempfile%
pause
exit

:IsRunning
echo IsRunning
goto exitDid this work? When I run it, it still tries to launch a new session.This works for me to determine whether Nod32kui.exe is running,
and to then take appropriate alternative actions :-

Code: [Select]TASKLIST /NH | FIND /I "Nod32kui"
SET NodLevel=%ERRORLEVEL%
IF %NodLevel%==0 GOTO END_NORMAL
Subsequently one of the alternative actions is
Code: [Select]IF %NodLevel% NEQ 0 START /NORMAL C:\PROGRA~1\ESET\nod32kui.exe /WAITSERVICE

Regards
Alan
Thanks. This seemed to work for me, but what is the command to bring focus or switch to the program?Quote from: bpoz on June 18, 2009, 12:31:49 PM

Thanks. This seemed to work for me, but what is the command to bring focus or switch to the program?
A 3rd PARTY program MIGHT be able to do it, but I doubt it. Batch can't normally do that...
appactivate (or something close to that) in a .wsh file may do it...I found it in the MSDN for SendKeys.instead of doing "c:\blah.exe" ,
you can do "start c:\blah.exe"

Launched from cmd or bat, the first waits for blah.exe to finish/terminate.
The second SAYS to launch blah in a new window and continue what we're doing.Quote from: uniquegeek on March 31, 2011, 09:42:07 AM
instead of doing "c:\blah.exe" ,
you can do "start c:\blah.exe"

You have revived a two year old thread.
i think this can also be a alternative.

@echo off

tasklist /nh /fi "imagename eq notepad.exe" | find /i "notepad.exe"
if errorlevel 0 if not errorlevel 1 goto IsRunning
start /b notepad.exe

:exit
pause
exit

:IsRunning
echo Cannot Have Multiple Interface Process Please Check the...
pause
exitThis thread was last posted to 3 years ago, and it was created 6 years ago. Just sayin' Hello,

I am having a peculiar and specific problem. When I use a batch file to test if, say, "notepad" is working, I use the simple program here:

////////
SETLOCAL EnableExtensions
set EXE=notepad.exe
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND
echo Not running
pause
goto FIN
:FOUND
echo Running
pause
:FIN
////////

And it works, of course. But not if I change the second line to:

set EXE=dbase.exe

This batch file doesn't see that ol' dBase IV is running when it is running. (I still have the program execute notepad because I don't want the trouble of two versions of dBase fighting over files.) Is there something else I should know about this or is there an alternate test out there? Does this have something to do with running a legacy program like Ashton-Tate's dBase IV? (The program works well except when someone tries to run two versions of it at the same time.)

I THANK anyone for their time.Once again...the Thread that will not die...
2818.

Solve : Net Stop service ... question?

Answer»

I am trying to figure out a service name for a TCI VT100 Service so I can NET STOP and NET START it to allow the USERS reset the service through a batch file SHORTCUT on their desktop.

I was wondering if anyone knew of a way to find the service name such as when looking at the print spooler it doesnt tell you that you can execute NET STOP SPOOLER to stop the service and NET START SPOOLER to start the print service back up. When you look at the services Properties you would see that it is pointing at C:\WINDOWS\system32\spoolsv.exe ..... so somewhere the system knows that SPOOLER = spoolsv.exe for the service.

I am trying to find it for TCI VT100 and I tried a bunch of combinations of trial and error on hoping I would find the declaration that will match the service.

So I am here asking if anyone knows of a way to find the actual service name so I can NET STOP and NET START That TCI VT100 service?

THANKS No guarantees, but this little script may help you match up the executable with the service name.

Code: [Select]On Error Resume Next
strComputer = "."

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo ""
WScript.Echo "StartName: " & objItem.StartName
WScript.Echo "PathName: " & objItem.PathName
Next

Save the script with a vbs extension and RUN from the command prompt as CSCRIPT scriptname.vbs

To make it easier to read, you can also redirect the output of cscript to a file.

Good luck.

EDIT: research turned up the service name as the target of a start/stop command.

2819.

Solve : Confused: batch file to kill itself ?!?!?

Answer»

What I'm trying to do is, if an old instance of my batch FILE is currently running, then I would like my batch file to kill it and start a new instance. I can do this in Java, but is this possible using a batch file?

I tried using taskkill or pskill to kill the old process but to no avail!!!!!!!!!
taskkill /IM "cmd.exe"
or
pskill "cmd.exe"

Any comment or suggestion is always appreciated.Could be difficult. With two or more Cmd.exe windows open all RELEVANT processes are named Cmd.exe, how can Taskill determine which one to terminate unless you quote the PID. So Taskkill will terminate all Cmd.exe processes including the CMD.exe which is currently running your batch script..

Worth investigating tho', hope someone comes up with an answer.

I am not sure what you mean. A batch file will kill itself far too easy, without much EFFORT! And why would you want another instance?

Code: [Select]REM this.bat is a batch that kills itself by invoking itself.
THIS.BAT

So, that is not what you meant?My batch file checks if the application is NOT running then starts up my application else it does nothing and also starts a batch menu. When I accidently close one of my applications, I just double click on my batch file and it starts up the application that was close but it also launches another instance of my batch menu. So there's two instance of cmd.exe running.

I know I would be ALOT easier if I had 2 batch files, one to start up all the applications and the other just for a batch menu but where's the challenge and fun in that?

thanks Quote

where's the challenge and fun in that?

Yeah. This type of thing requires all sorts of convolutions to get working in an actual programming language- such as C/C++, involving FIRST determining wether a previous instance exists, getting it's processID, grabbing the top level window of that process, and sending an Application message to it with the command line arguments of the new instance, and then the new instance quits. the old instance processes the message and loads the command line- for example file names. Some would say to just use KillProcess on the old instance. Well that would A: destroy everything changed in the original documents in the first process, and B: possibly leave open handles to files and devices.


Java has it easy since the VM will do all the real work.
2820.

Solve : ultimate noob question: how do you close dos??

Answer»

I was just playing AROUND on the computer and I typed command in the "run..." THING.
so I got the C:\Windows\system32\command.com open
and now I want to close it
but when I do (press the "X" in the corner) I get an END PROGRAM dialog box. Is it bad to close it and press end now?

Is this the correct way to close the programIf you *MADE* The batch file open Cmd, it'll do that. It's fine, just X it.Quote from: BatchRocks on February 07, 2009, 05:43:26 PM

If you *MADE* The batch file open Cmd, it'll do that. It's fine, just X it.

I really don't want to screw this up, so I'm going to be very careful. Here is what I did:

1. CLICKED start
2. Clicked "run"
3. Typed Command. Pressed Enter
4. Played around (typed stuff in), but didn't amount to anything
5. Now I want to get rid of the dang thing, but if I press X I get the end program window

ITS OKAY? I gotta be sure. It isn't my computer.EXIT
2821.

Solve : Copy and start?

Answer»

How do i make a file that is copied to a random place start once it is copied.
eg.
copy (file or wutever) C:\wutever\wutever\wutever\%random%.bat

U CANT tell it to start c:\wutever\wutever\wutever\%random%.bat because it will start a random file.
So what 2 do Why do you want to do this?In case a VIRUS TARGETS my antivirus, it will be restarted at a new random place, and then stop the virus

2822.

Solve : virtual 8086?

Answer»

I asked this recently but I'm afraid I may have worded it wrong. I have an ME system. I don't know what my dos version is. I loaded some early dos shareware, then TRIED to run Ultima7, and got the error message that my system was in virtual 8086 mode, and that I should remove the OFFENDING SOFTWARE. I deleted the dos shareware games and still got the error message. I ALSO get that message to remove expanded memory.

I don't know how to get out of virtual 8086 mode, and I don't know how to remove expanded memory.

Please help.

Thank youYeah, some older games are like that. You can go to the games forum and maybe they can tell you. You will need to create a DOS shortcut and then change it so that uses the computability mode. Or something like that. Thank you.Indeed- Windows uses the "Virtual 8086" mode of PROCESSORS beyond the 386 to create new instances of DOS applications- so that, as far as the application is concerned, it is running in DOS. However- In this case the game will onbly run in Real mode (literally pure DOS) so as Geek said you'll need to change the settings so the computer reboots into DOS mode.

2823.

Solve : trouble with a for loop?

Answer»

Ok, I'm using for loops now. So, here's what I'm doing

Code: [Select]for /f %%c in ('ver') do set the_ver=%%c
echo %the_ver%

Which outputs

Code: [Select]microsoft

Because the value set to THE_VER has spaces. Is it possible to get around this? Or is that
just the way it is is.You need to learn about delimiters ("delims"). The default token delimiter when parsing a line of text is a space or spaces. You can override this by including a delims block in your FOR command.

"delims=" SETS the delimiters to be the start and end of the line which is what you want here.

for /f "delims=" %%c in ('ver') do set the_ver=%%c

There is another way of doing this which involves tokens, but we won't bother about that just now.
You can do FOR /? for the details.

Basically, the default is to break up the output into PARAMETERS on each space or tab. In your example, %%c would be the first parameter, %%d would be the 2nd, %%e the 3rd, etc. This allows more detailed extraction of information for batch scripts. If you want the WHOLE string in one variable, the 2 easiest ways would be to set "delims=" or to set "tokens=*".

So try this:
Code: [Select]for /f "tokens=*" %%c in ('ver') do set the_ver=%%c
echo %the_ver%Sorry for posting behind you, Dias ... there was no reply when I started my reply which took about 20 minutes between dealing with a wild kid and 2 noisy dogs.No PROBLEM, 2 heads are better than one. Thank you . I learned something and I fixed my problem.

2824.

Solve : Open Sys files with Dos?

Answer»

Hello
I have a question
How do you open SYS files (.SYS) in DOS

That's my question.. My English is not very good so I'm writing short topics

Greeettzz LarsYou don't "open" them. They are system files which MS-DOS loads at boot time.
In the days of MS-Dos MSDOS.SYS was a plain text file which could be opened/edited using a plain text editor such as Edit.com or Notepad.exe (Win 9x/ME). If your operating system is an NT variant, forget it, .sys files LOOK like binaries.

So there's no way to start them?Quote from: Larssie111 on February 08, 2009, 06:26:18 AM

So there's no way to start them?

Please explain what you mean by "start".YOU don't start .sys files... YOU don't open system files.... YOU don't edit system files.....that's why they are called "System files".
They are started by the system, often thru a program like Config.sys

Now, if you put a .sys file, like Himem.sys in a config.sys file, which you can create or edit, then the system will run it when it boots (in DOS).

Edit.com in DOS or Notepad in Windows can be used to create or edit a Config.sys file.
But even if you create and/or edit a Config.sys file, YOU don't start it......DOS will start it when it boots up the computer.

I hope that helps!

Shadow

Quote from: THESHADOW on February 08, 2009, 08:12:29 AM
YOU don't start .sys files... YOU don't open system files.... YOU don't edit system files.....that's why they are called "System files".
They are started by the system, often thru a program like Config.sys

Now, if you put a .sys file, like Himem.sys in a config.sys file, which you can create or edit, then the system will run it when it boots (in DOS).

Edit.com in DOS or Notepad in Windows can be used to create or edit a Config.sys file.
But even if you create and/or edit a Config.sys file, YOU don't start it......DOS will start it when it boots up the computer.

I hope that helps!

Shadow



Thanks for backing up what I SAID before, TheShadow. Maybe he'll believe two of us... Quote from: Dusty on February 07, 2009, 07:16:34 PM
In the days of MS-Dos MSDOS.SYS was a plain text file which could be opened/edited using a plain text editor such as Edit.com or Notepad.exe (Win 9x/ME). If your operating system is an NT variant, forget it, .sys files look like binaries.

That was true exclusively for the DOS versions provided in Windows 95,98, and ME.

DOS VERSION prior to that were binary code...


But they are quite right- device drivers are loaded by DOS at boot time.


2825.

Solve : Dos=??

Answer»

guys whats the first thing to do if u wanna be an EXPERT in computers?? learning programming? i was thinking Turbo C. its really hard to understand Dos commands if u aren't familiar with the Terms. Being "an expert in computers" is pretty vague. I think you should start off by picking an area of expertise in computers and CONCENTRATE on that.
Quote from: Flux on February 08, 2009, 08:03:03 PM

its really hard to understand Dos commands if u aren't familiar with the Terms.
I think it is hard to understand almost anything until you become familiar with it. Turbo C is also really hard to understand if you aren't familiar with the terms (in my opinion much harder than DOS, since there are only about 150 commands (even taking into account the extended set of internal and external commands in CMD), where there are several hundred functions in Turbo C (and learning how to pass pointers to variables between functions in Turbo C usually requires a lot of practice).

So pick a topic to start from (maybe Turbo C, or "DOS" commands, or STORAGE, or memory, or computer SECURITY, etc.) and expand from there.Quote
its really hard to understand Dos commands if u aren't familiar with the Terms. Huh

It's really hard to win (or finish) races when they put the finishing line so *censored* far away from the start! I so agree with GuruGary. Start out small and build from there. You could argue that there is no such thing as an expert in "computers". You can be big in programming, or hardware, or OS, or whatever, or (more likely) some sub topic, maybe, after going to college and putting in lots of effort, but I don't think anybody knows everything about everything. Find out what you like best, what you're good at, most important: find out where to find out what you need to know, and stick at it!

Good luck.

I know a guy who is an absolute whiz at hardware design, he is a top guy in a particular field in chip layout and has been headhunted by major companies, and he can't write batch files or bash scripts to save his life! He's good at Ruby though.
2826.

Solve : Dos newbie?

Answer»

*Smack head*
didnt know you could get it on Microsofts website. Quote from: macdad- on February 02, 2009, 04:09:27 PM

*Smack head*
didnt know you could get it on Microsofts website.

http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=endang thats got a lot of tools
and they are all command line?Quote from: macdad- on February 03, 2009, 12:41:22 PM
dang thats got a lot of tools
and they are all command line?

Many of them are.

awesome, gotta download this.
and thanks for the link Quote from: Dusty on February 01, 2009, 11:09:49 PM
Flux - Welcome to the CH forums.

Get used to it - you cannot access Dos in Win XP, Win XP is not built on Dos. What you can use is a Windows program named Cmd.exe which is a Dos emulator and runs in a window so to CALL it Dos is a misnomer. You can, however, run things like DosBox.

Here is a list of NT commands for use at the XP Command Line or in scripts. Some are available only in XP Pro, others must be extracted from the Resource Kit.

Good luck.
dude thanks for the link. i really appreciate your HELP. im sure these would do.Quote from: macdad- on February 02, 2009, 06:27:04 AM
PING -n 1 -w 1000 1.1.1.1 >nul

can be used as a wait command, or just to ping a computer or server on your network.

the 1000 is the timeout, that makes PING a excellent wait command.
and the 1000, is in milliseconds so that would make PING wait for 1 sec.

It is actually a very bad practice to ping an IP address that you don't administer or have control over. Besides not being polite (depending on how it is used and how often it could be considered a denial of service attach which I know is not your intent), it is not reliable. For example, I assume by your example that your are expecting 1.1.1.1 to not respond to your ping (ICMP echo request). If the owner of that IP decides to one day enable ICMP echo for that IP address, then your command above would only pause for a few milliseconds. It is much better to ping something that you have control over, such as localhost, or 127.0.0.1. You can use
Code: [Select]ping -n 2 localhost >NULto pause for about 1 second (the number should be n+1 where n is the number of seconds to pause because the 1st reply should be INSTANT, and the others will wait 1 second by default).

I hope nobody takes offense to this ... just trying to point out a better way.
good point
2827.

Solve : how to use "choice" command in Win XP?

Answer»

i have learnt that i cannot use CHOICE COMMAND in batch file in XP COMPUTER. And if i want to use how can i modify ? PLZ, help me.the CHOICE.EXE prog your using, is it the NT version?
or were did you download it?Anything useful here? :
http://hp.vector.co.jp/authors/VA007219/dkclonesup/choice.html

2828.

Solve : How to convert short paths to long paths??

Answer»

Does anyone know of a way to convert short PATHS to long paths?
if I issue the dos command Code: [Select]ftype FirefoxHTMLMy output is:Code: [Select]FirefoxHTML=C:\PROGRA~1\MOZILL~1\FIREFOX.EXE -requestPending -osint -url "%1" But why? The short path is valid.I really need the long path for a java program I'm working on.There is a function in Windows for that. But if you tack it into java you will have code that can not port across platforms. Which is one reason for musing java.

Maybe the quick fix is to shell out to DOS and use a VB script to convert the files names. There is a function in VB script for this. I think.Quote from: Geek-9pm on February 05, 2009, 11:33:03 PM

There is a function in Windows for that. But if you tack it into java you will have code that can not port across platforms. Which is one reason for musing java.

Maybe the quick fix is to shell out to DOS and use a VB script to convert the files names. There is a function in VB script for this. I think.

Code: [Select]@echo off
@echo set oArgs = Wscript.Arguments>"%TEMP%\LongFileName.vbs"
@echo wscript.echo LongName(oArgs(0))>>"%TEMP%\LongFileName.vbs"
@echo Function LongName(strFName)>>"%TEMP%\LongFileName.vbs"
@echo Const ScFSO = "Scripting.FileSystemObject">>"%TEMP%\LongFileName.vbs"
@echo Const WScSh = "WScript.Shell">>"%TEMP%\LongFileName.vbs"
@echo. With WScript.CreateObject(WScSh).CreateShortcut("dummy.lnk")>>"%TEMP%\LongFileName.vbs"
@echo. .TargetPath = CreateObject(ScFSO).GetFile(strFName)>>"%TEMP%\LongFileName.vbs"
@echo. LongName = .TargetPath>>"%TEMP%\LongFileName.vbs"
@echo. End With>>"%TEMP%\LongFileName.vbs"
@echo End Function>>"%TEMP%\LongFileName.vbs"

set sfn=C:\PROGRA~1\MOZILL~2\firefox.exe

for /f "Tokens=*" %%a in ( ' cscript //nologo "%TEMP%\LongFileName.vbs" %sfn% ' ) do set LFN=%%a

echo %lfn%

WOW!
This looks really hopeful.
I wish I understood it or how to use it.
I copied it and put it into a batch file and ran it but it flashed by so fast I could not see any output.
Remember I am a new B.
N.OK I looked into my \Local Settings\Temp folder and found LongFileName.vbs.
Which looks like this:
Code: [Select]set oArgs = Wscript.Arguments
wscript.echo LongName(oArgs(0))
Function LongName(strFName)
Const ScFSO = "Scripting.FileSystemObject"
Const WScSh = "WScript.Shell"
With WScript.CreateObject(WScSh).CreateShortcut("dummy.lnk")
.TargetPath = CreateObject(ScFSO).GetFile(strFName)
LongName = .TargetPath
End With
End Function
Then I copied and pasted into a HTML file like this:
Code: [Select]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>shortToLong</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<script language="VBScript" type="text/vbscript">
set oArgs = Wscript.Arguments
wscript.echo LongName(oArgs(0))
Function LongName(strFName)
Const ScFSO = "Scripting.FileSystemObject"
Const WScSh = "WScript.Shell"
With WScript.CreateObject(WScSh).CreateShortcut("dummy.lnk")
.TargetPath = CreateObject(ScFSO).GetFile(strFName)
LongName = .TargetPath
End With
End Function
</script>
</body>
</html>When I try to view in a browser I get an error (No Surprise since I don't really know what I'm doing)
I've attached a screen shot of my error.
Thanks for your help.


[attachment deleted by admin]Well I figured it out. It works!! I'm so happy.
Thank You Dias de verano!
In the command line I type:
Code: [Select]cscript LongFileName.vbs "C:/PROGRA~1/MOZILL~1\firefox.exe>vb.txtAnd sure enough the vb.txt file is written with
Code: [Select]Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Program Files\Mozilla Firefox\firefox.exe
If there was some way to suppress the writing of the first TWO lines that would be nice but not necessary.
Again Thank You!


Quote from: nubia on February 06, 2009, 10:21:36 PM
If there was some way to suppress the writing of the first two lines that would be nice but not necessary.

Incidentally, you don't need that SINGLE quote mark before the short filename.

To run a VBscript with cscript.exe, without those 2 lines, you can add the //Nologo switch after the cscript command thus:

cscript //Nologo LongFileName.vbs C:/PROGRA~1/MOZILL~1\firefox.exe>vb.txt

Alternatively, you can beforehand get cscript.exe to save the //Nologo option by doing this:

cscript //Nologo //S

Afterwards, when you run any script with cscript.exe, on the same COMPUTER system, the //Nologo option is default and need not be included in the command. However this has the disadvantage that if the command is used on another system the option may or may not have been thus saved, and therefore the output of the script is unpredictable. So you should always include the //Nologo switch when supplying the script and command to other people (or explain all of the above, whichever seems appropriate!)

To restore the default behaviour to cscript.exe:

cscript //Logo //S

Use either switch to force the desired behaviour when running a script.

Although I have used capital letters N and L in the switches, they are not case sensitive.

type cscript /? at the prompt to see full details of options.

Code: [Select]C:\>cscript //nologo //S
Command line options are saved.

C:\>cscript //logo //S
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Command line options are saved.

C:\>cscript //nologo //S
Command line options are saved.Again Thank You -You have been more than helpful.
I really appreciate the time and effort you have taken to help me.
Nubia.
2829.

Solve : Dir command in For loop?

Answer»

Win XP Home.

I have two files with identical names on two physical hard drives, partitions C: and E:, the Dir outputs are shown below:

Quote

Volume in drive C is MASTER
Volume Serial Number is 2fd1-ab4e
Directory of c:\

Mon 01/26/2009 13:45 2,811 dates.bat
1 File(s) 2,811 bytes


Quote
Volume in drive E is SLAVE
Volume Serial Number is f68d-1e3a

Directory of e:\

Fri 12/05/2008 12:54 1,374 dates.bat
1 File(s) 1,374 bytes


When I run the following script 2811 is returned not, as I expected, 1374. Can someone please explain why the Dir command in the For loop is not picking up drive E: and defaulting to C:?

Quote
@echo off
cls

for /f %%A in ('dir/b e:\dates.bat') do (

echo %%~zA
)

I don't want a workaround, I can do that USING CD or Pushd, just an explanation of why Dir is not opting for partition E:. Dir/b e:\dates.bat at the Command Prompt works perfectly.

Thanks.

V.



My guess is that you are running the batch file from the directory that the 2811 byte file is in. I think the issue is that DIR /B will probably return just the filename instead of the entire path without the /S. And your parameters are not following the syntax for the DIR command (I don't think that is an issue in this case, but I would clean it up anyway). To verify my theory, try this:

Code: [Select]@echo off
cls

for /f %%A in ('dir e:\dates.bat /b') do (
echo FULLPATH=%%~fA
echo Size=%%~zA
)
You said you don't need a work-around, which is good - because the only thing I can think of would be to add a /S to the dir command which could add a significant amount of time to the script because it would search your entire E: drive for files named "dates.bat".Thanks for that GuruGary.

Quote
My guess is that you are running the batch file from the directory that the 2811 byte file is in.
You are correct, the batch script is located in C: which is the default directory.

Your script returned Quote
Fullpath=C:\dates.bat
Size=2811

I just don't understand why dir is defaulting to C: when E: is the target partition.

I'm just going to throw this out there and see if it sticks. Use the set command to see if a dircmd variable exists. Generally USED for default switches, it may have a value that is interfering with your execution of the dir command.

Quote from: ValerieMay on February 09, 2009, 01:26:56 AM
I just don't understand why dir is defaulting to C: when E: is the target partition.

Because using DIR with /B and without the /S the output is just "dates.bat" (without a path). So if a file with the same name happens to be in the current directory, then it uses that file. To see what I am talking about, make one more modification to your FOR loop:
Code: [Select]for /f %%A in ('dir e:\dates.bat /b') do (
echo Full path to file returned by DIR=%%A
echo Fullpath=%%~fA
echo Size=%%~zA
)You can then compare that to using the /S on the DIR command like
Code: [Select]for /f %%A in ('dir e:\dates.bat /b /S') do (
echo Full path to file returned by DIR=%%A
echo Fullpath=%%~fA
echo Size=%%~zA
)My guess is that the 2nd script will work the way you expect, but take longer to finish.
Code: [Select]for /f %%A in ('dir e:\dates.bat /b') do (
echo Full path to file returned by DIR=%%A
echo Fullpath=%%~fA
echo Size=%%~zA
)Returned Quote
Full path to file returned by DIR=dates.bat
Fullpath=C:\dates.bat
Size=2811

Code: [Select]for /f %%A in ('dir e:\dates.bat /b /S') do (
echo Full path to file returned by DIR=%%A
echo Fullpath=%%~fA
echo Size=%%~zA
)Returned Quote
Full path to file returned by DIR=e:\dates.bat
Fullpath=e:\dates.bat
Size=1374

Exactly as you predicted the latter TOOK a while.

I'm still at a loss to understand why Dir will not access the targetted drive without the /S switch.

Thanks for your interest.




Sidewinder - thank you. My Dircmd is set to /OG/ON/P but removing these switches made no difference, my script still defaulted to C:.

Quote from: ValerieMay on February 09, 2009, 01:15:13 PM
I'm still at a loss to understand why Dir will not access the targetted drive without the /S switch.
There are 2 separate tasks involved.
1) The DIR command is returning a file
2) The command interpreter uses the file returned by DIR to give you the size

If you look at the 2 outputs from your last run, you can see that the the first one says
Quote
Full path to file returned by DIR=dates.bat

And the second one (that used the /S) says
Quote
Full path to file returned by DIR=e:\dates.bat

So in the first example all the command interpreter has to go by is just a file name without a path. If a file that matches the request is in the current directory then it returns that INFORMATION (file size).

It is basically the difference of doing:
Code: [Select]for %a in (dates.bat) do echo %~za(which will return the size of dates.bat in whatever the current directory happens to be) and
Code: [Select]for %a in (E:\dates.bat) do echo %~zawhich will return the size of dates.bat in the specified path.

Does that help?Yes, somewhat, though I must admit the fog has not completely cleared. I now realise that /F and the Dir command were not required at all.

Thank you for your time and patience.

V..
2830.

Solve : How to execute batch file in sched time unnoticable/invisibly??

Answer»

Is there a way to Run the batch file with out popping-up the COMMAND PROMPT window?

it will just run on the system tray in a scheduled time? so it will not visible or distractable while running?

Thanks! Why?Yes

But wouldnt you want to be notified that a scheduled task was running ?Why does everybody want there batch files to run in the background?QUOTE from: Carbon Dudeoxide on February 10, 2009, 04:26:25 AM

Why?

Quote from: BatchFileCommand on February 10, 2009, 06:04:52 AM
Why does everybody want there batch files to run in the background?

Because my batch file will execute for about a minute.
it will be destructive to the user if it runs for about a minute... He/she may CANCEL the batch file.

anyway, i have alternative command

Start /minWhat is this supposed to do?

Quote
it will be destructive to the user if it runs for about a minute
You mean, in a minute, the computer will be....destroyed?Quote from: Carbon Dudeoxide on February 10, 2009, 06:28:42 AM
What is this supposed to do?

Quote
it will be destructive to the user if it runs for about a minute
You mean, in a minute, the computer will be....destroyed?

I'm hoping he meant "it will be disruptive to the user" and not "it will be destructive to the user"!Quote from: GuruGary on February 10, 2009, 06:33:47 AM
Quote from: Carbon Dudeoxide on February 10, 2009, 06:28:42 AM
What is this supposed to do?

Quote
it will be destructive to the user if it runs for about a minute
You mean, in a minute, the computer will be....destroyed?

I'm hoping he meant "it will be disruptive to the user" and not "it will be destructive to the user"!


Thanks for correction...

Still, what does it do?
2831.

Solve : trim beginning digits,symbols and space off filename?

Answer»

Hi there,

I saw a video tutorial introducing batch file a while back and it kind of piqued my interest, so here I am

I have some mp3 files that BEGIN with 01, 02, dashes and so on. Is there a command to:

1. list the files that are not BEGINNING with an alphabet
2. rename without those characters

otherwise, a line to trim the first digit would be fine.

Thanks in advance.
Quote from: mjncheers on February 09, 2009, 12:10:30 PM

otherwise, a line to trim the first digit would be fine.

Since trimming the 1st character is pretty easy, I'll give you an example on how to do that. The other can be done, but with batch the only ways I can think of to do it would take many more lines of code. Have you considered a file renaming program? My favorite is BRU or Bulk Rename Utility at http://www.bulkrenameutility.co.uk/

Anyway, here is some code. The way it is here, it will work on the current directory and all subdirectories. If you only want only the current directory, take out the /S. If there is already a file with the same name, it will probably give an error for that file and keep going. I have it ECHO the results so you can see what it will do instead of actually renaming. Bulk renaming can be dangerous, so be sure it is doing what you want it to do, and / or have a backup!
Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('dir *.mp3 /a-d /b') do (
set CurrentFile=%%a
echo ren "%%a" "!CurrentFile:~1!"
)

If you only want to trim the 1st character if it is a digit, you will have to add some code to check for a digit ... something like replacing your REN line with
Code: [Select]set FirstChar=!CurrentFile:~1,1!
if !FirstChar! GEQ 0 if !FirstChar! LEQ 9 echo ren "%%a" "!CurrentFile:~1!"
You could do something similar to check for files that don't begin with a-z or A-Z (IF NOT statement)

Hope that helps.
I do not like that bulk rename utility. It's hard to use. It's complicated. A batch file that size could sweep the computer from head to toe. It doesn't have a very well designed interface, but it doesn't take too long to get used to.I was going to use it to rename some of my NES ROMs, but then I realized that there are goodtools for that and NSRT for SNES... so I've yet to find a reason to use it.


Not sure what you mean:
Quote from: BatchFileCommand on February 09, 2009, 07:14:08 PM
A batch file that size could sweep the computer from head to toe.

that's why he's got it set to echo the renaming behaviour rather then actually do it.Quote from: BC_Programmer on February 09, 2009, 08:21:10 PM
Not sure what you mean:
Quote from: BatchFileCommand on February 09, 2009, 07:14:08 PM
A batch file that size could sweep the computer from head to toe.

that's why he's got it set to echo the renaming behaviour rather then actually do it.



That program is like 500 kb. Not saying that it's to big for the computer. But if you had a batch file that was 500KB it could sweep the whole computer and rename tons of files.Hey, thanks guys for your help and replies.

I haven't really got that far yet...As I'm an absolute beginner, I guess it'll take me a great while to figure out and learn from your codes. But great thanks anyways, it makes a good goalpost

P.S. yes, I use a RENAMER. I picked that up from a previous FAQ post here.

Great forum anyways, keep up the good work here!

Quote from: BatchFileCommand on February 10, 2009, 06:14:34 AM
Quote from: BC_Programmer on February 09, 2009, 08:21:10 PM
Not sure what you mean:
Quote from: BatchFileCommand on February 09, 2009, 07:14:08 PM
A batch file that size could sweep the computer from head to toe.

that's why he's got it set to echo the renaming behaviour rather then actually do it.



That program is like 500 kb. Not saying that it's to big for the computer. But if you had a batch file that was 500kb it could sweep the whole computer and rename tons of files.

The rename function in ExplorerXP is excellent, not too complicated but very powerful.

Doesnt work in vista though
2832.

Solve : Problem with variables?

Answer»

Okay. I'm making a simple alarm batch file. Then for the TIME, I want to extract the seconds from the %time% variable. Let me show you what I mean

6 : 5 2 : 4 8 . 5 2
1 2 3 4 5 6 7 8 9 10

So to get those I WOULD do this

Code: [Select]echo %time:~6,7 %


But it's giving me 6,7,8, and 9. COULD anyone explain how to fix this?

It sounds like you want
Code: [Select]echo %time:~6,2%In %VAR:~x,y%
x is the offset to start with
y is the length

It sounds like your understanding may have been that x,y was the RANGE to return, which is not QUITE correct.Okay, so is there a way to get only numbers 6 and 7Quote from: GuruGary on February 10, 2009, 06:29:39 AM

It sounds like you want
Code: [Select]echo %time:~6,2%
2833.

Solve : Using command prompt to disable hardware????

Answer»

Is there a way to disable HARDWARE connected through (COM & LPT) port using a batch file?For what purpose are you going to use this for?I am using an application to acquires heartbeat data between two machines. I am trying to start and stop it at a certain time, but it's not working. It would stop the process but not the driver. So I am just curious if it's POSSIBLE to disable the hardware.wow! and i was just asking since it SOUNDED like a viruses for a second.
but you can do this, you will just need this. from microsoft.

Hope this HELPS
,Nick(macdad-)

I will give that a try. Thank you Nick Anytime

2834.

Solve : DOS based POS application?

Answer»

We have a DOS based application RUNNING under windows 98. The author has long since retired. The program has been running on the same machine for years. In order to upgrade the hardware is it resonable to clone the old drive and instal in a new machine? Could one expect the application to run as before or would new hardware result in errors?
ThanksWelcome to the CH forums.

If you were considering upgrading the Operating SYSTEM as well there might be a problem with port access. If the intention is to continue using W.98 ensure that drivers are available for the new hardware.

It is not acceptable to simply clone a system drive and install it in new hardware, the system and updates must be installed in the new hardware. User programs must also be installed.Thanks DustyAnother option is Virtualization ... we have a piece of software that is used in accounting that is too pricey to replace for a small food store, yet it will only run on 95 or 98 and pukes on NT. We are using VIRTUAL PC 2007 to run a Virtual Windows 98 OS. The replacement software package is like 10 grand, and Virtual PC 2007 has been free to download and use from Microsoft for a while now.

I was able to use Norton Ghost to create an image of the Windows 98 Pentium II 350Mhz system and then install the image to the Virtual PC 2007 as a Win98 environment with 64MB Ram. And its completes so much faster in the virtual environment and shared CPU CORE with Pentium 4 - 3.2 Ghz.

Also a friend of mine had to do the same thing at his company for an old app that he went with VMware which also has a FREE package now, and VMware will take a snapshot without having to use Ghost etc to clone and you can virtualize that way. Just not sure is that was for 98 or not...Might have been for an app that had to run in another os environment.Neat workaround, especially with imaging an existing Win98 machine. Didn't it have problems with the percieved hardware changes though?

Also, it seems silly that a software company that sells an expensive program (especially at that PRICE ) wouldn't allow for free, or at least reduced cost upgrade to a version that works with the preferred OS.

2835.

Solve : Create list of entryes not in file?

Answer»

Hi'

I have created a list trough ADFIND. The list is all accounts from active directory, witch are not disable and have the password NEVER expires set.

The file (all.txt) is formatted like this:

Code: [SELECT] user1
user2
user3

Some of the users is allright, so I have another file that contains all accounts that is approved.
That file (approved.txt) is formatted like this:
Code: [Select]user2
user5

Now I need one file. The file should be a result, that contains all accounts listen in all.txt but not LISTED in approved.txt.

I think i need a combination of FOR and FIND /V command, but I'm stuck.



I don't know if it can be done using FOR and FIND, but here is a VBScript file which may be of use.
Paste the code below into a file with a .vbs extension and run it from the command prompt.

Code: [Select]Option Explicit
Dim oFso, iCase, inFile, strFile1, strFile2, strContent, arAll, arApproved, strOut, i, J, outFile, strOutFile, iFlag

Const ForReading = 1
Const ForWriting = 2

Set oFso = CreateObject( "Scripting.FileSystemObject" )

'**************** MAKE CHANGES BELOW AS REQUIRED ****************
' If case sensitivity matters, change this to 1
iCase = 0

' Full path to the file containing all the users names
strFile1 = "c:\all.txt"

' Full path to the file containing all the approved users names
strFile2 = "c:\approved.txt"

' Full path to the file which will contain the users who are not on the approved list
strOutFile = "c:\notapproved.txt"
'**************** MAKE CHANGES ABOVE AS REQUIRED ****************

Set inFile = oFso.OpenTextFile( strFile1, ForReading )
strContent = inFile.ReadAll
inFile.Close
If iCase Then
arAll = Split( strContent, vbCRLF )
Else
arAll = Split( LCase( strContent ), vbCRLF )
End If


Set inFile = oFso.OpenTextFile( strFile2, ForReading )
strContent = inFile.ReadAll
inFile.Close
If iCase Then
arApproved = Split( strContent, vbCRLF )
Else
arApproved = Split( LCase( strContent ), vbCRLF )
End If

strOut = ""
For i = 0 To UBound( arAll )
iFlag = 1
For j = 0 To UBound( arApproved )
If arAll( i ) = arApproved( j ) Then
iFlag = 0
Exit For
End If
Next
If iFlag Then
strOut = strOut & arAll( i ) & vbCRLF
End If
Next

If strOut <&GT; "" Then
Set outFile = oFso.CreateTextFile( strOutFile, True )
outFile.Write( strOut )
outFile.Close
End If
THX!! That works

2836.

Solve : Navigating a Windows Program via CMD Batch??

Answer»

My first post on your boards, but I've spent the past few days making this site and forum my bible for Batching

There's one thing I've not been able to find, however, and that is;

Am I able to navigate a windows program with a GUI via CMD batch files?

I'm attempting to make a batch file that will;

1) Run Fraps, change the "Destination" path for saving captured footage to a folder with the date, for example. Doesn't have to be, all I want is a new subdirectory automatically created so I don't "forget" and save new footage with old footage
2) Run Ventrilo, connect to a server, and automatically join the channel I want
3) Run World of Warcraft


The idea is that while I'm logging into WoW and loading, the batch file will do all the Ventrilo and Fraps tedium for me quietly in the background.

Is this possible?

I've made the script to run each of those programs seperately, or all in sequence (via "CHOICE.COM") calling multiple batch files, however, I just can't figure out how to emulate actions within a program through the batch.

Could ANYONE tell me if this is possible? Or if not, does anyone know of a link to a compendium of the ASCII codes for emulating keystrokes in CMD with "StuffIt"? That would absolve the need for me to use CMD for that STEP... the program was just written in 1991 so there isn't a lot of documentation floating around anymore.


Thank you in advance if anyone can help with this. I am extremely new to Batch scripting so I don't actually know everything that is possible through Batch files.

I can post my script when I get off work if it would make anyones lives easier.Batch files are probably not what you want for what you are trying to do in #1 and #2. You can probably use VBS with SENDKEYS to do what you are looking for, but not being familiar with any of the programs you listed, I can't really help.

Can you provide more details on what you want? For example, what is the full path to the file that runs Fraps, and what keys do you press (without using the mouse) to change the destination path? And similar details on the other 2 tasks.VBS doesn't have sendkeys.Code: [Select] Syntax
Visual Basic (Declaration)
PUBLIC Class SendKeys

Visual Basic (Usage)
Dim instance As SendKeys

C#
public class SendKeys

Visual C++
public ref class SendKeys


Quote from: GuruGary on February 11, 2009, 09:01:58 AM

Batch files are probably not what you want for what you are trying to do in #1 and #2. You can probably use VBS with SENDKEYS to do what you are looking for, but not being familiar with any of the programs you listed, I can't really help.

Can you provide more details on what you want? For example, what is the full path to the file that runs Fraps, and what keys do you press (without using the mouse) to change the destination path? And similar details on the other 2 tasks.

Full path to the file that runs Fraps..

C:\Fraps I just used
Code: [Select]cd/
cd fraps
START fraps.exe

The keystrokes to use to navigate Fraps' menu I haven't tried yet, however, for Ventrilo.. which is
C:\Program Files\Ventrilo
Code: [Select]cd/
cd "program files\ventrilo"
START ventrilo.exe
I would need to hit O (For Connect) and then Tab 9 times, Down Arrow once and Return once to join the desired channel. The StuffIt code for Tab, Down Arrow and Enter is listed, but not O.. and I don't know where to find that so I was kinda stuck there.

For World of Warcraft it's simple, since I have a "run" shortcut already made for it. I just;
Code: [Select]START wow
But the path is C:\Users\Public\Games\World of Warcraft\

If I have to use VB and SendKeys I guess I'll do that, I just didn't want to go through all the extra stuff involved there.. compiling, a GUI, etc. I just wanted a quick batch job heh.

Thanks a lot.Quote
I just wanted a quick batch job heh.

Wait! Don't go away mad!

Look at this:
http://www.download.com/Quick-Macros/3000-2084_4-10254443.html?tag=mncol

This is but one of a number of "Keyboard Macro" programs where you define keystrokes, save it in a file, and later can invoke it as a shortcut.
After a bit of reading, you can do this faster that writing something with Visual Basic. But not as much fun. Somebody else did all the work!

Quote from: Geek-9pm on February 11, 2009, 09:25:51 AM
Code: [Select] Syntax
Visual Basic (Declaration)
Public Class SendKeys

Visual Basic (Usage)
Dim instance As SendKeys

C#
public class SendKeys

Visual C++
public ref class SendKeys




First - Visual Basic is NOT VBScript. I tested to make sure sendkeys didn't exist before posting.

Secondly - that's .NET, which is even further from the roots of VBScript, which originally branched off Visual Basic 5 (and was updated to include the VB6 Functions InstrRev,Split,Join, and so forth later on). (Some may say that it branched off from VBA, but on the other hand VBA was integrated into Visual Basic at version 4)
And Of course... Visual Basic 5 or 6 aren't easy to find OR free.

Also sendkeys is busted in the .NET framework. One would need to use the SendInput() APIs instead.Quote from: BC_Programmer on February 11, 2009, 10:31:44 AM
First - Visual Basic is NOT VBScript. I tested to make sure sendkeys didn't exist before posting.
I am almost certain that I have used SENDKEYS in VBS before. It's possible that it was VB, but I am pretty sure it was VBS. I'll try to get in front of that computer and look through my scripts.SENDKEYS does work in VBS. Try this as a VBS:

Code: [Select]set WshShell = CreateObject("WScript.Shell")
WshShell.Run "notepad.exe"
WScript.Sleep 1000
WshShell.AppActivate "Notepad"
WScript.Sleep 200
WshShell.SendKeys "This should put some text in a notepad document"
WScript.Sleep 200
WshShell.SendKeys "%F"
WScript.Sleep 200
WshShell.SendKeys "A"
WScript.Sleep 200
WshShell.SendKeys "C:\VBS_SendkeysTest.txt"
WScript.Sleep 200
WshShell.SendKeys "%S"
It should start NOTEPAD, enter some text (using SENDKEYS), and then use SENDKEYS to open the File menu -> Save As -> C:\VBS_SendkeysTest.txt and [Alt-S] to save.
Quote from: pheNom on February 11, 2009, 10:09:31 AM
I would need to hit O (For Connect) and then Tab 9 times, Down Arrow once and Return once to join the desired channel.
In VBS, I think you could do something like:
Code: [Select]set WshShell = CreateObject("WScript.Shell")
WshShell.Run "program files\ventrilo\ventrilo.exe"
WScript.Sleep 1000
WshShell.SendKeys "O"
WScript.Sleep 200
WshShell.SendKeys "{TAB 9}{DOWN}{ENTER}"technically VBScript doesn't have sendkeys- the windows scripting host does- so Javascript,PERL, etc can all use the same sendkeys Appactivate, etc.

in pure VB it's a statement- same with appactivate, as well as a few other statements...- this is what I was referring to.

Additionally I was confused as to where Geek9pm found a class called sendkeys, given it's actually a method of the WSH...

Quote
Additionally I was confused as to where Geek9pm found a class called sendkeys, given it's actually a method of the WSH...

Sorry about my confusing post.
It is in the .NET framework class library.Thank you all very much.

I'm at work right now so I can't test out that macro program you linked, Geek, but I can't wait to get home and mess around with it.

Looks like it'll do everything I need it to, AND everything the original batch was already doing. Hah. Easymode

...but since I love code I'm gonna spend the rest of my day at work with SendKeys in VBS. See what I can do with that.

God, I love working in IT. Nobody can give you a hard time if your screens are filled with scripts and coding that they don't understand! ...until a printer breaks, or one of their cables gets unplugged. *sigh* -_-

Love these boards btw. Fastest replies, with actual relevant information, I've ever seen.

Quote from: Geek-9pm on February 11, 2009, 12:02:22 PM
Quote
Additionally I was confused as to where Geek9pm found a class called sendkeys, given it's actually a method of the WSH...

Sorry about my confusing post.
It is in the .NET framework class library.

No worries An entire class devoted to sending keys... intriguing...

Assume whenever I say Visual Basic and forget to say which kind, that I mean 6
2837.

Solve : Installing Dos 6.22?

Answer»

Quote

like... like... like...
YES? he didnt cause we were installing XP to laptops.Jesus, three pages already?

SQUALL, no.

Topic CLOSED.
2838.

Solve : Batch file - using AD group membership?

Answer»

Guys

I'm pretty new at creating batch files so excuse me if this is a simple question.

Basically I want to create a login script (suing a batch file) that maps peoples network drives and printers. All pretty simple so far. Where i run into trouble is that I want to be able to map different drives depending upon which ACTIVE directory group user is in. So if we have a finance director then only people in the AD group finance have that drive mapped etc. obviously some people will be members of multiple groups.

Here's what I have so far.


@echo off

:Begin
CLS

REM Deletes all existing drive mappings
net USE f: /delete
net use g: /delete
net use h: /delete
net use i: /delete
net use J: /delete
net use k: /delete
net use l: /delete
net use m: /delete
net use n: /delete
net use o: /delete
net use p: /delete
net use q: /delete
net use r: /delete
net use s: /delete
net use t: /delete
net use u: /delete
net use v: /delete
net use w: /delete
net use x: /delete
net use y: /delete
net use z: /delete



REM connect to home drive & Reception Printer
net use i: \\fileserver\home\%USERNAME%
rundll32 printui.dll,PrintUIEntry /in /n \\printserver\reception


IF Group ==Dev GOTO Dev
IF Group ==Technical_services GOTO Tech_serv
IF Group ==LONDON GOTO London
IF Group ==Ney_york GOTO New_york
IF Group ==Singapore GOTO Sing
IF Group ==VIP_Manager GOTO VIP
IF Group ==PTG GOTO PTG
If GROUP ==Finance GOTO Finance
if GROUP == HR GOTO HR


GOTO END



:Dev
rundll32 printui.dll,PrintUIEntry /in /n \\printserver\dev
net use r: \\fileserver\dub
GOTO END




:Tech_serv
rundll32 printui.dll,PrintUIEntry /in /n \\printserver\tech
net use r: \\fileserver\dub
net use z: \\fileserver\apps
GOTO END



:London
REM rundll32 printui.dll,PrintUIEntry /in /n \\printserver\eng
net use r: \\fileserver\london
GOTO END


:New_york
net use r: \\fileserver\ney_york
GOTO END


:Sing
net use r: \\fileserver\sing
GOTO END


:VIP
net use v: \\fileserver\vip
GOTO END

:PTG
rundll32 printui.dll,PrintUIEntry /in /n \\printserver\ptg
net use p: \\fileserver\ptg
net use r: \\fileserver\dub
GOTO END



:Finance
rundll32 printui.dll,PrintUIEntry /in /n \\printserver\finance
net use f: \\fileserver\finance
GOTO END


:HR
rundll32 printui.dll,PrintUIEntry /in /n \\printserver\hr
net use h: \\fileserver\HR
GOTO END




:END


Looks like London will have a printer issue because of the remark (rem) statement ....did you purposely add the REM or is this a typo that is fowling it up at

:London
REM rundll32 printui.dll,PrintUIEntry /in /n \\printserver\eng
net use r: \\fileserver\london
GOTO END

2839.

Solve : BATCH saving files to specific locations?

Answer»

I am a complete novice with batch files. This is what I want to do:

save 3 files to 3 LOCATIONS for 60 users:

1. Normal.dotm to REPLACE users existing Normal.dotm in C:\Documents and Settings\\Application Data\Microsoft\Templates
2. Save a new *.dotx Word 2007 quick style file to: C:\Documents and Settings\\Application Data\Microsoft\QuickStyles
3. Save\overwrite *.qat file to: C:\Documents and Settings\\Local Settings\Application Data\Microsoft\Office

any help woul be cool
many thanks Why do you want to do this?

These files are normally not touched, but are targets for an older style macro virusIf you have 60 users it would be easier to set up a roaming profile then have all them stored on C: of each PC... unless you have one PC with 60 users which is simply wrong.I assume the 60 users log into a DOMAIN controller that has a login script? And in #3, I assume "save/overwrite" means "do not back up"?

Assuming that is the case, you can add something like this to the login script:
Code: [Select]xcopy "path\to\new\Normal.dotm" "C:\Documents and Settings\%username%\Application Data\Microsoft\Templates\" /Y
xcopy "path\to\new\*.dotx" "C:\Documents and Settings\%username%\Application Data\Microsoft\QuickStyles\" /Y
xcopy "path\to\new\*.qat" "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Office\" /Y
If you NEED to be SURE it only runs once, then you could add an IF EXIST statement to check for a file to see if it has been run already.

2840.

Solve : dual boot, dos 6.22 and XP?

Answer»

First, can I dual boot between dos 6.22 and XP?
If yes, just how? I have a new job and they use Dos, I have XP on my computer. I still have my old Dos 6.22 disks to install with.

IF not, just what is the best way to do it with WIN98se. I have that on a old computer.

Thanks!!You asked the question barbecue you are not sure about this. Right?
OK. The best answer for you is to take a very conservative approach, Xp does not like it when some other OS overwrites the Master Boot Record. Unless it is Vista, which has a way of dealing with this.
So, to protect your XP install ans to save time, go find a good small HDD that you can install in your Desktop as a secondary drive. Your BIOS has some way to boot from the secondary drive.

Of course thee are other wasy to do what you want.
This is the more conservative.

If you have a laptop, we have to take another approach.thanks for the reply. Barbecue??
Conservative if fine.
Okay, I can pull the hard drive off the other old computer I have.
Do I install 6.22 after the small hard drive in install in my XP computer
or
Do I install it first on the drive then install the drive on the computer?
Will dos know to ask me to install on the new D:\ drive?
How do I switch back and forth?
thanks again.You can get a boot manager to help you. A good boot manager will let you choose for operating systems on other drives, other partitions, and often even multiple operating systems on the same partition, and you can USUALLY install the operating systems in any order. This WOULD let you keep your existing XP drive / partition and add DOS to it.

The way I have done it (which I think is the official Microsoft way) is to start off with the older OS, which would be DOS in your case. Then boot to the Windows XP CD and tell it to install. When the XP setup is complete, it should give you a boot menu that will allow you to choose between Windows XP and "Previous operating system" (or something like that). Doing it that way, you can:
1) install on the same partition as DOS (which will have to be a 2GB or less FAT C: drive), or
2) install on a different partition that you can make whatever size and file system you want ... but it won't be drive LETTER C: which I have seen cause issues in some older applications.Quote

How do I switch back and forth?

You can use a boot manager. but some can ruin your present system.
Geneally, you can learn how you BIOS works in five minuetes or less. How the boot managerwokrs can take days. For me it has taken months and months and finally discovered I don't need it, just do it in the BIOS.
Get into your BIOS. Somewhere there is a way to change the boot order. You can boot off the second IDE or the second drive. I have a Intel board mad a few years ago and have no problem getting it to boot off the second drive. Most Dell computers and ASUS mother boards have that feature. In fact, I can not think of a BIOS that does not have that feature. Except a laptop..
I suppose you have the old PATA (IDE) drives. You can not do DOS on a SATA unless it is in emulation mode.

For DOS, you can just install it on the other computer. It does not care. Some 20 mega byres is lots for DOS. Win 98 about 500 is good.
For endows 98, you would disable the main hard drive in the BIOS settings.
For Windows 98 will install on what it sees as the first hard drive. Or whatever drive has a FAT32 partition.

Yes what the other post said is true. You can not retro install Windows versions. A Windows 98 or DOS install onto the main drive will mess up the XP MBR, NT boot sector and NTLDR. So you would install on another drive, with the main drive removed or disable or mapped by the BIOS to be the virtual second drive.
(Windows allows BIOS remapping, Linux does not. And trying to dual boot with Linux is something I have never liked. Too much HASSLE.)

If this is not clear, ask questions. After you put the second drive in, look in the BIOS. It should find it ans somewhere give you the option of making it the boot drive. Or you disable the first IDE channel and it gos for the other channel. If the BIOS can not find a valid boot sector on any HDD, it gives some error message. Unless it boots first from the CD or floppy.


2841.

Solve : Assigning the output of a command to a variable in a batch file?

Answer»

Hi,

I am creating a batch file which uses the OSQL utility to execute a stored procedure. I would like to pass a parameter to the stored procedure. The parameter should be populated with the output from an xml document.

I am EXPLAINING this with an example:

set /P xmltext = :: contents of abcd.xml

and then execute the OSQL like this:

OSQL -S server_name -E -d database_name -w 500 -h-1 -n -Q "exec Usp_ReadXml %xmltext%" -o targetfile.txt

to COPY the contents of abcd.xml to xmltext I have tried different ways like;

type abcd.xml > %xmltext% etc.

I would like to know if this is possible and if yes how?

Any help would be greatly appreciated...

I also tried using this statement:


For /F "tokens=* " %%A in ('type abcd.xml') Do Set MyVar=%%A

its reading by tokens...which is what i donot want...I want the bulk of the xml contents inside the variable at once........

any help would be greatly appreciatedBummer. Maybe line returns can not be in a variable string.The line RETURN signifies the end of inputIs there any way for me to capture the entire xml content into a single variable?How big is your XML file? There might be a work-around to what you want to do, but environment space is very limited. I think it is maybe 64k, and there is probably 2k used with typical Windows stuff. Also, what OS are you running? Assuming Windows XP, I think the max command line length is 8192 chars, and previous versions of windows are like 2048. So the command plus the variable would have to be less than that.

Have you looked into alternatives, like importing your XML file into your database directly?I am doing all this because I donot have permissions to use OPENROWSET function.

My task is to open the xml file and read its contents into a table variable and generate an insert script.

the OS i am using is windows XP.

The size of the xml file varies, however at this point of time it is 6MB.

I am using OSQL to call a stored procedure from a batch file and want to pass the contents of the xml as a parameter.

If you could think of a better way of accomplishing this task please do suggest.If you can accomplish your task with the OPENROWSET function, then talk to the database admin to get permissions to do that by using a login instead of a trusted connection.

Can your stored procedure take a path to an XML file instead of file data?Hi,

I could not be GRANTED permission to use OPENROWSET, I can definitely modify the SP to take a path instead of file contents, however I need to use the OPENROWSET to open and read the contents of the file isnt it???...or is there any other METHOD you would suggest.....

2842.

Solve : Write to file with echo and use \n?

Answer»

Hi i'm wondering if there is way to append text to some file going to the next line.
For exampe if my text file is text.txt and contains the line this is an example using echo this is another example>>text.txt the results is in the file text.txt is:

this is a examplethis is another example while i would like to have

this is an example
this is another example

Thank youCode: [Select]echo.>>test.txt That will append a BLANK line onto test.txt

FB
Using only one ">" WITHIN the @echo command will either create a new "test.txt file" if one does not already exist or over write the contents of the "test.txt" file should one already exist.

@echo This will create a file with new contents > test.txt

Using two ">>" within thin the @echo command will append this line to the EXISTING "test.txt" file.

@echo This will append this line to the END of the file >> test.txt

2843.

Solve : Directory Command?

Answer»

Hello

I am USING a simple batch command to list all the directories on a drive in a TEXT file.

dir /b > list.txt

what i ALSO NEED is the size all the directories.

thank youdir /s > list.txt
Thanks but the /s switch give me more info then i need, each sub DIRECTORY and all files in the directories, all i need is the main directory and a total directory size.

IE

(size) (directory) (not printed)
7,031,293 bytes A0164
936,382 bytes A0165dir C:\ > list.txt

or

dir C:\ /s > list.txt

2844.

Solve : Starting all files/exes in a directory??

Answer»

Hi All - FIRST post here. Trying to put together a batch file to make life a little easier.

I'd like to make a batch file open all files and programs within a single folder on a mapped network drive. These files and programs will change constantly, so I can't tell DOS the file names.
For example, I've got a folder on c:\ called "test". Inside of test I've got a url "digg.url" link and a shortcut to filemaker pro "fmp.lnk". I want them to both open when I run "test.bat"
I'm trying to use wildcards to make this happen. I thought it would be fairly straightforward.

So far, I've got:

cd c:\test
start *.*

I get "windows cannot find file *.*".

I'm not experienced in dos - I can navigate and run a command here and there.

Help is much appreciated.
Maybe something like this?

Code: [Select]@Echo Off
CD /D C:\Test
Dir /B > C:\Content.txt
For /F "tokens=*" %%i In (C:\Content.txt) DO Start "" /WAIT %%i
You can also do it without creating a content file (and without waiting) like this:
Code: [Select]cd "C:\test"
for /f "tokens=*" %%a in ('dir /a-d /b') do start "" "%%a"this will work in pure DOS:

Code: [Select]cd C:\test
for %%P in (*.exe) do start %%P
Thanks for your suggestions. I'll give these a shot and update later.We have a Winner! (Almost).

So I plugged in my original test values using a local drive. Worked perfectly.
I then plugged in my actual working values - instead of
cd "C:\test"

I put it to

cd "Z:\test"

Z being a shared drive on the domain that is mapped to the local machine.

When I do that, the batch file DEFAULTS to the directory where the batch file is stored, and opens everything in that directory (including the batch file itself, which opens everything + itself, which creates a loop that ends up opening dozens of windows worth of the same thing).

I have verified that I am connected and authenticated to the mapped drive.

In the end, this .bat is only functional if it is ABLE to GRAB its items from a mapped network drive.

Any ideas? I feel like I'm on the cusp of success.\

Thanks in advance.

Quote from: GuruGary on February 11, 2009, 08:55:24 AM

You can also do it without creating a content file (and without waiting) like this:
Code: [Select]cd "C:\test"
for /f "tokens=*" %%a in ('dir /a-d /b') do start "" "%%a"

If you are changing drive letters you need the /D switch on the CD (or manually change the drive letter). So try this instead:
Code: [Select]cd /D "C:\test"
for /f "tokens=*" %%a in ('dir /a-d /b') do start "" "%%a"It works perfectly.

+3 internets, and the right to name my firstborn.

Thanks!!
"Sparky".....

2845.

Solve : net start basic -- start unattended?

Answer»

I am using a netboot CD, and am trying to get it to RUN unattended.

When I run the line "net start basic", it prompts me to confirm my username/password then asks if I want to create a password list (the responses would be {enter}{enter}{n}{enter}). I would like to run this part without user-entries.

I have tried "net start basic /yes" and that does not work.

What does work is "net logon {username} {password} /yes", but this service takes up to much memory and prohibits other services from loading later down the line.

Anybody know how to automate the {enter}{enter}{n}{enter} keystrokes, or how to suppress the prompt?

Thanks,
-darrylYou can redirect input from a file.

Create a file called response.txt with the response that you want ({enter}{enter}{n}{enter}) ... and maybe but an extra [Enter] at the end. So the file should look like:
Code: [Select]

n


If this file is in the same directory as your batch file, then you should be able to do net Code: [Select]start basic <response.txtThis is exactly what I was looking for, but unfortunately it doesn't quite work for me.

When I apply your solution, the computer hangs at the password prompt. It seems to pass the username part, but when username comes up it fails.

Why might this be?Not sure why it isn't working. Maybe try adding an extra [Enter] in the file? Or try taking one away?I've done that. Could it be an issue with memory? Does this kind of input require a significant amount of memory? I'm RUNNING VERY tight on memory usage, there's very little to spare.

Is there any other way to do this?The redirection is going to use very little memory.

Some other suggestions would be to try the NET LOGON, but since you said that uses too much memory, maybe try to address the other memory issues? Or see if the NET START will take some sort of .INI or other config file that you can store the username and password in. For EXAMPLE, I think I remember being to have a uername= and password= in the SYSTEM.INI file that was read by the NET command in DOS 6. I think the documentation is with the LANMAN stuff that USED to come with Windows NT.Thanks for your help Guru... The system.ini is a good place to look, I guess I'll just tweak and browse until I find a solution. I'll post when I do.

Thanks again.Found it! The CHANGE in system.ini in the [network] portion. Add the line

preferredredir=basic
autostart=basic


Then "net logon" works without using so much memory.

Thanks!You're welcome!

2846.

Solve : Xcopy command Invalid parameter?

Answer»

Hi,
I'm new at USING DOS and doing Xcopy.

at the c:\> prompt I typed

xcopy /s/y "C:\documents and settings" "D:\documents and settings"

The response I get is
Invald paramreter
-"C:\documents

Thanks for the help.helpAt the command prompt.
First, make sure both directors exist.
Log onto the D: drive and CD to the directory
Go back to C: and CD to the directory

XCOPY /s /y C: D:

Does that help any?


Quote from: ubcome on February 05, 2009, 08:49:42 PM

Hi,
I'm new at using DOS and doing Xcopy.

at the c:\> prompt I typed

xcopy /s/y "C:\documents and settings" "D:\documents and settings"

The response I get is
Invald paramreter
-"C:\documents

Thanks for the help.
In Xcopy, the switches go at the end of the command line, like this:

Xcopy "C:\junk\*.*" "D:\junk\" /s /y

That line will copy everything in the junk folder in C: to a junk folder in drive D:.
You MUST first make the "junk" folder on D: for this to work properly.

Does that make sense?

Every day, I back up my entire "My Documents" folder (and several others) to a like folder on drive D:

The way I have it written, the first time I ran the batch file, it backed up the entire directory, but the next time I ran it, it backed up only new files and files that had been updated or changed.
Now I run it in my shutdown batch file and it backs up just a few files and takes only a few SECONDS to run.

Here's the text of that shutdown batch file:

@ECHO off
cls
xcopy "C:\Documents and Settings\Alex\My Documents\*.*" "D:\My Documents\" /s /y /H /R /D

Rem Back up my WordPerfect files.
xcopy "C:\MyFiles\*.*" "D:\MyFiles\" /s /y /H /R /D

Rem Back up all the files for My Web Page.
xcopy "C:\My web page\*.*" "D:\My web page\" /s /y /H /R /D

Rem Back up my email folders and address book.
xcopy "C:\Documents and Settings\Alex\Local Settings\Application Data\Identities\{CC1A6FC7-0D07-4169-865D-56EBDD76EB8B}\Microsoft\Outlook Express\*.dbx" "D:\MyEmailFiles-Backup\" /s /y /H /R /D
xcopy "C:\Documents and Settings\Alex\My Documents\My Address Books\*.*" "D:\My Address Books" /s /y /H /R /D

Rem When the backup is done...Shutdown!

%windir%\System32\shutdown.exe -s -t 00 -f

In your example, you will be copying all the files in those folders, over and over again.
That's pointless and very time consuming.
I suggest that you add more switches like I've done, to copy only new or changed files.

Just a suggestion,
Shadow That's good stuff, Shadow.

You might want to make a menu to select what kind of backup
you want. All of my documents, only new and changed, or other options.

Thanks.
2847.

Solve : Sending Files Using DOS via Internet?

Answer»

Is it possible to send files using only DOS to other computers via Internet?Which version of DOS?
Why do you need to do this? (There may be another way to do it.)
Are both computers connected to a router?
Do you know how to use a direct cable connections?
This is a connection that will use a port thet DOS knows about. It can be the SERIAL port or the printer port.
DOS that is INSTALLED in Windows XP. There's no direct cable connection only internet. I was thinking if the command "net send" can send any file to other computer via internet.Quote

here's no direct cable connection only internet
Simple answer is no.

Long answers start here.

You can use P2P programs to do this. P2P means Peer to Peer. That requires both users to agree on a service that they will both use.
The program runs in Windows and does not require a DOS command.

Personally, I do not recommend the use of P2P. You can have other issues. Like more people wanting to get in on your file sharing and sum you have people you never knew wanting to have some of the material.

The other way is to get an password protected FTP account you can both share. Ask nice and somebody here will give you a free one.

The best alternative is to establish a your own VPN.
Never mind. Very long story.

If this is new to you, go for the SHARED FTP account. Slow, but it works

But If you are sharing just videos and photos, go to Photobucket. No brainier.
A free FTP host is hfmwebs.co.cc . It's main page is in another language (LAST time I CHECKED), but its pretty easy to find the register button, and the words you need to know to register are similar to English.
2848.

Solve : copy problem?

Answer»

i guys i want MAKE ONE batch file that first find eny kind of file like .txt of .pdf form all computer DIRECTORS and COPY file that find in result in my pen drive...........

i don't now the other's computer dir so pls how i can do this job.........? from command line??

pls help meis this for stealing data?
This is screaming plagerism and theft...NEITHER are good.

2849.

Solve : DOS copy syntax?

Answer»

It's ages since I needed to use DOS, and I'm afraid I'm a bit rusty - hope someone can help.

I have a list of files that I want to copy from ONE directory to another (about 6000 of them) - format is 003as.txt 003dhei.txt etc.

The source directory contains other files I don't wish to copy, so wildcards won't do the job, but according to copy/? 'source' is the file or files you wish to copy. I'm sure I'm missing something fairly simple here, but after hours of searching, I can't find an EXAMPLE of the syntax to copy multiple (specified) files from one directory to another.

I've tried this:
copy 003as.txt 003dhei.txt ..\otherdirectory
and all sorts of permutations with quotes, commas, etc. to no avail. I'm planning to use the list I have to BUILD a simple batch file containing that command.

Any assistance greatly appreciated.What do you call simple?
A 100 line program you can do in TWENTY minutes ?
Or a 3 line program you can get done in two days?
in the directory you are working with do this
DIR *.*
That gives everything.Now do
DIR *.* >list.txt
Now edit the file'list.txt with notepad or whatever.
Put a @ at the start of every line.
The replace every @ with 'copy ' (not the quotes, but include a space.)
Now put a %1 at the end of every line. Leav a space.
While you are doing that, delete the files you do not want copied.
You will have something like this:

copy mylov.mp3 %1
copy mylove.db %1
copy myhouse.wav %1
copy myhorse.jpg %1

save the the file as 'list.bat'

The do this
list \mybackup

the files will be copied to the \mybackup directory

You can down that maybe faster that I could.
And yes, there is some other neat cool ways to do that, but you can take days to get it right.
Your choice.



a for loop could be used to iterate each line of OUTPUT from a dir /b:

Quote

@echo off

for /f "tokens=*" %%i in ('dir /b %1') do xcopy %%i %3 /EXCLUDE:%2

place this is a batch file- and call as follows:

batfile.bat

Hope this works for you. remember to back up important data before running this, I wouldn't want to be responsible for the loss of anything important. Thanks Guys,

I used your solution, Geek-9pm - did just what I wanted. I'm still confused as to why DOS help on the copy command suggests that multiple named files can be copied at once, when this doesn't appear to be the case.

Thanks again.I believe when it says "file(s)" it means using wildcard characters- the only other option via multiple files is copying via file1+file2, which concatenates files together.
2850.

Solve : How to: Write Console output to *.txt file?

Answer»

Thanks:
I want to Write Console OUTPUT to *.txt FILE .
In other words write every thing that shows in a cmd.exe window to a *.txt file.
Thanks!Have a look at this:

Code: [Select]echo hello >>"C:\file.txt"When you say console it can mean the keyboard or the output. But you can not get all of the DISPLAY, just the output of a command or standard program.
Like dir *.txt /b >list
creates a file NAMED 'list' that has all the NAMES of the files in the directory
but no other information.
ver > whoru
writes the version info in a file named 'whoru'.

Sorry, I don't know.