Solved

Create shorcut to network drives

Posted on 2007-11-20
13
245 Views
Last Modified: 2009-11-12
At present users logon to their machines and access the files they require through various mapped drives. Each user has a script when they logon which is assigned to their user profile in Active Directory, the script will be their surname followed by the first initial of their first name, for example smitha.bat

It is quite common that a user will call Technical Support to say that their drives have not loaded, sometimes a restart will fix this but sometimes it doesn't and therefore we manually put their .bat file onto the desktop which they can double click and it will then load the drives.

What I would like to do is create a script either in VB or as a batch file so when the user logs onto any machine the script automatically puts their .bat file on the desktop. This will save time for the users and tech support.

Does anyone know how I could do this?
0
Comment
Question by:ZEDA_ISG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
13 Comments
 
LVL 6

Expert Comment

by:MorDrakka
ID: 20319001
Hi,

Would something like this solve your problem ??

1st get the name of the users login script with a dsquery query:

dsquery user -samid %username% | dsget user -loscr

2nd copy the file to C:\documents and settings\%username%\desktop

Hope this helps
0
 

Author Comment

by:ZEDA_ISG
ID: 20319090
Thank you for the fast reply.

The first line works as it states the users batch file. Great, thanks.

What we need to do is create a shortcut to the .bat from the server to the desktop upon logon, for example:

\\Servername\SYSVOL\domain.co.uk\scripts\smitha.bat

to

C:\Documents and Settings\smitha\Desktop

Then they double click the smitha.bat which then loads the network drives in My Computer.

Thanks.

0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20321206
Here's an example of how to create a shortcut on the desktop, just pass in the path to the bat file:

Private Sub CreateShortCut(ByVal path As String)

Set myWSH = CreateObject("WScript.Shell")
Set WSHShortcut = _
    myWSH.CreateShortCut("C:\Documents and Settings\All Users\Desktop\MapDrives.lnk")
   
    With WSHShortcut
        .TargetPath = path
        .Description = "MapDrives"
        .RelativePath = path
        .WorkingDirectory = "C:\"
        .WindowStyle = 3   ' 1 = normal; 3 = maximize window; 7 = minimize
        .Save
    End With
   
    Set myWSH = Nothing
    Set WSHShortcut = Nothing
   
End Sub




'And here's an example:
Dim databasePath As String
databasePath = "C:\TEMP\db4.mdb"
CreateShortCut (databasePath)

MsgBox "Done"

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:MorDrakka
ID: 20326217
Hi,

I still believe it's better to copy the batchfile, since it is a t iny bit of data. If you use script VBrocks mentioned above you must change the path from all user profile to target userprofile. Else will the next person to logon be able to click the batchfile lnk too.

Me and my collegue spend some time on this :p

The following is tested and should work:


dsquery user -samid %username% | dsget user -loscr >>logonS.txt

for /F "skip=1" %i in (logonS.txt) do @if not %i==dsget copy %i C:\documents and settings\%username%\desktop
1 file(s) copied.

Check it out! Just 2 lines!
M
0
 

Author Comment

by:ZEDA_ISG
ID: 20326524
Thanks for the replys. I tried this:

dsquery user -samid %username% | dsget user -loscr >>logonS.txt

for /F "skip=1" %i in (logonS.txt) do @if not %i==dsget copy %i C:\documents and settings\%username%\desktop
1 file(s) copied.

It creates the logonS.txt file in the root of C:/ which is great but it doesn't put the individuals .bat file on the desktop, i.e. smitha.bat.

Any ideas?
0
 
LVL 6

Expert Comment

by:MorDrakka
ID: 20327814
HJi,

You have to test a little with that.

Change the for loop into:

for /F "skip=1" %i in (logonS.txt) do @if not %i==dsget echo %i
This echo's in your dosboxx what logonscript is supposed to be.(We have no logon script in AD so had to test that For loop with something else)
If you see nothing, you can add >>log.txt to the command and show me here what is in log.txt
Next you can try
for /F "skip=1" %i in (logonS.txt) do @if not %i==dsget copy %i C:\
To see whether he can copy the script to c:\ (Maybe %username% does not work.

Good luck!
0
 

Author Comment

by:ZEDA_ISG
ID: 20328133
Hi

Tried the new suggestions again, still it runs the first bit:
dsquery user -samid %username% | dsget user -loscr >>logonS.txt

But after this, it is still not doing anything at all.  I have found that if I drag the script into a command prompt and run it, it does not run with the % signs as in the script in notepad
(eg.
for /F "skip=1" i in (logonS.txt) do @if not i==dsget echo i
instead of
for /F "skip=1" %i in (logonS.txt) do @if not %i==dsget echo %i
)

I also tried putting the >>log.txt but the text file didn't create as an error came back in the command window saying "echo was unexpected at this time" or "copy was unexpected at this time" depending on whether using Echo or Copy.

Thanks for the help so far...
0
 
LVL 6

Expert Comment

by:MorDrakka
ID: 20333050
Hmmmz,

I am running out of options to help you with this, the command works fine here.

Be sure that when you run in a command prompt you are in the same path as logonS.txt. I might be a problem of there being a slight delay between logonS.txt being created and you opening it for reading.

In picture below you clearly see the echo of D:\test.vbs
http://img150.imageshack.us/my.php?image=logonsio6.jpg

I hope you figure it out!
0
 

Author Comment

by:ZEDA_ISG
ID: 20356872
Thanks for the help but I cannot get this to work.

It finds the batch file no problem but it simply will not copy the .bat file to the desktop for the user to click to load the drives.

Any other ideas?
0
 

Author Comment

by:ZEDA_ISG
ID: 20372046
Can anyone else offer any advice?

It would save so much time if we got this to work!
0
 

Author Comment

by:ZEDA_ISG
ID: 20394875
Anyone ? :)
0
 

Accepted Solution

by:
ZEDA_ISG earned 0 total points
ID: 20412307
I have got this to work by doinf the following:

Create a .bat file which contains a copy command:

copy "\\servername\sysvol\domain.co.uk\scripts\network_drives\network_drives.lnk" "%systemdrive%\Documents and Settings\%username%\Desktop"

This then create a network_drives.lnk file which copies the .bat file to the desktop.

It is then applied through group policy, logon/logoff script. Working just as I wanted to. Thanks for the help anyway.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question