1.

Solve : creating file from computer name?

Answer»

If someone can help me with this.
I have my laptops marked with HP at the end so I need a BATCH which will check computername like JOHN01-HP
and if it finds HP in the computer name it will make a file like laptop.txt, I will use that file for some backups.
and that file will be stored at user folder Documents
I have many users so I can't do this for just one.

Thank you.Just looking at some of your PREVIOUS threads, you should have the knowledge to do this already.
You basically have two options.
1) Use the SET command to read the last two characters of the computer name. Then use an IF command to see if the last two characters are equal to HP.
2) Use the FOR /F command and the hyphen as a delimiter to split the computer name into two tokens.  Then use an IF command to see if the 2nd token is equal to HP.Ok I will try, to see if it will works.OK I did it
Code: [Select]echo.>>%computername%.txt  Quote from: Blisk on October 29, 2014, 07:17:54 AM

OK I did it
Code: [Select]echo.>>%computername%.txt 
How does this solve your problem?  You said you needed to check if the computer name has HP in the name.This batch makes file with computername like mike10-HP.txt
and second batch search for file with *-HP.txt if batch found that file than it makes backup, if not, than doesn't.This is another method which should work:

Code: [Select]echo %computername%|findstr /e /i "-HP" >nul && (goto :backup) || (goto :FINISH)

and this:

Code: [Select]if /i "%computername:~-3%"=="-HP" (goto :backup) else (goto :finish)thank you, tihis one is better I will use it Quote from: Blisk on October 29, 2014, 08:42:15 AM
This batch makes file with computername like mike10-HP.txt
and second batch search for file with *-HP.txt if batch found that file than it makes backup, if not, than doesn't.
Ugh! I guess you didn't bother to even research my ideas or even LOOK at all your old threads to accomplish this task. Quote from: Squashman on October 29, 2014, 01:51:33 PM
Ugh! I guess you didn't bother to even research my ideas or even look at all your old threads to accomplish this task.

No it is not that way, I have alot of work to do, so I don't have time now to sarch and learn how to do it so I found quickest way which worked.
Quote from: Blisk on October 30, 2014, 01:34:26 AM
No it is not that way, I have alot of work to do, so I don't have time now to sarch and learn how to do it so I found quickest way which worked.
You are preaching to the choir, but that doesn't keep me from learning new scripting techniques every day.  People will only want to give you the FISH so many times. Eventually you have to learn to FISH!unofrtunally everyone can't be fisherman, so thats why you have fish I have BREAD, you give me a fish I give you a bread!
The basics I know but in reality what I do with fev lines or 2 batch files you can do with one line, because you have experiences.
My work field is windows system and desktop, I use batch files just to make my job easier and I am not a programmer.I never saw you give him bread... Quote from: Blisk on October 30, 2014, 08:14:32 AM
unofrtunally everyone can't be fisherman, so thats why you have fish I have bread, you give me a fish I give you a bread!
The basics I know but in reality what I do with fev lines or 2 batch files you can do with one line, because you have experiences.
My work field is windows system and desktop, I use batch files just to make my job easier and I am not a programmer.
Most Network System Administrators and Desktop Support people are not programmers but are at least required to know some kind of scripting language to automate tasks.  I went to school 15 years ago and learning Batch on Windows and BASH on Unix was a requirement for my Network Administration degree.

So it has nothing to do with being a programmer.yes you are right, what can I say.


Discussion

No Comment Found