/build/static/layout/Breadcrumb_cap_w.png

VB - Modify Shorcut target

Hi,
I have used the following script to modify a Shorcut's target path:


set wshell = Createobject("wscript.shell")
set Fso= createobject("scripting.filesystemobject")

shortcutpath = "C:\Documents and Settings\All Users\Start Menu\Programs\Mozilla Firefox\Copy of Mozilla Firefox.lnk"
ExePath = "C:\Program Files\Mozilla Firefox\firefox.exe"
SeverPath = "\\Servername\test\test.txt"
ShortcutTargetPath = ExePath&" "&SeverPath

If Fso.FileExists(ShortcutPath) then
msgbox ShortcutTargetPath
Set shortcut = wshell.CreateShortcut(shortcutpath)
shortcut.TargetPath =ShortcutTargetPath
msgbox shortcut.TargetPath
'shortcut.Save

Else
msgbox "Shorcut not found !",16
End If


'OutPut :

'C:\Program Files\Mozilla Firefox\firefox.exe \\Servername\test\test.txt
'C:\Program Files\Mozilla Firefox\firefox.exe \Servername\test\test.txt


I am wondering why this single "\" gets missed out while appending the argument to the shortcut Target.....
do i have to include anything more to handle it ????????


Regards,
Rajesh.

0 Comments   [ + ] Show comments

Answers (4)

Posted by: rayz_0020 15 years ago
Senior Purple Belt
0
got it myself... the following script works...


set wshell = Createobject("wscript.shell")
set Fso= createobject("scripting.filesystemobject")

shortcutpath = "C:\Documents and Settings\All Users\Start Menu\Programs\Mozilla Firefox\Copy of Mozilla Firefox.lnk"
ExePath = "C:\Program Files\Mozilla Firefox\firefox.exe"
ShortCutArg ="\\Servername\test\test.txt"

If Fso.FileExists(ShortcutPath) then
Set shortcut = wshell.CreateShortcut(shortcutpath)
shortcut.TargetPath = ExePath
shortcut.Arguments = ShortCutArg
shortcut.Save

Else
msgbox "Shortcut not found !",16
End If


But still i got no clue for the behavior of the earlier script...
Posted by: AngelD 15 years ago
Red Belt
0
The targetpath needs to be set to ex. an existing file which it seems the save method of the shortcut object is trying to "fix" and therefore interpret the target argument part (\\Servername\test\test.txt) as the last part of the filepath, so in this scenario "firefox.exe " becomes a subfolder and Servername the next subfolder and so on.
Posted by: prathima 14 years ago
Yellow Belt
0
Hi to all
im new to the packaging..
I dont knw how to start new thread also..
Im having one batch file can any one tell what it is doing exactly and
can we convert this one in to the vb script to keep in the CA of my package.
.the batch file looks as
**************************

ECHO ComputerName : %COMPUTERNAME% > "%LOGPATH%"
DATE /T >> "%LOGPATH%"
TIME /T >> "%LOGPATH%"
REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /V "Authentication Packages" | FIND /I "Authentication Packages">nul
SET RETCODE=%ERRORLEVEL%
IF "%RETCODE%"=="0" (
IF EXIST "%TEMP%\~.tmp.txt" DEL /F /Q "%TEMP%\~.tmp.txt" > nul
ECHO Registry key found : "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" "Authentication Packages" >> "%LOGPATH%"
FOR /F "TOKENS=3 DELIMS=Z, " %%A IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /V "Authentication Packages"') DO (
ECHO Current Value : %%A >> "%LOGPATH%"
ECHO %%A>"%TEMP%\~.tmp.txt"
)
SLEEP 2
CSCRIPT //NOLOGO "%~DP0postfix.vbs" "%TEMP%\~.tmp.txt"
SLEEP 2
FOR /F "tokens=* delims=" %%A IN ('type "%TEMP%\~.tmp.txt"') DO (
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /V "Authentication Packages" /T REG_MULTI_SZ /d "%%A" /f>nul
SET RETCODE=%ERRORLEVEL%
)
FOR /F "TOKENS=3 DELIMS=Z, " %%A IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /V "Authentication Packages"') DO (
ECHO New Value : %%A >> "%LOGPATH%"
)
IF EXIST "%TEMP%\~.tmp.txt" DEL /F /Q "%TEMP%\~.tmp.txt" > nul
) ELSE (
ECHO Registry key NOT found : "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" "Authentication Packages" >> "%LOGPATH%"
SET RETCODE=1
)
ECHO Return-Code : %RETCODE% >> "%LOGPATH%"
DATE /T >> "%LOGPATH%"
TIME /T >> "%LOGPATH%"
EXIT %RETCODE%
******************
and the vb file content is........
Option Explicit
Dim objFSO
Dim strFileName, strData, strFStream
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileName = WScript.Arguments(0)
Set strFStream = objFSO.OpenTextFile(strFileName)
strData = strFStream.ReadAll
WScript.Sleep 1000
Set strFStream = Nothing
strData = Replace( strData, "\0\0\0", "\0", 1, -1, 1 )
WScript.Sleep 1000
Set strFStream = objFSO.OpenTextFile(strFileName, 2, True)
strFStream.Write strData
WScript.Sleep 1000
Set strFStream = Nothing

Thanks in advance,
.......
Posted by: guy.forum 14 years ago
Orange Belt
0
[font="microsoft sans serif"]Hello Prathima,
[font="microsoft sans serif"]
[font="microsoft sans serif"]Though even i am new to this forum. I would like to comment on the same you have asked for:
[font="microsoft sans serif"]
[font="microsoft sans serif"]1.) Regarding the VbScript.This Script is just replacing a content of the file having "\0\0\0" to "\0".
[font="microsoft sans serif"]Also, As you can see in the vbscript "StrFileName" is coming from the Arguments and this has been defined in your batch file in the line
[font="microsoft sans serif"]CSCRIPT //NOLOGO "%~DP0postfix.vbs" "%TEMP%\~.tmp.txt"

[font="microsoft sans serif"]So here "%TEMP%\~.tmp.txt" is the argument for your script to execute and to replace the characters as described above.
[font="microsoft sans serif"]
[font="microsoft sans serif"]Hope this part is clear!!
[font="microsoft sans serif"]
[font="microsoft sans serif"]Also in the batch file: there is some conditional based loops present by checking the registry key.I would suggest if you can give "pause" statement in every line and check for the flow of the script.
[font="microsoft sans serif"]
[font="microsoft sans serif"]Do add in the beginning
[font="microsoft sans serif"]SET LOGPATH =c:\abc.log (Any name you want)
[font="microsoft sans serif"]
[font="microsoft sans serif"]Also keep the vbs file in the same folder from where you execute the batch script.
[font="microsoft sans serif"]
[font="microsoft sans serif"]Please let me know if you want any help in the same.
[font="microsoft sans serif"]
[font="microsoft sans serif"]And of course yes, this all can be converted to VbScript and be called into CA.
[font="microsoft sans serif"]
[font="microsoft sans serif"]Thanks!![:)]
[font="microsoft sans serif"]
[font="microsoft sans serif"]
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ