Solved

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

Posted on 2008-06-18
6
310 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now