Apologies if incorrect group - Mapped drive rename from batch error

R

Richhall

All

On Windows XP I am running the following script from a .cmd batch to
rename a drive. The problem is I have named the drive before using
this, and it seems to be remembering the previous name, and I cannot
change it. Why is this please?

setlocal
set drv=J
set drv=%drv:"=%
set nn="MY DRIVE"
set nn=%nn:"=%
set mn="%TEMP%\MapName_%RANDOM%.VBS"
if exist %mn% del /q %mn%
set er="%TEMP%\MapName_%RANDOM%.TMP"
if exist %er% del /q %er%
@echo Set oShell = CreateObject("Shell.Application")>%mn%
@echo DRIVE = "%drv:~0,1%:\">>%mn%
@echo oShell.NameSpace(DRIVE).Self.Name = "%nn%">>%mn%
call :quiet>%er% 2>&1
del /q %mn%
del /q %er%



Cheers

Rich
 
P

Pegasus \(MVP\)

Richhall said:
All

On Windows XP I am running the following script from a .cmd batch to
rename a drive. The problem is I have named the drive before using
this, and it seems to be remembering the previous name, and I cannot
change it. Why is this please?

setlocal
set drv=J
set drv=%drv:"=%
set nn="MY DRIVE"
set nn=%nn:"=%
set mn="%TEMP%\MapName_%RANDOM%.VBS"
if exist %mn% del /q %mn%
set er="%TEMP%\MapName_%RANDOM%.TMP"
if exist %er% del /q %er%
@echo Set oShell = CreateObject("Shell.Application")>%mn%
@echo DRIVE = "%drv:~0,1%:\">>%mn%
@echo oShell.NameSpace(DRIVE).Self.Name = "%nn%">>%mn%
call :quiet>%er% 2>&1
del /q %mn%
del /q %er%

Cheers

Rich

Your code looks like an elaborate hoax. It its current
form it won't do anything useful.
 
R

Richhall

This might be why it doesn't work - i copied it from an old file i
thought worked. Can you tell me how from a batch I can rename what
appears in explorer to a newly mapped drive please?

i.e.

ive used

net use j: etc to create a new network mapped drive, but wish to
display what is displayed in explorer.

Cheers

Richc
 
B

Bob I

Your phrasing is difficult to understand. IF you create a mapping of "J"
it will be "J", just create the correct desired mapping in the first
place. Simply clear all mapping and map drives as desired.

NET USE * /D
NET USE J: /computername/sharename
 
R

Richhall

Apologies

I'll try as suggested, what I mean is say I may a drive

net use j: password logon etc

then in explorer it appears on the left as:

(J) $E on XXX.XX.XX.XX (Windows 2003 server)

I want it to simply say

(J) E on Rich Server 1

Cheers

Rich
 
P

Pegasus \(MVP\)

Richhall said:
Apologies

I'll try as suggested, what I mean is say I may a drive

net use j: password logon etc

then in explorer it appears on the left as:

(J) $E on XXX.XX.XX.XX (Windows 2003 server)

I want it to simply say

(J) E on Rich Server 1

Cheers

Rich

AFAIK, the description field is fixed.
 
B

Bob I

R-click the drive letter in My Computer and pick "Rename". Call it
whatever you want.
 
P

Pegasus \(MVP\)

Bob I said:
R-click the drive letter in My Computer and pick "Rename". Call it
whatever you want.

So it does! Applying this newly learnt piece of info, I knocked
together this batch file which makes sense AND works. You
need to change lines 2 and 3 to suit your requirements.
@echo off
echo >"%temp%\ren.vbs" drive = "Q:"
echo >>"%temp%\ren.vbs" NewName = "Shared Drive 2"
echo >>"%temp%\ren.vbs" Set oShell = CreateObject("Shell.Application")
echo >>"%temp%\ren.vbs" oShell.NameSpace("Q:").Self.Name = NewName
cscript //nologo "%temp%\ren.vbs"
 
P

Pegasus \(MVP\)

Oops - slight correction. The script should look like this:
@echo off
echo >"%temp%\ren.vbs" Drive = "Q:"
echo >>"%temp%\ren.vbs" NewName = "Shared Drive 2"
echo >>"%temp%\ren.vbs" Set oShell = CreateObject("Shell.Application")
echo >>"%temp%\ren.vbs" oShell.NameSpace(Drive).Self.Name = NewName
cscript //nologo "%temp%\ren.vbs"
 
P

Pegasus \(MVP\)

Thanks. They key idea was already in the OP's first post-
I only had to dig it out of the rubbish it was covered with.
 
R

Richhall

Thanks, been away so not had a chance to try. Sorry about the
'rubbish' but it had worked at one point and I'm not a developer of
any sort.
 
P

Pegasus \(MVP\)

Richhall said:
Thanks, been away so not had a chance to try. Sorry about the
'rubbish' but it had worked at one point and I'm not a developer of
any sort.

No offence meant. I suggest you ask the original
author of the following cod fragment what he had
in mind, unless, as I said before, it was meant to
be a hoax:
setlocal
set drv=J
set drv=%drv:"=%
set nn="MY DRIVE"
set nn=%nn:"=%
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top