Solved

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

Posted on 2008-06-18
6
329 Views
Last Modified: 2010-05-18
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


 
0
Comment
Question by:supercoqui
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 21818992
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 21819042
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
 

Author Comment

by:supercoqui
ID: 21820167
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
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 21828038
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
 

Author Closing Comment

by:supercoqui
ID: 31468639
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Introduction to Processes
Starting up a Project

691 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