Solved

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

Posted on 2004-09-06
10
23,512 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
[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
  • 3
  • 2
  • +2
10 Comments
 

Expert Comment

by:Naveen13
ID: 11994375


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
ID: 11996897
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
ID: 11998217
If you are making install package,just using installsheild. It is very easy to use and can fit all your problem.
0
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

Author Comment

by:Ian_Beby
ID: 12002828
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
ID: 12003423

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
 
LVL 10

Expert Comment

by:Kavar
ID: 12005973
I must have missed something here...
0
 

Author Comment

by:Ian_Beby
ID: 12013214
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
ID: 12015347
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
ID: 12099862
Thank you so much for your help Kavar..your a legend!
0
 

Expert Comment

by:stenorit
ID: 14938885
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

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
Make the most of your online learning experience.
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 …

695 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