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

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...
Ian_BebyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Naveen13Commented:


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
KavarCommented:
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
tzxie2000Commented:
If you are making install package,just using installsheild. It is very easy to use and can fit all your problem.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Ian_BebyAuthor Commented:
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
Naveen13Commented:

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
KavarCommented:
I must have missed something here...
0
Ian_BebyAuthor Commented:
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
KavarCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ian_BebyAuthor Commented:
Thank you so much for your help Kavar..your a legend!
0
stenoritCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.