Link to home
Start Free TrialLog in
Avatar of supercoqui
supercoquiFlag for United States of America

asked on

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


 
Avatar of RobSampson
RobSampson
Flag of Australia image

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.
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.
Avatar of supercoqui

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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