Hi I would like to know as to how I can pass an array to vbscript file. I have 5text files containing integers. I read them in a batch program and have to pass those 5 integers to the vbscript file and detect them in vbscript
I don't know if this is what you want:
How to use:
Integers.vbs "number1" "number2" "number3" "number4" "number5"
Integers.vbs
' set the vars
Integer1 = Wscript.Arguments.Item(0)
Integer2 = Wscript.Arguments.Item(1)
Integer3 = Wscript.Arguments.Item(2)
Integer4 = Wscript.Arguments.Item(3)
Integer5 = Wscript.Arguments.Item(4)
' Print all the args
Set objArgs = WScript.Arguments
For Each strArg in objArgs
WScript.Echo strArg
Next
Related
I have numerous uniquely named .CSV files that I need to remove the first 17 lines from. Some of these files exceed 65534 rows so my MORE/MOVE Batch script is not working. Looking for alternative solutions.
#echo off
for %%a in (*.csv) do (
more +17 "%%a" >"%%a.new"
move /y "%%a.new" "%%a" >nul
)
Regardless of number of rows input I am looking to have the 17 header rows removed and new file with all remaining rows built.
Here's a powershell option; this one uses a stream to cater for your large files:
$csvs = Get-ChildItem -Path "P:\ath to\your csvs" -Filter *.csv
foreach ( $csv in $csvs ) {
$fin = New-Object System.IO.StreamReader( $csv.FullName )
$fout = New-Object System.IO.StreamWriter( $csv.FullName+".new" )
try {
for( $s = 1; $s -le 17 -and !$fin.EndOfStream; $s++ ) {
$fin.ReadLine()
}
while( !$fin.EndOfStream ) {
$fout.WriteLine( $fin.ReadLine() )
}
}
finally {
$fout.Close()
$fin.Close()
}
}
Just change the path to your .csvs on the first line, before testing it.
I have purposely left out the deletion of the original files, simply appending .new to the new filenames to allow you time to check the results, test the speed etc. I will leave it to you to include a Rename/Delete or Move should you feel the need to extend the functionality.
Here's a one-line solution
for %%a in (*.txt) do powershell -Com "sc -Path '%%a' -Value (gc '%%a' | select -Skip 17)"
where gc and sc are default aliases for Get-Content and Set-Content respectively. See also
Powershell select-object skip multiple lines?
Powershell skip first 2 lines of txt file when importing it
If your files are huge then it'll be better to read in lines or blocks which can also be implemented easily using file functions, [IO.File]::OpenText or the -ReadCount option of Get-Content in PowerShell
Reading large text files with Powershell
Reading very BIG text files using PowerShell
How to process a file in PowerShell line-by-line as a stream
How can I make this PowerShell script parse large files faster?
As Squashman mentioned, for /f also has an option to skip lines at the beginning of the file
for %%a in (*.csv) do (
for /f "usebackq skip=17 delims=" %%l in ("%%f") do #echo(%%l>>"%%a.new"
move /y "%%a.new" "%%a" >nul
)
But that won't work if your file contains lines with special characters like & or |. For more information about it run for /?
Make your own cut command. This is VBScript ported to VB.NET.
Cut
cut {t|b} {i|x} NumOfLines
Cuts the number of lines from the top or bottom of file.
t - top of the file
b - bottom of the file
i - include n lines
x - exclude n lines
Example
cut t i 5 < "%systemroot%\win.ini"
Cut.bat
REM Cut.bat
REM This file compiles Cut.vb to Cut.exe
REM Cut.exe Removes specified from top or bottom of lines from StdIn and writes to StdOut
REM To use
REM cut {t|b} {i|x} NumOfLines
Rem Cuts the number of lines from the top or bottom of file.
Rem t - top of the file
Rem b - bottom of the file
Rem i - include n lines
Rem x - exclude n lines
Rem
Rem Example - Includes first 5 lines Win.ini
Rem
Rem cut t i 5 < "%systemroot%\win.ini"
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\Cut.exe" "%~dp0\Cut.vb" /verbose
pause
Cut.vb
'DeDup.vb
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Module DeDup
Sub Main
Dim Arg() As Object
Dim RS as Object
Dim LineCount as Object
Dim Line as Object
Arg = Split(Command(), " ")
rs = CreateObject("ADODB.Recordset")
With rs
.Fields.Append("LineNumber", 4)
.Fields.Append("Txt", 201, 5000)
.Open
LineCount = 0
Line=Console.readline
Do Until Line = Nothing
LineCount = LineCount + 1
.AddNew
.Fields("LineNumber").value = LineCount
.Fields("Txt").value = Console.readline
.UpDate
Line = Console.ReadLine
Loop
.Sort = "LineNumber ASC"
If LCase(Arg(0)) = "t" then
If LCase(Arg(1)) = "i" then
.filter = "LineNumber < " & LCase(Arg(2)) + 1
ElseIf LCase(Arg(1)) = "x" then
.filter = "LineNumber > " & LCase(Arg(2))
End If
ElseIf LCase(Arg(0)) = "b" then
If LCase(Arg(1)) = "i" then
.filter = "LineNumber > " & LineCount - LCase(Arg(2))
ElseIf LCase(Arg(1)) = "x" then
.filter = "LineNumber < " & LineCount - LCase(Arg(2)) + 1
End If
End If
Do While not .EOF
Console.writeline(.Fields("Txt").Value)
.MoveNext
Loop
End With
End Sub
End Module
how to create a shortcut for a exe from a batch file.
i tried
call link.bat "c:\program Files\App1\program1.exe" "C:\Documents and Settings\%USERNAME%\Desktop" "C:\Documents and Settings\%USERNAME%\Start Menu\Programs" "Program1 shortcut"
but it did not worked.
link.bat can be found at
http://www.robvanderwoude.com/amb_shortcuts.html
Your link points to a Windows 95/98 version and I guess you have at least Windows 2000 or XP. You should try the NT version here.
Alternatively use a little VBScript that you can call from the command line:
set objWSHShell = CreateObject("WScript.Shell")
set objFso = CreateObject("Scripting.FileSystemObject")
' command line arguments
' TODO: error checking
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut)
set objSC = objWSHShell.CreateShortcut(sShortcut)
objSC.TargetPath = sTargetPath
objSC.WorkingDirectory = sWorkingDirectory
objSC.Save
Save the file as createLink.vbs and call it like this to get what you originally tried:
cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Desktop\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe"
cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Start Menu\Programs\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe"
That said I urge you not to use hardcoded paths like "Start Menu" since they're different in localized versions of windows. Modify the script instead to use special folders.
This is the kind of thing that PowerShell is really good at, and is therefore a reason to eschew batch files and get on PowerShell the bandwagon.
PowerShell can talk to .NET. For example, you can get the location of the Desktop like this:
[Environment]::GetFolderPath("Desktop")
PowerShell can talk to COM objects, including WScript.Shell, which can create shortcuts:
New-Object -ComObject WScript.Shell).CreateShortcut( ... )
So your script might look like:
$linkPath = Join-Path ([Environment]::GetFolderPath("Desktop")) "MyShortcut.lnk"
$targetPath = Join-Path ([Environment]::GetFolderPath("ProgramFiles")) "MyCompany\MyProgram.exe"
$link = (New-Object -ComObject WScript.Shell).CreateShortcut( $linkpath )
$link.TargetPath = $targetPath
$link.Save()
Shortcuts have a lot of settings that WScript.Shell can't manipulate, like the "run as administrator" option. These are only accessible through the Win32 interface IShellLinkDataList, which is a real pain to use, but it can be done.
Using vbscript:
set WshShell = WScript.CreateObject("WScript.Shell" )
strDesktop = WshShell.SpecialFolders("AllUsersDesktop" )
set oShellLink = WshShell.CreateShortcut(strDesktop & "\shortcut name.lnk" )
oShellLink.TargetPath = "c:\application folder\application.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "c:\application folder\application.ico"
oShellLink.Description = "Shortcut Script"
oShellLink.WorkingDirectory = "c:\application folder"
oShellLink.Save
Ref: http://www.tomshardware.com/forum/52871-45-creating-desktop-shortcuts-command-line
Failing that, a quick google search shows there's a number of third party tools that can create .lnk files for application shortcuts. I'm assuming you need to stick to stuff that's available natively on Windows though? VBscript is probably your best bet, otherwise I'd suggest trying copying the .lnk file from your machine or using it as a sample to see the correct format for a shortcut file.
On XP I wrote makeshortcut.vbs
Set oWS = WScript.CreateObject("WScript.Shell")
If wscript.arguments.count < 4 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir "
WScript.Quit
end If
shortcutPath = wscript.arguments(0) & ".LNK"
targetPath = wscript.arguments(1)
arguments = wscript.arguments(2)
workingDir = wscript.arguments(3)
WScript.Echo "Creating shortcut " & shortcutPath & " targetPath=" & targetPath & " arguments=" & arguments & " workingDir=" & workingDir
Set oLink = oWS.CreateShortcut(shortcutPath)
oLink.TargetPath = targetPath
oLink.Arguments = arguments
' oLink.Description = "MyProgram"
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
' oLink.WindowStyle = "1"
oLink.WorkingDirectory = workingDir
oLink.Save
It takes exactly 4 args, so it could be improved by making the later 2 optional.I only post because it echo's usage, which might be useful to some. I like WS's soln using special folders and ExpandEnvironmentStrings
Additional note: the link.bat you're using is for Windows 95/98 only:
This batch file is for Windows 95/98 only. I will post the NT equivalent in
the NT newsgroup soon.
NT version is posted at http://www.robvanderwoude.com/amb_shortcutsnt.html instead. You might try that for a .bat approach if preferred over vbscript.
Alternative method, using a third party utility:
Creating a Shortcut from the command line (batch file)
XXMKLINK:
With XXMKLINK, you can write a batch file for software
installation which has been done by specialized installation
programs. Basically, XXMKLINK is a tool that gathers various
information from a command line and packages it into a shortcut.
xxmklink spath opath
where
spath path of the shortcut (.lnk added as needed)
opath path of the object represented by the shortcut
You can check shortcutjs.bat:
::creates a shortcut that will start the target with minimized window and admin permissions
shortcutjs.bat -linkfile myscriptMin.lnk -target "%cd%\myscript.bat" -windowstyle 7 -adminpermissions yes
::creates a shortcut with a hot keys
shortcutjs.bat -linkfile myscriptHK.lnk -target "%cd%\myscript.bat" -hotkey "ALT+CTRL+P"
With this you can also edit existing shortcut or only display its properties.
This worked for me on Windows XP ms-dos, I still haven't tried it on Windows 7. It's just like creating a symbolic link in Linux.
shortcut -T source.exe destination.lnk
In the end I decided to write the correct script, because no solution works for me
You will need two fileLocal Settings\
first
createSCUT.bat
#echo on
set VBS=createSCUT.vbs
set SRC_LNK="shortcut1.lnk"
set ARG1_APPLCT="C:\Program Files\Google\Chrome\Application\chrome.exe"
set ARG2_APPARG="--profile-directory=QuteQProfile 25QuteQ"
set ARG3_WRKDRC="C:\Program Files\Google\Chrome\Application"
set ARG4_ICOLCT="%USERPROFILE%\Local Settings\Application Data\Google\Chrome\User Data\Profile 25\Google Profile.ico"
cscript %VBS% %SRC_LNK% %ARG1_APPLCT% %ARG2_APPARG% %ARG3_WRKDRC% %ARG4_ICOLCT%
and second
createSCUT.vbs
Set objWSHShell = WScript.CreateObject("WScript.Shell")
set objWSHShell = CreateObject("WScript.Shell")
set objFso = CreateObject("Scripting.FileSystemObject")
If WScript.arguments.count = 5 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir IconLocation"
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
set objSC = objWSHShell.CreateShortcut(sShortcut)
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sArguments = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(2))
sWorkingDirectory = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(3))
sIconLocation = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(4))
objSC.TargetPath = sTargetPath
rem http://www.bigresource.com/VB-simple-replace-function-5bAN30qRDU.html#
objSC.Arguments = Replace(sArguments, "QuteQ", Chr(34))
rem http://msdn.microsoft.com/en-us/library/f63200h0(v=vs.90).aspx http://msdn.microsoft.com/en-us/library/267k4fw5(v=vs.90).aspx
objSC.WorkingDirectory = sWorkingDirectory
objSC.Description = "Love Peace Bliss"
rem 1 restore 3 max 7 min
objSC.WindowStyle = "3"
rem objSC.Hotkey = "Ctrl+Alt+e";
objSC.IconLocation = sIconLocation
objSC.Save
WScript.Quit
end If
If WScript.arguments.count = 4 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir "
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
set objSC = objWSHShell.CreateShortcut(sShortcut)
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sArguments = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(2))
sWorkingDirectory = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(3))
objSC.TargetPath = sTargetPath
objSC.Arguments = Replace(sArguments, "QuteQ", Chr(34))
objSC.WorkingDirectory = sWorkingDirectory
objSC.Description = "Love Peace Bliss"
objSC.WindowStyle = "3"
objSC.Save
WScript.Quit
end If
If WScript.arguments.count = 2 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath"
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
set objSC = objWSHShell.CreateShortcut(sShortcut)
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut)
objSC.TargetPath = sTargetPath
objSC.WorkingDirectory = sWorkingDirectory
objSC.Save
WScript.Quit
end If
i have two text files- blacklist.txt and complete.txt.
I want a batch file not bash file code.
I want to delete the common lines between the two files.
names in blacklist file should be deleted from complete.txt file
any help ?
findstr /v /x /g:blacklist.txt complete.txt >outfile.txt
should remove all entries in blacklist from complete to produce outfile
This does Unicode input and output. Name it something.vbs.
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
Set BlackFile = Fso.OpenTextFile(Arg(0), 1, False, -1)
Set CompleteFile = Fso.OpenTextFile(Arg(1), 1, False, -1)
Set OutputFile = Fso.CreateTextFile(Arg(2), True, True)
Set Dict = CreateObject("Scripting.Dictionary")
On Error Resume Next
Do Until BlackFile.AtEndOfStream
Line=BlackFile.readline
Dict.Add Line, ""
Loop
Do Until CompleteFile.AtEndOfStream
Line=CompleteFile.readline
If Dict.Exists(Line)
OutputFile.Writeline Line
End If
Loop
To use at command prompt.
C:\folder\something.vbs black.txt complete.txt newfile.txt
I have a csv file with 1M email addresses and i need to extract them from the CSV to a text file.
I googled this and found very few links, and those that i found, didn't do the trick.
So is it even possible to extract emails from a csv using a dos/cmd batch file?
I now and it is possible to do it with Linux but saddly i'm have to use windows.
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
'Remove ^ from quoting command line. Quote, ampersand and brackets
Pttn = Replace(Arg(2), "^(", "(")
Pttn = Replace(Pttn, "^)", ")")
Pttn = Replace(Pttn, "^&", "&")
Pttn = Replace(Pttn, "^""", """")
Set regEx1 = New RegExp
If Instr(LCase(Arg(1)), "i") > 0 then
regEx1.IgnoreCase = True
Else
regEx1.IgnoreCase = False
End If
regEx1.Global = False
regEx1.Pattern = Pttn
Do Until Inp.AtEndOfStream
Line=Inp.readline
Line = RegEx1.Replace(Line, Arg(3))
outp.writeline Line
Loop
To use
cscript //nologo "c:\path to\scriptname.vbs" < inputfile.txt > outputfile.txt
Replace
filter replace {i|n} expression replace
filter repl {i|n} expression replace
Finds and replaces text using regular expressions.
Also used to extract substrings from a file.
Ampersands and brackets in expression must be escaped with the caret. Do not escape carets. Use hexidecimal code \x22 for quotes.
SearchOptions
i - ignore case
n - none
Expression
Regular Expression Reference
Replace
The text to replace. Use $1, $2, $..., $n to specify sub matches in the replace string
Example
filter replace i "=" "No equal sign" < "%systemroot%\win.ini"
This searches for text within square brackets and replaces the line with cat followed by the text within brackets
Filter replace i "^\[^(.*^)\]" "cat$1" < %windir%\win.ini
This searches for any text and prints from the 11th character to the end of the line.
Filter replace i "^.{10}^(.*^)$" "$1" < %windir%\win.ini
This searches a CSV file and prints the second and fourth field
Filter replace i "^.+,^(.+^),.+,^(.+^)$" "$1,$2" < csv.txt
Try a RegEx like (there are thousands on the internet like http://www.regular-expressions.info/email.html)
[0-9a-zA-Z]+\.?[0-9a-zA-Z]?#[0-9a-zA-Z]+\.com|org|net|gov
#set #code=#Batch /*
#echo off
cscript //nologo //E:JScript "%~F0"
goto :EOF
#set #code=#JScript */
var fileContents = WScript.StdIn.ReadAll(),
search = /(\w+)#(\w+)\.(\w+)/g, match;
while ( match = search.exec(fileContents) ) {
WScript.Stdout.WriteLine(match[0]);
}
Copy previous code in a Batch file; for example: GetEmails.bat, and execute it redirecting the input/output files. This is the output of an example session:
C:\> type theFile.txt
Line, with, an, email, address, joedoe#unknown.org
Please, send, mail, to, george#contoso.com, and, someone#example.com, Thanks!
Line, number, 3, with, no, email, address
C:\> GetEmails.bat < theFile.txt
joedoe#unknown.org
george#contoso.com
someone#example.com
how to create a shortcut for a exe from a batch file.
i tried
call link.bat "c:\program Files\App1\program1.exe" "C:\Documents and Settings\%USERNAME%\Desktop" "C:\Documents and Settings\%USERNAME%\Start Menu\Programs" "Program1 shortcut"
but it did not worked.
link.bat can be found at
http://www.robvanderwoude.com/amb_shortcuts.html
Your link points to a Windows 95/98 version and I guess you have at least Windows 2000 or XP. You should try the NT version here.
Alternatively use a little VBScript that you can call from the command line:
set objWSHShell = CreateObject("WScript.Shell")
set objFso = CreateObject("Scripting.FileSystemObject")
' command line arguments
' TODO: error checking
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut)
set objSC = objWSHShell.CreateShortcut(sShortcut)
objSC.TargetPath = sTargetPath
objSC.WorkingDirectory = sWorkingDirectory
objSC.Save
Save the file as createLink.vbs and call it like this to get what you originally tried:
cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Desktop\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe"
cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Start Menu\Programs\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe"
That said I urge you not to use hardcoded paths like "Start Menu" since they're different in localized versions of windows. Modify the script instead to use special folders.
This is the kind of thing that PowerShell is really good at, and is therefore a reason to eschew batch files and get on PowerShell the bandwagon.
PowerShell can talk to .NET. For example, you can get the location of the Desktop like this:
[Environment]::GetFolderPath("Desktop")
PowerShell can talk to COM objects, including WScript.Shell, which can create shortcuts:
New-Object -ComObject WScript.Shell).CreateShortcut( ... )
So your script might look like:
$linkPath = Join-Path ([Environment]::GetFolderPath("Desktop")) "MyShortcut.lnk"
$targetPath = Join-Path ([Environment]::GetFolderPath("ProgramFiles")) "MyCompany\MyProgram.exe"
$link = (New-Object -ComObject WScript.Shell).CreateShortcut( $linkpath )
$link.TargetPath = $targetPath
$link.Save()
Shortcuts have a lot of settings that WScript.Shell can't manipulate, like the "run as administrator" option. These are only accessible through the Win32 interface IShellLinkDataList, which is a real pain to use, but it can be done.
Using vbscript:
set WshShell = WScript.CreateObject("WScript.Shell" )
strDesktop = WshShell.SpecialFolders("AllUsersDesktop" )
set oShellLink = WshShell.CreateShortcut(strDesktop & "\shortcut name.lnk" )
oShellLink.TargetPath = "c:\application folder\application.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "c:\application folder\application.ico"
oShellLink.Description = "Shortcut Script"
oShellLink.WorkingDirectory = "c:\application folder"
oShellLink.Save
Ref: http://www.tomshardware.com/forum/52871-45-creating-desktop-shortcuts-command-line
Failing that, a quick google search shows there's a number of third party tools that can create .lnk files for application shortcuts. I'm assuming you need to stick to stuff that's available natively on Windows though? VBscript is probably your best bet, otherwise I'd suggest trying copying the .lnk file from your machine or using it as a sample to see the correct format for a shortcut file.
On XP I wrote makeshortcut.vbs
Set oWS = WScript.CreateObject("WScript.Shell")
If wscript.arguments.count < 4 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir "
WScript.Quit
end If
shortcutPath = wscript.arguments(0) & ".LNK"
targetPath = wscript.arguments(1)
arguments = wscript.arguments(2)
workingDir = wscript.arguments(3)
WScript.Echo "Creating shortcut " & shortcutPath & " targetPath=" & targetPath & " arguments=" & arguments & " workingDir=" & workingDir
Set oLink = oWS.CreateShortcut(shortcutPath)
oLink.TargetPath = targetPath
oLink.Arguments = arguments
' oLink.Description = "MyProgram"
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
' oLink.WindowStyle = "1"
oLink.WorkingDirectory = workingDir
oLink.Save
It takes exactly 4 args, so it could be improved by making the later 2 optional.I only post because it echo's usage, which might be useful to some. I like WS's soln using special folders and ExpandEnvironmentStrings
Additional note: the link.bat you're using is for Windows 95/98 only:
This batch file is for Windows 95/98 only. I will post the NT equivalent in
the NT newsgroup soon.
NT version is posted at http://www.robvanderwoude.com/amb_shortcutsnt.html instead. You might try that for a .bat approach if preferred over vbscript.
Alternative method, using a third party utility:
Creating a Shortcut from the command line (batch file)
XXMKLINK:
With XXMKLINK, you can write a batch file for software
installation which has been done by specialized installation
programs. Basically, XXMKLINK is a tool that gathers various
information from a command line and packages it into a shortcut.
xxmklink spath opath
where
spath path of the shortcut (.lnk added as needed)
opath path of the object represented by the shortcut
You can check shortcutjs.bat:
::creates a shortcut that will start the target with minimized window and admin permissions
shortcutjs.bat -linkfile myscriptMin.lnk -target "%cd%\myscript.bat" -windowstyle 7 -adminpermissions yes
::creates a shortcut with a hot keys
shortcutjs.bat -linkfile myscriptHK.lnk -target "%cd%\myscript.bat" -hotkey "ALT+CTRL+P"
With this you can also edit existing shortcut or only display its properties.
This worked for me on Windows XP ms-dos, I still haven't tried it on Windows 7. It's just like creating a symbolic link in Linux.
shortcut -T source.exe destination.lnk
In the end I decided to write the correct script, because no solution works for me
You will need two fileLocal Settings\
first
createSCUT.bat
#echo on
set VBS=createSCUT.vbs
set SRC_LNK="shortcut1.lnk"
set ARG1_APPLCT="C:\Program Files\Google\Chrome\Application\chrome.exe"
set ARG2_APPARG="--profile-directory=QuteQProfile 25QuteQ"
set ARG3_WRKDRC="C:\Program Files\Google\Chrome\Application"
set ARG4_ICOLCT="%USERPROFILE%\Local Settings\Application Data\Google\Chrome\User Data\Profile 25\Google Profile.ico"
cscript %VBS% %SRC_LNK% %ARG1_APPLCT% %ARG2_APPARG% %ARG3_WRKDRC% %ARG4_ICOLCT%
and second
createSCUT.vbs
Set objWSHShell = WScript.CreateObject("WScript.Shell")
set objWSHShell = CreateObject("WScript.Shell")
set objFso = CreateObject("Scripting.FileSystemObject")
If WScript.arguments.count = 5 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir IconLocation"
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
set objSC = objWSHShell.CreateShortcut(sShortcut)
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sArguments = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(2))
sWorkingDirectory = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(3))
sIconLocation = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(4))
objSC.TargetPath = sTargetPath
rem http://www.bigresource.com/VB-simple-replace-function-5bAN30qRDU.html#
objSC.Arguments = Replace(sArguments, "QuteQ", Chr(34))
rem http://msdn.microsoft.com/en-us/library/f63200h0(v=vs.90).aspx http://msdn.microsoft.com/en-us/library/267k4fw5(v=vs.90).aspx
objSC.WorkingDirectory = sWorkingDirectory
objSC.Description = "Love Peace Bliss"
rem 1 restore 3 max 7 min
objSC.WindowStyle = "3"
rem objSC.Hotkey = "Ctrl+Alt+e";
objSC.IconLocation = sIconLocation
objSC.Save
WScript.Quit
end If
If WScript.arguments.count = 4 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir "
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
set objSC = objWSHShell.CreateShortcut(sShortcut)
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sArguments = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(2))
sWorkingDirectory = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(3))
objSC.TargetPath = sTargetPath
objSC.Arguments = Replace(sArguments, "QuteQ", Chr(34))
objSC.WorkingDirectory = sWorkingDirectory
objSC.Description = "Love Peace Bliss"
objSC.WindowStyle = "3"
objSC.Save
WScript.Quit
end If
If WScript.arguments.count = 2 then
WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath"
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
set objSC = objWSHShell.CreateShortcut(sShortcut)
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut)
objSC.TargetPath = sTargetPath
objSC.WorkingDirectory = sWorkingDirectory
objSC.Save
WScript.Quit
end If