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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.