Solved

Create shorcut to network drives

Posted on 2007-11-20
13
237 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:ZEDA_ISG
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Can anyone else offer any advice?

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

Author Comment

by:ZEDA_ISG
Comment Utility
Anyone ? :)
0
 

Accepted Solution

by:
ZEDA_ISG earned 0 total points
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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

10 Experts available now in Live!

Get 1:1 Help Now