If username = stuff

  • Thread starter Thread starter Mark Coutinho
  • Start date Start date
M

Mark Coutinho

I've got a pretty basic question here, but I can't figure out how to
do it, being a newby.

I want to write a batch-file which can do the next few things:
- check if the user is Mary or Pete or Joseph
- if yes: call a batch (f:\public\printer.bat)
- if no: call another batch (f:\public\colorprinter.bat)

Can anyone help me on this one?

Thanks!
 
Mark said:
I've got a pretty basic question here, but I can't figure out how to
do it, being a newby.

I want to write a batch-file which can do the next few things:
- check if the user is Mary or Pete or Joseph
- if yes: call a batch (f:\public\printer.bat)
- if no: call another batch (f:\public\colorprinter.bat)

Can anyone help me on this one?

@echo off&setlocal
set PB=f:\public\colorprinter.bat
set P2=f:\public\printer.bat
set Users=mary pete Joseph
for %%A in (%Users%) do if /I "%USERNAME%" EQU "%%A" set PB=%P2%
call %PB%

HTH
 
Hi Matthias,

thanks for you reply!

I've changed a few things which makes a few adjustings necessary.

My batch looks like this right now

@echo off&setlocal
set PB=f:\public\AllePrintersVerbindenKleur.reg
set P2=f:\public\AllePrintersVerbinden.reg
set Users=petra berry wilma rose-marie
for %%A in (%Users%) do if /I "%USERNAME%" EQU "%%A" set PB=%P2%
call %PB%

It's about the .reg entry's
I know I said I wanted to call batches, but is it possible to execute
these registry-entries instead? Of course it is, but how would the
lines be then?

So the 5 users will get a colorprinter in their printer-registry-key
and all the others get the other registry entry which does not have a
colorprinter in it.

Thanks again!
 
Mark said:
My batch looks like this right now

@echo off&setlocal
set PB=f:\public\AllePrintersVerbindenKleur.reg
set P2=f:\public\AllePrintersVerbinden.reg
set Users=petra berry wilma rose-marie
for %%A in (%Users%) do if /I "%USERNAME%" EQU "%%A" set PB=%P2%
call %PB%

It's about the .reg entry's
I know I said I wanted to call batches, but is it possible to execute
these registry-entries instead? Of course it is, but how would the
lines be then?

So the 5 users will get a colorprinter in their printer-registry-key
and all the others get the other registry entry which does not have a
colorprinter in it.
You could use reg.exe (included in xp, for w2k in the resource Kit)
to integrate the settings directly, or use start xyz.reg to install
the reg file. Type reg /? in a cmd window.

Depending on your environment there should be other/better ways to
set default/allowed printers.

HTH
 
Hi Matthias,

I made some changes for my batch, but I can't get the last thing
right.

This is what I got:

@echo off&setlocal
setPB=F:\PUBLIC\Uitrollen\Printersverbinden\AllePrintersVerbindenKleur.bat
set P2=F:\PUBLIC\Uitrollen\Printersverbinden\AllePrintersVerbinden.bat
set Users= petra berry
for %%A in (%Users%) do if /I "%USERNAME%" EQU "%%A" set PB=%PB%
call %P2%

(in the original there is a space between 'set' and 'PB' (i.e. set PB,
but I can't get it right in my Free Agent mail)
Now what has to happen is: if Berry or Petra is the one who's logging
in they have to 'use' PB
If anyone else is logging in they have to call P2.

But no matter how I puzzle with the last two lines of the batch I
never get i right.

Could you help me once more, please?

Thanks!
 
Mark said:
But no matter how I puzzle with the last two lines of the batch I
never get i right.
I made PB standard, if one of the named users logs in, copy P2 to PB.

@echo off&setlocal
set P1=F:\PUBLIC\Uitrollen\Printersverbinden\AllePrintersVerbinden.bat
set P2=F:\PUBLIC\Uitrollen\Printersverbinden\AllePrintersVerbindenKleur.bat
set PB=%P1%
set Users= petra berry
for %%A in (%Users%) do if /I "%USERNAME%" EQU "%%A" set PB=%P2%
call %PB%

HTH
 
Back
Top