Dos batch problem

Status
Not open for further replies.

Beni

Posts: 12   +0
Hi all

I'm currently working at a netlogon script. I came as far as you can see below (the comments are in german, so, ignore them :) );

@echo off
cls
REM Scripted by B.Grob / Cropmark AG

REM ** Variable ipadress deklarieren **
for /f "Tokens=2 Delims=[] skip=1" %%i in ('ping -n 1 %computername%') do set IPAdress=%%i

REM ** Bestimmen des Subnetz **
If %IpAdress% LEQ 192.168.0.0 Goto unbekannt
If %IpAdress% LEQ 192.168.100.9 Goto 100
If %IpAdress% LEQ 192.168.100.99 Goto 100
If %IpAdress% LEQ 192.168.100.255 Goto 100
If %IpAdress% LEQ 192.168.200.9 Goto 200
If %IpAdress% LEQ 192.168.200.99 Goto 200
If %IpAdress% LEQ 192.168.200.255 Goto 200
If %IpAdress% LEQ 192.168.222.9 Goto 222
If %IpAdress% LEQ 192.168.222.99 Goto 222
If %IpAdress% LEQ 192.168.222.255 Goto 222
If %IPAdress% GEQ 192.168.255.0 Goto unbekannt
GOTO ENDE

REM ** Bei Welchem Subnetz was machen **
REM ** Subnet 192.168.100.0 **
:100
net use * /delete
y
y
y
net use p: \\server8\server8
goto ende

REM ** Subnet 192.168.200.0 **
:200
net use * /delete
y
y
y
net use p: \\server6\server6
goto ende

REM ** Subnet 192.168.222.0 **
:222
net use * /delete
y
y
y
net use p: \\server4\server4
goto ende

REM ** Subnet grösser oder kleiner als der definierte Bereich **
:unbekannt
shutdown /l
Goto ende

:ende


Now, i have two questions;
1. To define in which subnet the client is, I had to check three times (1 for 1-digit ips, 1 for 2-digit ips, 1 for 3-digit ips). I really belive this isn't the nice way to programm a script, but I don't know how to do it correctly. I tryed it with 192.168.100.* or 192.168.100.???, but neither of them worked.

2. As you can see, I delete the currently mapped networkshares in a really ugly way, but didn't found a better way yet. The three y's are for the confirmation that is needed. There must be a better way for this (or better, I hope there is a better way), didn't found out which one it is untill now.

I hope somone can help..
 
The first part of the batch file tries to find out the IP address of the computer it is running on and then figures out the subnet out of three possible values?

You could do something like this instead:
ECHO %IPADDRESS% | FIND ".100." > NUL
IF NOT ERRORLEVEL 1 GOTO 100
ECHO %IPADDRESS% | FIND ".200." > NUL
IF NOT ERRORLEVEL 1 GOTO 200
ECHO %IPADDRESS% | FIND ".222." > NUL
IF NOT ERRORLEVEL 1 GOTO 222

I have no idea if this will work.. Just something off the top of my head :p

To get rid of all network drives without confirmation use "net use * /del /yes"
 
I got it yesterday.. It looks now something like;
FOR %%x in (9 99 255) do If %IpAdress% LEQ 192.168.100.%%x goto :100

I haven't got the time to check if it works, but I think it will.. Your way way should work as well.. Perhaps I'll try it as well.. thx for the help

BTW: I could solve the Problem with the network drive as well. There is the option /persistent:no, so the drives will only be mapped as long as the user is logged on. So, everything should work now..

Thx again
 
Status
Not open for further replies.
Back