mardi 22 janvier 2019

vbscript IF statement- if file does not exist

In my VB script I am trying to run a another VBscript to create a desktop link IF that desktop link doesn't exist. If the desktop link does exist, do not do anything. However currently even if the desktop link exist , the vbscript still runs. Why? No syntax error.

    '* ----------------------------------------------------------------------------
Dim objFSO, strDirectory, strFile

Set oShell = CreateObject ("Wscript.Shell") 

'* getting script location
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile) 

' define directory & file
strDirectory = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
strFile = strDirectory & "\Desktop\My Program.lnk"
' Create the File System Object


If objFSO.FileExists(strFile) Then

     '* DO NOTHING

Else

strDesk= "desktoplink.vbs"
oShell.Run strDesk, 0, false

End If

'* enclosing path to support spaces
HMIpath = strFolder & "\CHK.bat"
HMIpath = """"& HMIpath & """"




Dim strArgs
strArgs = "cmd /c " & HMIpath
oShell.Run strArgs, 0, false
'* End of file

Aucun commentaire:

Enregistrer un commentaire