Could someone provide a VBS script for creating a directory and copying shortcuts(*.lnk)

Basically I got a folder named c:\program files\software_modifications

Inside this folder I have various folders A,B,C,D. Each of these folders got different ini files along with other folders suchs as Desktop and Startmenu.
There is  a VBS script in the software_modification folder that copies some of the files inside other folders in C:

The main problem is that the desktop folder has a group of shortcuts that I wish to copy to the Allusers desktop and the startmenu folder has a group of shortcuts that I want the script to create a folder named "Afolder" and copy to the allUsers startmenu. A basic copy job.

Everytime I run the script I get the error 800A0035. The error is caused due to the last two lines of each of the selections been incorrect. If I take out the lines related to the links, the problem goes away.

================================Problem lines========================================
fso.CopyFile "C:\Program Files\software_modifications\A\Startmenu\*.lnk", "C:\Documents and Settings\All Users\Start Menu\Programs\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\A\Desktop\*.lnk", "C:\Documents and Settings\All Users\Desktop\", true
=============================Problem lines==========================================

Here is a copy of the script:

=====================================Original script=================================
Option Explicit

dim fso, bValid, sResponse

Set fso = CreateObject("Scripting.FileSystemObject")

bValid = false

Do

            sResponse = InputBox("Please select." & vbCrLf & vbCrLf & "Press 1 for A CONFIGURATION" & vbCrLf & vbCrLf & "Press 2 for B CONFIGURATION" & vbCrLf & vbCrLf & "Press 3 for C CONFIGURATION" & vbCrLf & vbCrLf & "Press 4 for D CONFIGURATION" & vbCrLf & vbCrLf & "Press 5 for E CONFIGURATION", "Select a configuration")

           

            Select Case(sResponse)

                        Case "1"           WScript.Echo "You selected A (1)"

                                                fso.CopyFile "C:\Program Files\software_modifications\A\*.ini", "C:\Program Files\software\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\A\SYBASE\INI\*.ini", "C:\sybase\ini\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\A\Startmenu\*.lnk", "C:\Documents and Settings\All Users\Start Menu\Programs\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\A\Desktop\*.lnk", "C:\Documents and Settings\All Users\Desktop\", true                              
      
                                    bValid = true

 

                        Case "2"           WScript.Echo "You selected B (2)"

                                                fso.CopyFile "C:\Program Files\software_modifications\B\*.ini", "C:\Program Files\software\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\B\SYBASE\INI\*.ini", "C:\sybase\ini\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\B\Startmenu\*.lnk", "C:\Documents and Settings\All Users\Start Menu\Programs\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\B\Desktop\*.lnk", "C:\Documents and Settings\All Users\Desktop\", true

                                                bValid = true

                       

                        Case "3"           WScript.Echo "You selected C (3)"

                                                fso.CopyFile "C:\Program Files\software_modifications\C\*.ini", "C:\Program Files\software\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\C\SYBASE\INI\*.ini", "C:\sybase\ini\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\C\Startmenu\*.lnk", "C:\Documents and Settings\All Users\Start Menu\Programs\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\C\Desktop\*.lnk", "C:\Documents and Settings\All Users\Desktop\", true                                    

                                                bValid = true

                       

                        Case "4"           WScript.Echo "You selected D (4)"

                                                fso.CopyFile "C:\Program Files\software_modifications\D\*.ini", "C:\Program Files\software\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\D\SYBASE\INI\*.ini", "C:\sybase\ini\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\D\Startmenu\*.lnk", "C:\Documents and Settings\All Users\Start Menu\Programs\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\D\Desktop\*.lnk", "C:\Documents and Settings\All Users\Desktop\", true

                                                bValid = true


                        Case "5"           WScript.Echo "You selected E (5)"

                                                fso.CopyFile "C:\Program Files\software_modifications\E\*.ini", "C:\Program Files\software\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\E\coco\WINDOWS\*.ini", "C:\coco\windows\", true
                                                fso.CopyFile "C:\Program Files\software_modifications\E\WINDOWS\*.ini", "C:\windows\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\E\SYBASE\INI\*.ini", "C:\sybase\ini\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\E\Startmenu\*.lnk", "C:\Documents and Settings\All Users\Start Menu\Programs\", true
                                    fso.CopyFile "C:\Program Files\software_modifications\E\Desktop\*.lnk", "C:\Documents and Settings\All Users\Desktop\", true
                                    
                                    bValid = true


                       
 

                        Case Else         WScript.Echo "You have entered an invalid response.  Acceptable values are 1 - 5."

                                               

            End Select

 

Loop Until bValid = true


 
supercoquiAsked:
Who is Participating?
 
RobSampsonConnect With a Mentor Commented:
Hi, there's a couple of options I suppose.....

Normal users do not have rights to add things to the All Users profile, so your options are:
1) Run the above script as Admin once on each PC to populate the All Users profile
2) Change the script to write to the user's own Desktop, each time a user logs in (a Login script).  To make that change, add
   Set objShell = CreateObject("WScript.Shell")
to the top of the script, and then change each occurance of
   "C:\Documents and Settings\All Users\Start Menu\Programs\"
to
   objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Start Menu\Programs\"


So, if you choose to use option 1, this becomes a bit more difficult if you want normal users to execute the script, and you would need to use a tool like PSExec to run the script as an Administrator....

Let me know what your thoughts are, and we'll go from there...

Regards,

Rob.
0
 
RobSampsonCommented:
Hi, are you executing the VBS file as a normal user, or admin user?  Check that you can copy a LNK file to the All Users profile manually....

Regards,

Rob.
0
 
RobSampsonCommented:
The 800A0035 error is probably File Not Found.

See if this helps you see what your problem might be, although your syntax looks correct:
http://msdn.microsoft.com/en-us/library/e1wf9e7w(VS.85).aspx

Regards,

Rob.
0
 
supercoquiAuthor Commented:
Thanks for the reply. It is been executed as an administrator right now. This will be a script for a program I am packaging.

So to write to the AllUsers area I need administrator rights? Is there a way to run the script as an administrator while putting some rights on the script for users not to open and peek into it?

I am planing on putting read, list folder contents and execute rights on the folder where this script will be hosted.

0
 
supercoquiAuthor Commented:
It was extremelly helpful. I was out fo the area for over a month and not able to reply due to a slow internet link. Thanks
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.