Ian_Beby
asked on
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...
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...
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(ShortCutNam e,ShortCut Target,Sho rtCutWorki ngdirector y)
Dim WSH
Set WSH=CreateObject("wscript. Shell")
Dim strDeskTop
strDeskTop=WSH.SpecialFold ers("DeskT op")
Dim NewShortCut
set NewShortCut = Wsh.CreateShortcut(strDesk top & "\" & 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:\destFi le"
function DeleteFile(WhatFile)
on Error Resume Next
dim fso
set fso=createobject("Scriptin g.Filesyst emobject")
fso.DeleteFile(WhatFile)
End Function
function CopyFile(WhatSource,WhatDe st)
on Error Resume Next
dim fso
set fso=createobject("Scriptin g.Filesyst emobject")
fso.CopyFile WhatSource,WhatDest
End Function
'***************End Script***************
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(ShortCutNam
Dim WSH
Set WSH=CreateObject("wscript.
Dim strDeskTop
strDeskTop=WSH.SpecialFold
Dim NewShortCut
set NewShortCut = Wsh.CreateShortcut(strDesk
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:\destFi
function DeleteFile(WhatFile)
on Error Resume Next
dim fso
set fso=createobject("Scriptin
fso.DeleteFile(WhatFile)
End Function
function CopyFile(WhatSource,WhatDe
on Error Resume Next
dim fso
set fso=createobject("Scriptin
fso.CopyFile WhatSource,WhatDest
End Function
'***************End Script***************
If you are making install package,just using installsheild. It is very easy to use and can fit all your problem.
ASKER
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\ACDS ee\5.0\ACD See5.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\ACD See\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!
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\ACDS
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\ACD
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!
Hello rock..
To reach your requirement the vbs code looks like this..
Set WSH=CreateObject("wscript.
set ShortCut = Wsh.CreateShortcut("C:\Doc
ShortCut.TargetPath = "C:\Program Files\Programs\ACDSee\ACDS
ShortCut.WorkingDirectory = "C:\Program Files\Programs\ACDSee\ACDS
ShortCut.Save
Kavar message also helps you......
(or)
http://vbcity.com/forums/faq.asp?fid=6&cat=Shell&
Thanks
Naveen
I must have missed something here...
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much for your help Kavar..your a legend!
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"
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"
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