Support Forums

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.
User avatar
devereux0110
Posts: 34
Joined: Thu Aug 31, 2006 4:34 am

Rename Mapped Drive

Postby devereux0110 » Mon Jul 13, 2015 11:51 am

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
Joined: Wed Dec 03, 2014 2:26 pm

Rename Mapped Drive

Postby SAPIEN Support Forums » Mon Jul 13, 2015 11:51 am

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 ***
User avatar
jvierra
Posts: 10026
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Rename Mapped Drive

Postby jvierra » Mon Jul 13, 2015 3:44 pm

Logon scripts cannot be run when not connected to the domain.
User avatar
devereux0110
Posts: 34
Joined: Thu Aug 31, 2006 4:34 am

Re: Rename Mapped Drive

Postby devereux0110 » Tue Jul 14, 2015 2:15 am

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
User avatar
jvierra
Posts: 10026
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Rename Mapped Drive

Postby jvierra » Tue Jul 14, 2015 4:23 am

Try removing this line and fixing the errors: "On Error Resume Next"
User avatar
jvierra
Posts: 10026
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Rename Mapped Drive

Postby jvierra » Tue Jul 14, 2015 4:27 am

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: 34
Joined: Thu Aug 31, 2006 4:34 am

Re: Rename Mapped Drive

Postby devereux0110 » Tue Jul 14, 2015 7:16 am

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.
User avatar
jvierra
Posts: 10026
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Rename Mapped Drive

Postby jvierra » Tue Jul 14, 2015 7:34 am

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: 34
Joined: Thu Aug 31, 2006 4:34 am

Re: Rename Mapped Drive

Postby devereux0110 » Tue Jul 14, 2015 9:36 am

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
User avatar
jvierra
Posts: 10026
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Rename Mapped Drive

Postby jvierra » Tue Jul 14, 2015 9:47 am

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.

Return to “VBScript”

Who is online

Users browsing this forum: No registered users and 1 guest

cron