Script only by computer name...
Moderator: DosItHelp
Script only by computer name...
Hi,
How to run command in script only if computer name start with XXX ?
like XXX01 / XXX02 / XXX03
Thanks, Gil.
How to run command in script only if computer name start with XXX ?
like XXX01 / XXX02 / XXX03
Thanks, Gil.
Re: Script only by computer name...
There you can insert a command.@echo off
if "%computername:~0,3%"=="XXX" echo Run a command
Saso
Re: Script only by computer name...
What is ~0,3% for?
what ~ for?
0,3 for?
also do I need to write at the end of line "Run a command"???
Thanks
what ~ for?
0,3 for?
also do I need to write at the end of line "Run a command"???
Thanks
Re: Script only by computer name...
Execute SET /? or have a look at the command index.
If you want to execute a command if the comparison matches then you certainly should write this command instead.
Steffen
Re: Script only by computer name...
If you would give us information what you want we could give you a complete solution: for example: "I want to start abc.exe if computer name starts with XXX..."
Saso
Saso
Re: Script only by computer name...
Did this:
---------
IF /i %computername:~0,6%%== mokedm
(Do...)
ELSE IF /i %computername:~0,5%%== moked
(Do...)
-------------
Not working
what's wrong here?
Thanks, GIl
---------
IF /i %computername:~0,6%%== mokedm
(Do...)
ELSE IF /i %computername:~0,5%%== moked
(Do...)
-------------
Not working
what's wrong here?
Thanks, GIl
Re: Script only by computer name...
I see you didn't even come close to reading the help file for the IF command.
Code: Select all
The ELSE clause must occur on the same line as the command after the IF. For
example:
IF /i %computername:~0,6%==mokedm (
echo yes
) ELSE (
echo no
)
Re: Script only by computer name...
howto?
IF /i %computername:~0,6%==mokedm (
echo yes
) ELSE (
echo no
)
how to do it with.. ELSE IF?
IF /i %computername:~0,6%==mokedm (
echo yes
) ELSE (
echo no
)
how to do it with.. ELSE IF?
Re: Script only by computer name...
I don't understand your question. Just use ELSE IF
Steffen
Code: Select all
if /i "%computername:~0,6%"=="mokedm" (
echo yes
) else if /i "%computername:~0,5%"=="abcde" (
echo yes
) else (
echo no
)
Re: Script only by computer name...
I wrote this:
but pc name is MOKED01
this is not runs the command in the if statemant
howto fix it?
Thanks
Code: Select all
IF /i
"%computername:~0,5%"=="MOKED"(
but pc name is MOKED01
this is not runs the command in the if statemant
howto fix it?
Thanks
Last edited by Squashman on 20 Feb 2018 10:27, edited 1 time in total.
Reason: MOD EDIT: PLEASE USE CODE TAGS.
Reason: MOD EDIT: PLEASE USE CODE TAGS.
Re: Script only by computer name...
Going forward please use CODE tags in your responses.
Has any example we have given you shown you that you can put the IF command on its own line and the comparison on a separate line?
Re: Script only by computer name...
How to do it that will work?
Batch File script - by computer name
Hi,
Did this:
---------
@echo off
IF /I %COMPUTERNAME:~0,3%==PCM
(Do THIS1)
ELSE IF /i %computername:~0,3%== "PCS
(DO THIS2)
ELSE IF /i %computername:~0,2%%= "PC"
(DO THIS3)
--------------
got 3 pcs:
1 = PCM01
2= PCS01
3 = PC01
when run script on 1 - it need to do = "DO THIS1"
when run script on 2 - it need to do = "DO THIS2"
when run script on 3 - it need to do = "DO THIS3"
BUT NOTHING Happends
What I'm doing wrong?
Thanks, Gil
Did this:
---------
@echo off
IF /I %COMPUTERNAME:~0,3%==PCM
(Do THIS1)
ELSE IF /i %computername:~0,3%== "PCS
(DO THIS2)
ELSE IF /i %computername:~0,2%%= "PC"
(DO THIS3)
--------------
got 3 pcs:
1 = PCM01
2= PCS01
3 = PC01
when run script on 1 - it need to do = "DO THIS1"
when run script on 2 - it need to do = "DO THIS2"
when run script on 3 - it need to do = "DO THIS3"
BUT NOTHING Happends
What I'm doing wrong?
Thanks, Gil
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Batch File script - by computer name
Well, if it looks exactly like that, it's because your parentheses are in the wrong place. You also need parentheses on both sides of the == operator, and there were a few other typos that were breaking things.
Code: Select all
@echo off
IF /I "%COMPUTERNAME:~0,3%"=="PCM" (
Do THIS1
) ELSE IF /i "%computername:~0,3%"=="PCS" (
DO THIS2
) ELSE IF /i "%computername:~0,2%"=="PC"(
DO THIS3
)