Script to handle a few Windows tasks

I need a VB script (must be VB as I will be adding to an existing VB).  The script needs to perform the following items on a Windows  computer.

Create a folder in the current user's profile..
%userprofile%\Login Local Helpdesk

Copy files from  a UNC path to this new folder.

Create a shortcut on the user's desktop for a file that was copied above.
murrycAsked:
Who is Participating?
 
RobSampsonCommented:
Sure, just modifying the If statement should do that.

Regards,

Rob.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strFolder = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Login Local Helpdesk\"
If objFSO.FolderExists(strFolder) = False Then objFSO.CreateFolder strFolder
objFSO.CopyFile "\\server\share\*", strFolder, True
strDesktop = objShell.SpecialFolders("Desktop")
Set objShortcut = objShell.CreateShortcut(strDesktop & "\My Shortcut.lnk")
objShortcut.TargetPath = strFolder & "RunThisFile.exe"
objShortcut.WorkingDirectory = strFolder
objShortcut.Save

Open in new window

0
 
RobSampsonCommented:
Hi, this should work for you.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strFolder = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Login Local Helpdesk\"
If objFSO.FolderExists(strFolder) = False Then
	objFSO.CreateFolder strFolder
	objFSO.CopyFile "\\server\share\*", strFolder
	strDesktop = objShell.SpecialFolders("Desktop")
	Set objShortcut = objShell.CreateShortcut(strDesktop & "\My Shortcut.lnk")
	objShortcut.TargetPath = strFolder & "RunThisFile.exe"
	objShortcut.WorkingDirectory = strFolder
	objShortcut.Save
End If

Open in new window

0
 
murrycAuthor Commented:
I love your solutions Rob!

Can you tweak a few things for me?  I would like for this script to also be used to repair botched executions of the script, or broken pieces of the puzzle. Currently, if I execute it and the folder already exists, it will not do anything further.  So say the user deletes the shortcut on the desktop, or a file gets deleted out of the userprofile folder.  Can you tweak the script to actually execute each command no matter pre-existing files or folders?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.