Solved

A script to rename, move ,delete files and folders and to create shortcuts

Posted on 2004-09-06
10
23,502 Views
Last Modified: 2011-01-30
Hi there,
         I had a question in Windows 2000 where I had a problem with my .MSI packages where the shortcuts didn't work. The program installed successfully and works like a dream but the shortcuts don't work - (Can't make .msi package how I want it - WinInstaller Lite Problems).

As a temporary OR permanent alternative....

I was wondering if someone could help me create a script (batch file or vb file) which can create shortcuts to my desired location and delete\move\copy other files.
Is it possible that the file only run once then after that it will not run again.

Please help me with this one as its been bugging me for weeks. Im desperate enough to give 500 points for this one and personally thank you via email.

Thanks again for all your help...
0
Comment
Question by:Ian_Beby
  • 3
  • 3
  • 2
  • +2
10 Comments
 

Expert Comment

by:Naveen13
Comment Utility


Instead of creating .msi extension you can creeate .exe file using innosetup tool.

because to install msi file into system you have to install msiexec file... If this file not exists you will get errors like....

If you use any version of Innoset it automaticallu writes a script that copied, register, moves, deleted e.t.c

This may helps you
thanks
Naveen
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
okay to create a shortcut via vbs, I have written a little function
everything between "Function CreateShortCut" and "End Function"
is the code to create a short cut, if you want to have a script create a short cut, copy all of this into a vbs
the use the line "CreateShortCut" with parameters that match your need, in my example I created a shortcut with
the name "test short cut" with a executable name of "c:\Some File Here" and a working directory of ","C:\some Working directory Here".  Of course there are other options I can help you with if you need, (Like all of these shortcuts are created on the desktop, if you want them on the start menu I can help you with that)

'************** Begin Script**********************
CreateShortCut "Test Short Cut","c:\Some File Here","C:\some Working directory Here"

Function CreateShortCut(ShortCutName,ShortCutTarget,ShortCutWorkingdirectory)
Dim WSH
Set WSH=CreateObject("wscript.Shell")

Dim strDeskTop
strDeskTop=WSH.SpecialFolders("DeskTop")

Dim NewShortCut
set NewShortCut = Wsh.CreateShortcut(strDesktop & "\" & ShortCutName & ".lnk")
With NewShortCut
      .TargetPath = ShortCutTarget
    .WindowStyle = 1
'    .Hotkey = "CTRL+SHIFT+F"
    .IconLocation = "notepad.exe, 0"
    .Description = "Short Cut Description Here"
    .WorkingDirectory = ShortCutWorkingDirectory
    .Save
End With
End Function
'**************** End Script ***********************


To Delete or Copy files with VBscript (there is no move in vbscript)
use these helper functions, I left an example of each, again like the example above
if you want to delete a file include everything between "function DeleteFile" and "End Function"
and the same with copy file, it should be pretty straight forward, but let me know if you need help

'*****************Begin Script **********************

DeleteFile "C:\whatever File"
CopyFile "C:\sourceFile","C:\destFile"

function DeleteFile(WhatFile)
on Error Resume Next
dim fso
set fso=createobject("Scripting.Filesystemobject")
fso.DeleteFile(WhatFile)
End Function

function CopyFile(WhatSource,WhatDest)
on Error Resume Next
dim fso
set fso=createobject("Scripting.Filesystemobject")
fso.CopyFile WhatSource,WhatDest
End Function
'***************End Script***************
0
 
LVL 5

Expert Comment

by:tzxie2000
Comment Utility
If you are making install package,just using installsheild. It is very easy to use and can fit all your problem.
0
 

Author Comment

by:Ian_Beby
Comment Utility
Hi there Naveen13,
         Thank you for the effort you have gone to helping me with my problem and thanx tzxie2000 also.

Naveen13 - I tried your script but was a little unsure of what fields I had to change.
If I give you my exact example - can you create the script so I will know exactly where everything goes.

Here it goes:-

I have the program ACDSee which is a picture viewing program.
This program is installed in the following directory - C:\Program Files\Programs\ACDSee
The actual .exe file which starts the program sits in - C:\Program Files\Programs\ACDSee\ACDSee\5.0\ACDSee5.exe

I would like a shortcut created to this .exe file and placed in the following directory - C:\Documents and Settings\All Users\Start Menu\Programs\Programs\ACDSee\ACDSee 5.0.lnk

The existing shortcut which is there can be overwritten or deleted - doesn't matter.

Also, in the script, how to I select which Icon picture it should use???

Thanks again for this - I wish I knew more about VB Scripting - know any good sites?

You rock!
0
 

Expert Comment

by:Naveen13
Comment Utility

Hello rock..

To reach your requirement the vbs code looks like this..

Set WSH=CreateObject("wscript.Shell")
set ShortCut = Wsh.CreateShortcut("C:\Documents and Settings\All Users\Start Menu\Programs\Programs\ACDSee\ACDSee 5.0.lnk")
ShortCut.TargetPath = "C:\Program Files\Programs\ACDSee\ACDSee\5.0\ACDSee5.exe"
ShortCut.WorkingDirectory = "C:\Program Files\Programs\ACDSee\ACDSee\5.0\"
ShortCut.Save

Kavar message also helps you......

(or)

http://vbcity.com/forums/faq.asp?fid=6&cat=Shell&

Thanks
Naveen



0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Expert Comment

by:Kavar
Comment Utility
I must have missed something here...
0
 

Author Comment

by:Ian_Beby
Comment Utility
I must of missed something too
Sorry Kavar - My mistake.........

I apologise - Thank you buddy for the detailed code....thats awsome.

I'm still trying to run the vbs script but it comes up with all errors. Do I need a special compiler or something to run this code.

Currently Im just sticking the code in notepad.exe and save it as a vbs file.

0
 
LVL 10

Accepted Solution

by:
Kavar earned 500 total points
Comment Utility
for the code to run you will need windows scripting host installed ( I prefer version 5.6)

take all 3 functions (include the inner text as well) and place them at the bottom of a script.
you can place them anywhere but I find it more readable at the bottom.
with those functions in your vbs you will be able to call them with a single line like...

'*************Begin Script******************
'the format for the create shortcut function is:
' Name of short cut (don't include the .lnk), Taget Program (what you want to run), and Working Directory
CreateShortCut "My ShortCut","notepad.exe","c:\"

'the format for deletefile is
'the name of the file you want to delete
DeleteFile "c:\unwanted file.exe"

'the format for the CopyFile is
'the name of the source file, the name of the Destination file
CopyFile "c:\Source.exe","c:\Dest.exe"


Function CreateShortCut(ShortCutName,ShortCutTarget,ShortCutWorkingdirectory)
Dim WSH
Set WSH=CreateObject("wscript.Shell")

Dim strDeskTop
strDeskTop=WSH.SpecialFolders("DeskTop")

Dim NewShortCut
set NewShortCut = Wsh.CreateShortcut(strDesktop & "\" & ShortCutName & ".lnk")
With NewShortCut
     .TargetPath = ShortCutTarget
    .WindowStyle = 1
'    .Hotkey = "CTRL+SHIFT+F"
    .IconLocation = "notepad.exe, 0"
    .Description = "Short Cut Description Here"
    .WorkingDirectory = ShortCutWorkingDirectory
    .Save
End With
End Function


function DeleteFile(WhatFile)
on Error Resume Next
dim fso
set fso=createobject("Scripting.Filesystemobject")
fso.DeleteFile(WhatFile)
End Function

function CopyFile(WhatSource,WhatDest)
on Error Resume Next
dim fso
set fso=createobject("Scripting.Filesystemobject")
fso.CopyFile WhatSource,WhatDest
End Function
'*****************End Script*******************
0
 

Author Comment

by:Ian_Beby
Comment Utility
Thank you so much for your help Kavar..your a legend!
0
 

Expert Comment

by:stenorit
Comment Utility
Naveen,


I'm wondering how I can supply options to the ShortCut.TargetPath = line?

What I'm trying to do is create a shortcut to an access database that has a security file.  The issue I have it the ShortCut.TargetPath does not understand the full path that I require.  Below is an example of what I have.

Shortcut.TargetPath = "\\files\common\Drafting - Drawing Indexes\DRAWINGS.mdb" /WRKGRP "\\files\common\Drafting - Drawing Indexes\Secured.mdw"
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is about my first experience with programming Arduino.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

11 Experts available now in Live!

Get 1:1 Help Now