Jump to content

Recommended Posts

Posted

Bur I am unsure of the syntax.

I need to do the following, pickup the computer name, if it is a specific computer that I am looking for then run a regkey silently.

I need to do this for 32 pc's labs.

is this right?

if /I "%computername%"=="2F16-01" (regedit /s myreg.reg)

else (if /I "%computername%"=="2F16-02") (regedit /s myreg2.reg)


Posted (edited)

IF you have a standard format for computer names, like:

2F16-01

2F16-02

....

2F16-32

Something like this may be more appropriate:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET Prefix=2F16-
FOR /L %%A IN (1,1,32) DO (
IF %%A leq 9 (SET Num=0%%A) ELSE (SET Num=%%A)
ECHO !Num!
IF /I "%computername%"=="%Prefix%!Num!" ECHO regedit /s myreg!Num!.reg
)

Just an example, it will just print on the screen numbers and if the computer name matches the regedit command line.

jaclaz

Edited by jaclaz
Posted

Here's another example for testing, it has been included because the jaclaz version will not actually expand the variables to the console for viewing.

@ECHO OFF & SETLOCAL
SET "Prefix=2F16-"
FOR /L %%A IN (1,1,32) DO CALL :SUB 10%%A
ENDLOCAL & GOTO :EOF

:SUB
SET "Num=%1"
ECHO ON
ECHO=IF /I "%COMPUTERNAME%"=="%Prefix%%Num:~-2%" REGEDIT /s myreg%Num:~-2%.reg
@ECHO OFF

An actual working version would look a little like this:

@ECHO OFF & SETLOCAL
SET "Prefix=2F16-"
FOR /L %%A IN (1,1,32) DO CALL :SUB 10%%A
ENDLOCAL & GOTO :EOF

:SUB
SET "Num=%1"
IF /I "%COMPUTERNAME%"=="%Prefix%%Num:~-2%" REGEDIT /s myreg%Num:~-2%.reg

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...