Solved

Create shortcuts on remote desktop

Posted on 2011-03-14
12
1,756 Views
Last Modified: 2012-05-11
I send to create a Shortcut Icon on all users desktop. I have an inputlist
Computer and username. (Inputlist.txt attached)

Eg u123c1:psr123a
     u431c2:psr432a

The shortcut will be as follows

\\auprifile01\username\my_documents

The VBScript will do the following

Let say for u123c1:psr123a

Copy the Shortcut \\auprifile01\psr123a\my_documents  to c:\documents and settings\u231c1\desktop

Inputlist.txt
0
Comment
Question by:Bianchi928
[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
  • 6
  • 3
  • 3
12 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 35135288
Hi, can you please explain a little more?

If you have
u123c1:psr123a

do you want to copy
\\auprifile01\psr123a\my_documents.lnk
to
\\u123c1\c$\documents and settings\psr123a\desktop\my_documents.lnk

Thanks,

Rob.
0
 
LVL 8

Expert Comment

by:GundogTrainer
ID: 35136549
As per RobSampson comment, Can you confirm the shortcut already exists or does that need to be created ?

If its just a copy the attached code should work, I can post the code to just create a shortcut if that is required.
Const ForReading = 1

CurrentLineNum=0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile ("Inputlist.txt", ForReading)

Do Until oTextFile.AtEndOfStream
 sLine = oTextFile.ReadLine
 arrLine=split(sline,":")

 CopyFrom = "\\auprifile01\" & arrline(0) & "\my_documents.lnk"
 CopyTo =   "c:\documents and settings\" & arrline(1) & "\desktop\"
 
 wscript.echo "Copying: " & CopyFrom & " to: & CopyTo
 If oFSO.FileExists() Then
   filesys.CopyFile CopyFrom, CopyTo
 End If

Loop

Open in new window

0
 
LVL 8

Expert Comment

by:GundogTrainer
ID: 35136623
If you just need to create a shortcut to the network folders then the following should work.
Const ForReading = 1

Set WshShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile ("Inputlist.txt", ForReading)

Do Until oTextFile.AtEndOfStream
 sLine = oTextFile.ReadLine
 arrLine=split(sline,":")

 ShortcutTarget = "\\auprifile01\" & arrline(0) & "\my_documents"
 ShortcutPath =   "c:\documents and settings\" & arrline(1) & "\desktop\My Documents on AUPRIFILE01.lnk"

 Set objShortcutLnk = WshShell.CreateShortcut(ShortcutPath)
 objShortcutLnk.TargetPath = ShortcutTarget
 objShortcutLnk.Save
 set objShortcutLnk=nothing

Loop

Open in new window

0
Technology Partners: 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!

 

Author Comment

by:Bianchi928
ID: 35136657
Hey Rob  !

All i want the script to do is create a shortcut on the desktop as per attachment

 1. Use the input file so as to know to which computer (u123c1) to send it to.
 2  Use the username (psr123a) to know where to copy it to on the desktop.

In a nutshell  the user should see on his computer desktop a shortcut  as per attachment.
N.B Should be mapped to H: drive.

Sorry about the confusion
Thanks
Cheers




Shortcut.bmp
0
 
LVL 8

Expert Comment

by:GundogTrainer
ID: 35136790
So are you saying for the input file:

u123c1:psr123a

This should create a shortcut to \\auprifile01\psr123a\my_documents
The shortcut needs be created on \\u123c1\documents and settings\prs123a\desktop\
And look something like "Shortcut to My_Documents on AUPRIFILE01"

Const ForReading = 1

Set WshShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile ("Inputlist.txt", ForReading)

Do Until oTextFile.AtEndOfStream
 sLine = oTextFile.ReadLine
 arrLine=split(sline,":")

 ShortcutTarget = "\\auprifile01\" & arrline(1) & "\my_documents"
 ShortcutPath =   "\\" & arrline(0) & "\documents and settings\" & arrline(1) & "\desktop\Shortcut to My_Documents on AUPRIFILE01.lnk"

 Set objShortcutLnk = WshShell.CreateShortcut(ShortcutPath)
 objShortcutLnk.TargetPath = ShortcutTarget
 objShortcutLnk.Save
 set objShortcutLnk=nothing

Loop

Open in new window

0
 

Author Comment

by:Bianchi928
ID: 35141945
To Rob & Gundog Trainer

The following Code was used to send a lnk to a list of remote computers (attached list). I want to be able to do the same but send a shorcut (as per previous attached bmp) to appear on their desktop.

Dim objFSO, objFile, wmiQuery, objWMIService, objPing, objStatus
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
ComputersList = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\inputlist2.txt"
SourceFile    = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\e-Learning.url"
Const intForAppending = 8
ReportFile = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\outputlist2.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutput = objFSO.OpenTextFile(ReportFile, intForAppending, False)
arrComputers  = Split(objFSO.OpenTextFile(ComputersList).ReadAll,vbNewLine)
 
For Each PC in arrComputers
  username = "psr" & mid(pc,2,3) & "a"
  Set objping = objWMIService.ExecQuery("Select * From Win32_PingStatus Where " & "Address = '" & PC & "'")
  for each objstatus in objping
       If IsNull(objStatus.StatusCode) Or objStatus.Statuscode <> 0 Then
           ResolveIP = PC & " " & "Failed"
       Else
                DestinationPath = "\\" & PC & "\C$\" & "Documents and Settings\" & username & "\desktop\"
                If objFSO.FolderExists(DestinationPath) = True Then
                 objFSO.CopyFile SourceFile, DestinationPath
                 ResolveIP = PC & " " & objStatus.ProtocolAddress & " Done"
           Else
                 ResolveIP = PC & " " & DestinationPath & " was not found."
           End If
       End If
       ObjOutput.WriteLine(resolveip)
  next
Next

objOutput.Close

Wscript.echo "Job Done"


Thanks
Cheers

Inputlist2.txt
0
 

Author Comment

by:Bianchi928
ID: 35143764
I think that I will have to send this little vbs via email to these users

Dim objShell, strUserName, objnetwork
Set objShell = CreateObject("wscript.Shell")
strUserName = objShell.ExpandEnvironmentStrings("%UserName%")
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "P:", "\\tyrenet-14\transfer\" & strusername & "\my_documents

It will show as a Network Drive in My Computers.

What can I do to this little code to make the shortcut display on their desktop ?

Thanks
Cheers

0
 

Author Comment

by:Bianchi928
ID: 35144092
Okay..I've been a bit further to the point to have the following script save the shortcut on the desktop. One way to have all remote users have it is to send it via email...is there a way by a vbscript to rund that to all remote computers

Dim objShell, strUserName, objnetwork
Set objShell = CreateObject("wscript.Shell")
strUserName = objShell.ExpandEnvironmentStrings("%UserName%")

Set objNetwork = WScript.CreateObject("Wscript.Network")
Set oFSO = CreateObject("Scripting.FileSystemObject")

If Not oFSO.DriveExists("P:") Then
objNetwork.MapNetworkDrive "P:", "\\tyrenet-14\transfer\" & strusername
End If

set WshShell = WScript.CreateObject("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

set objShortcut = WshShell.CreateShortcut(strDesktop & "\\My_Documents.lnk")

objShortcut.Description = "Network Source File Storage"

objShortcut.TargetPath = "\\tyrenet-14\transfer\" & strusername & "\my_documents"

objShortcut.IconLocation = "C:\Windows\System32\shell32.dll, 19"

objShortcut.Save



0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35144371
OK, well you won't be able to map the drive remotely, but that's not required for the shortcut creation anyway.  This will read the input file of
<computer>:<username>

and create the desktop shortcut for them, provided their desktop is at exactly: C:\Documents and Settings\<username>\Desktop

Couldn't you run the script you posted above as a login script via GPO though?  That would be easier, and you'd know that everyone would eventually get it.

Regards,

Rob.
strInputFile = "ComputerUsers.txt"

Dim objShell, objFSO, objInput, strComputer, strUser, objShortcut, strLine
Const ForReading = 1

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objInput = objFSO.OpenTextFile(strInputFile, ForReading, False)
While Not objInput.AtEndOfStream
	strLine = objInput.ReadLine
	If InStr(strLine, ":") > 0 Then
		strComputer = Split(strLine, ":")(0)
		strUser = Split(strLine, ":")(1)
		If Ping(strComputer) = True Then
			If objFSO.FolderExists("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop") = True Then
				Set objShortcut = objShell.CreateShortcut("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop\My_Documents.lnk")
				objShortcut.Description = "Network Source File Storage"
				objShortcut.TargetPath = "\\tyrenet-14\transfer\" & strUser & "\my_documents" 
				objShortcut.IconLocation = "C:\Windows\System32\shell32.dll, 19"
				objShortcut.Save 
			End If
		End If
	End If
Wend
objInput.Close

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 

Author Closing Comment

by:Bianchi928
ID: 35146101
Top
0
 

Author Comment

by:Bianchi928
ID: 35152423
Rob,

After testing the script on live computer it seems that I will need to pass on a local\administrator & password

Can you modify the code for me
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35152703
OK, try this.  It should map a drive to the IPC$ share of each computer as it goes, providing admin access.

Regards,

Rob.
strInputFile = "ComputerUsers.txt"
strLocalUser = "administrator"
strLocalPassword = "localpassword"

Dim objShell, objFSO, objInput, strComputer, strUser, objShortcut, strLine
Const ForReading = 1

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")

Set objInput = objFSO.OpenTextFile(strInputFile, ForReading, False)
While Not objInput.AtEndOfStream
	strLine = objInput.ReadLine
	If InStr(strLine, ":") > 0 Then
		strComputer = Split(strLine, ":")(0)
		strUser = Split(strLine, ":")(1)
		If Ping(strComputer) = True Then
			On Error Resume Next
			objNetwork.MapNetworkDrive "", "\\" & strComputer & "\IPC$", False, strLocalUser, strLocalPassword
			If objFSO.FolderExists("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop") = True Then
				Set objShortcut = objShell.CreateShortcut("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop\My_Documents.lnk")
				objShortcut.Description = "Network Source File Storage"
				objShortcut.TargetPath = "\\tyrenet-14\transfer\" & strUser & "\my_documents" 
				objShortcut.IconLocation = "C:\Windows\System32\shell32.dll, 19"
				objShortcut.Save 
			End If
			objNetwork.RemoveNetworkDrive "\\" & strComputer & "\IPC$", True, False
			If Err.Number <> 0 Then
				WScript.Echo "Error connecting to " & strComputer & VbCrLf & "Error " & Err.Number & ": " & Err.Description
				Err.Clear
			End If
			On Error GoTo 0
		End If
	End If
Wend
objInput.Close

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …

738 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