Question : in vbscript - How can I check if a file exists in a remote server that requires a username and password to log in?

in vbscript - How can I check if a file exists in a remote server that requires a username and password to log in?

Answer : in vbscript - How can I check if a file exists in a remote server that requires a username and password to log in?

try this.

There are two scripts. Save both of them on the same folder, with the specified names

The script will use the windows runas command to execute the second script with different credentials. Remove the /savecred if you don't want the password to be saved by runas.

On the first script, instantiate the srtUser and srtDomain vaiables with the info of the user that has access to the server/folder.

On the second script instantiate the strFilePath with the path for the file you want to check that exists.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
'VBS RUNAS SCRIPT SAVE IT AS RUNAS_REMOTE_FILE_CHECK.VBS

strUser = "USER_NAME"
strDomain = "DOMAIN_NAME"
strCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
strRunAs ="runas /savecred /user:" & strDomain & "\" & strUser&" " & Chr(34)& "cscript.exe \"& Chr(34)& strCurPath & "\REMOTE_FILE_CHECK.VBS" & Chr(34)

Set WshShell = CreateObject("WScript.Shell")
strRunPath = strRunAs
WshShell.Run (strRunPath)

'========================================================================================================

'VBS SCRIPT - SAVE IT AS REMOTE_FILE_CHECK.VBS

strFilePath = "PATH FOR THE FILE"

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFilePath) Then
    Wscript.Echo "File does exist."
Else
    Wscript.Echo "File does NOT exist."
End If
Random Solutions  
 
programming4us programming4us