Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to replace my current batch logon 1

Status
Not open for further replies.

MikeKhod

IS-IT--Management
Dec 21, 2007
33
US
Can anyone help me to write this in VB script.
I am able to map all drives, but on the H: drive i would like the script to actually create a folder with the users name and map it to the H drive. Also i get an error message if the network drive is mapped already. thanks.
That is the part i cant get to work.
rem Map Network Drives
REM NET USE * /DELETE
NET USE E: /DELETE /YES
REM NET USE F: /DELETE
REM NET USE G: /DELETE
REM NET USE J: /DELETE
rem NET USE E: \\Icverify\request
NET USE E: \\Icvsvr\request
NET USE F: \\W2003svr\Pdcmain
NET USE G: \\W2003svr\Depts
NET USE H: \\W2003svr\Pdcmain\Users\%username%
NET USE I: \\term-srvr-2003\ts3server
NET USE J: \\W2003svr\docs
 
Have a look at my login script FAQ.

faq329-5798

Creating a folder is easy.

Code:
If Nof objFSO.FolderExists("C:\Users\" & UserString) Then 
   objFSO.CreateObject("C:\Users\" & UserString)
End If

You should however look at a more comprehensive solution that will also set folder permissions.



I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thank you for your help, but this is my current one.
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "E:" , "\\Icvsvr\request"
objNetwork.MapNetworkDrive "F:" , "\\W2003svr\Pdcmain"
objNetwork.MapNetworkDrive "G:" , "\\W2003svr\Depts"
objNetwork.MapNetworkDrive "I:" , "\\term-srvr-2003\ts3server"
objNetwork.MapNetworkDrive "J:" , "\W2003svr\docs

AND THIS IS WHAT I AM MISSING
NET USE H: \\W2003svr\Pdcmain\Users\%username%
Which i have to manually create user folder for the system to map to the server. I was looking for a vb script to create and map network drive.
 
Sorry, correction to my above posted code

Code:
If Nof objFSO.FolderExists("C:\Users\" & UserString) Then 
   objFSO.Create[red]Folder[/red]("C:\Users\" & UserString)
End If

Refer to my FAQ for grabbing the user name and mapping the drive.

Use XCACLS to set the folder permissions via script as well.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Mark, thanks for trying to help me, but I am confiused.
You see my above vbscript that i use, do i just add the line you gave me and change the path?
when someone new is hired i create the folder then with this line it mapps, not so concern with permisions
NET USE H: \\W2003svr\Pdcmain\Users\%username%
i was wondering if you can give me an exact code of what i would have to add to my new vb script before i take the .bat file off and use it.
 
To get the current user's account name you need this line:
Code:
strUserName = objNetwork.UserName

then to map the drive:
Code:
objNetwork.MapNetworkDrive "H:" , "\\W2003svr\Pdcmain\Users\" & strUserName

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Mike, as JJ has suggested you need to grab the username so you can use it in the mapping.

I'm guessing that you did not look at my FAQ though because I have a very comprehensive login script and the code I provided you could easily be added to that (or your existing) script.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thank you very much to both of you, i greatly apriciate your help.
 
This is the script i tryed and i got an erro on line6 car1.
Is there an error on this?

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "E:" , "\\Icvsvr\request"
objNetwork.MapNetworkDrive "F:" , "\\W2003svr\Pdcmain"
objNetwork.MapNetworkDrive "G:" , "\\W2003svr\Depts"
objNetwork.MapNetworkDrive "I:" , "\\term-srvr-2003\ts3server"
objNetwork.MapNetworkDrive "J:" , "\W2003svr\docs"
strUserName = objNetwork.UserName
objNetwork.MapNetworkDrive "H:" , "\\W2003svr\Pdcmain\Users\" & strUserName
 
Is that the line that starts
Code:
objNetwork.MapNetworkDrive "J:" , "\W2003svr\docs"
?

If so, it should be like this:
Code:
objNetwork.MapNetworkDrive "J:" , "\\W2003svr\docs"
(note the DOUBLE backslash)

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "E:" , "\\Icvsvr\request"
objNetwork.MapNetworkDrive "F:" , "\\W2003svr\Pdcmain"
objNetwork.MapNetworkDrive "G:" , "\\W2003svr\Depts"
objNetwork.MapNetworkDrive "I:" , "\\term-srvr-2003\ts3server"
objNetwork.MapNetworkDrive "J:" , "\W2003svr\docs"
strUserName = objNetwork.UserName
objNetwork.MapNetworkDrive "H:" , "\\W2003svr\Pdcmain\Users\" & strUserName
This is how my current vb script looks like but i get an error on line 6:?????
Also, how do i add to disconect any cureently mapped drives?
THANKS+
 
Actually, JJ you are right, mistype. That worked, except, how do i also add it to disconnect mapped drive for the ones i want to use, so that i dont get an error.??
Thanks again for all your help
 
I deleted my home user which is the last line, and it didnt create a folder for the username
strUserName = objNetwork.UserName
objNetwork.MapNetworkDrive "H:" , "\\W2003svr\Pdcmain\Users\" & strUserName
Is there a way i can tell it to create?
 
Mark,
I didnt see a FAQ on the web link you posted
 
From my December 26 post FAQ329-5798

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Well, in an earlier post you stated that you'd create the target user's folder manually, but no matter, it's easy enough to do.
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FolderExists("\\W2003svr\Pdcmain\Users\" & strUserName) Then
    objFSO.CreateFolder("\\W2003svr\Pdcmain\Users\" & strUserName)
End If

objNetwork.MapNetworkDrive "H:" , "\\W2003svr\Pdcmain\Users\" & strUserName
Of course there's no error checking in this, so if the CreateFolder method fails then the MapNetworkDrive method will fail too...but that's whole different thread!

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Thanks for your help, is there a way to set it to create the folder, cause, i copied your script and ran it so i did get an error.
How can i make it create the folder for me as well, and if it exists to ignore it and just map instead?
Also if the network drive is mapped already i get an error.
Is there a way just like batch files to make it disconnect current drives mapped or ignore if the drive letter already in use.
Thanks again
 
This is my current script:

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "E:" , "\\Icvsvr\request"
objNetwork.MapNetworkDrive "F:" , "\\W2003svr\Pdcmain"
objNetwork.MapNetworkDrive "G:" , "\\W2003svr\Depts"
objNetwork.MapNetworkDrive "I:" , "\\term-srvr-2003\ts3server"
objNetwork.MapNetworkDrive "J:" , "\\W2003svr\docs"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists("\\W2003svr\Pdcmain\Users\" & strUserName) Then
objFSO.CreateFolder("\\W2003svr\Pdcmain\Users\" & strUserName)
End If
objNetwork.MapNetworkDrive "H:" , "\\W2003svr\Pdcmain\Users\" & strUserName
 
Mike you seem to be ignoring every other post.

You need to assign the strUserName value.

Code:
Dim objNetwork, objFSO, strUserName

Set objNetwork = CreateObject("WScript.Network") 
Set objFSO = CreateObject("Scripting.FileSystemObject")
[red]
strUserName = objNetwork.UserName
[/red]

objNetwork.MapNetworkDrive "E:" , "\\Icvsvr\request"
objNetwork.MapNetworkDrive "F:" , "\\W2003svr\Pdcmain"
objNetwork.MapNetworkDrive "G:" , "\\W2003svr\Depts"
objNetwork.MapNetworkDrive "I:" , "\\term-srvr-2003\ts3server"
objNetwork.MapNetworkDrive "J:" , "\\W2003svr\docs"
If Not objFSO.FolderExists("\\W2003svr\Pdcmain\Users\" & strUserName) Then
    objFSO.CreateFolder("\\W2003svr\Pdcmain\Users\" & strUserName)
End If
objNetwork.MapNetworkDrive "H:" , "\\W2003svr\Pdcmain\Users\" & strUserName

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
No, i am not ignoring any posting, i am just not undrestanding some of it. This is my first time ever messing around with .vbs. I am not sure if it needs to be in an different order, if a space between lines makes a difference,etc..
Thank you for your help, and the script works perfectly, except if the network drive is mapped it gives me an error.
How can i make it ignore mapped drive already?
thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top