Rename Mapped Drive

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
devereux0110
Posts: 38
Last visit: Mon Oct 02, 2017 7:11 am

Rename Mapped Drive

Post by devereux0110 »

I have come across a small issue

I have a rather simple script that runs as a logon script which renames the Home Drive set by AD, script below

This works perfectly at logon if the user is connected to the Domain at the time of logon. If a user logs on off the network (I,e. working at home offline), when this script is run manually the mapped drive does not rename like it does at a logon where the computer is connected to the system.
Any ideas why it wouldn't work with a manual run, the users are local admins on the computers they are trying to run this on.

On Error Resume Next
Dim objNetwork, strUserName, objApp

Set objNetwork = CreateObject("Wscript.Network")
Set objApp = CreateObject("Shell.Application")
strUsername = objNetwork.UserName

MapDrive "W:", "Home Drive (" & UCase(strUserName) & ")"

Wscript.Quit

'RENAME MAP NETWORK DRIVE FOR MEMBERS OF CERTAIN GROUP
Sub MapDrive (strLetter, strDescription)
On Error Resume Next
Err.Clear
objApp.NameSpace(strLetter & "\").Self.Name = strDescription
On Error Goto 0
End Sub
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Rename Mapped Drive

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, devereux0110.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Rename Mapped Drive

Post by jvierra »

Logon scripts cannot be run when not connected to the domain.
User avatar
devereux0110
Posts: 38
Last visit: Mon Oct 02, 2017 7:11 am

Re: Rename Mapped Drive

Post by devereux0110 »

jvierra wrote:Logon scripts cannot be run when not connected to the domain.
I think you missed a bit of what i said.
It works as a logon script no problem.

The question was, when running the script manually after a logon as taken place offsite, it doesn't rename the mapped drive as expected

I know a logon script wont work when not on the network but a script should work when run manually.

Is there any suggestions on why the script wouldn't work if run manually
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Rename Mapped Drive

Post by jvierra »

Try removing this line and fixing the errors: "On Error Resume Next"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Rename Mapped Drive

Post by jvierra »

Without al of the extra lines this is the whole functional script. Run it and see what errors you are getting then address the errors.
VBScript Code
Double-click the code block to select all.
Set objNetwork = CreateObject("Wscript.Network")
Set objApp = CreateObject("Shell.Application")
objApp.NameSpace("W:\").Self.Name = "Home Drive (" & objNetwork.UserName & ")"
User avatar
devereux0110
Posts: 38
Last visit: Mon Oct 02, 2017 7:11 am

Re: Rename Mapped Drive

Post by devereux0110 »

jvierra wrote:Without al of the extra lines this is the whole functional script. Run it and see what errors you are getting then address the errors.
VBScript Code
Double-click the code block to select all.
Set objNetwork = CreateObject("Wscript.Network")
Set objApp = CreateObject("Shell.Application")
objApp.NameSpace("W:\").Self.Name = "Home Drive (" & objNetwork.UserName & ")"
The results are the same, works when used as logon script but not running manually.
however a bit more information we realised to go with this, it only doesn't rename the drive if the drive as been offline and then comes online again.

No error messages are displayed, it run and then closes as expected, the drive just doesn't rename as expected.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Rename Mapped Drive

Post by jvierra »

For that to work the drive must be physically attached to the computer and not be a network drive. You cannot authenticate to a network share when not in the domain.

If it is a physically attached drive then you likely have other issues that have nothing to do with scripting.

Consider using the "label" command to verify what you are doing.

label /?
User avatar
devereux0110
Posts: 38
Last visit: Mon Oct 02, 2017 7:11 am

Re: Rename Mapped Drive

Post by devereux0110 »

jvierra wrote:For that to work the drive must be physically attached to the computer and not be a network drive. You cannot authenticate to a network share when not in the domain.

If it is a physically attached drive then you likely have other issues that have nothing to do with scripting.

Consider using the "label" command to verify what you are doing.

label /?
OK, a user logs on when at home and files are available offline.
The user then closes the lid on their laptop and puts the laptop to sleep.
When the user comes in school and wakes the laptop in a logged on states and connects to the network, the Offline Drive then goes back online and connects normally but has not been renamed.

Running the script at this time does not rename the drive.

A fresh logon where the script runs as a logon script, the same drive which is already on line renames with no issues
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Rename Mapped Drive

Post by jvierra »

I thought the issue only happened when the user was not connected to the network.

Why are you renaming a drive that is not connected?

I am afraid that this is a hardware issue and not a scripting issue. It may also be a result of trying to use the shell to rename a disconnected drive. The shell is not intended to be used this way.

You can use the net mapping commands to label a mapped device. It will usually be more reliable.
This topic is 8 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked