Solved

Create shorcut to network drives

Posted on 2007-11-20
13
238 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

937 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

Need Help in Real-Time?

Connect with top rated Experts

3 Experts available now in Live!

Get 1:1 Help Now