Link to home
Start Free TrialLog in
Avatar of ZEDA_ISG
ZEDA_ISG

asked on

Create shorcut to network drives

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?
Avatar of MorDrakka
MorDrakka

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
Avatar of ZEDA_ISG

ASKER

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.

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"

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
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?
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!
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...
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!
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?
Can anyone else offer any advice?

It would save so much time if we got this to work!
Anyone ? :)
ASKER CERTIFIED SOLUTION
Avatar of ZEDA_ISG
ZEDA_ISG

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial