Solved

Create shortcuts on remote desktop

Posted on 2011-03-14
12
1,673 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
  • 6
  • 3
  • 3
12 Comments
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Bianchi928
Comment Utility
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
Comment Utility
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
Comment Utility
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
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).

 

Author Comment

by:Bianchi928
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Top
0
 

Author Comment

by:Bianchi928
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

7 Experts available now in Live!

Get 1:1 Help Now