Create WinSCP.SessionOptions takes 20 seconds in COM and account not logged on
Hi,
I use WinSCPnet.dll with a program written with AutoIT script language. It acts as a COM.
It works fine but when I start the program from a scheduled task (under Windows Server 2012 R2) using an user account that is not logged on, it takes 20 seconds for the WinSCP.SessionOptions create object. If I run the scheduled task with a user already logged on, it create the object immediately.
So, I tried with two simple scripts, one with Powershell and one with VBScript.
With Powershell there is no wait time and with VBScript it takes 20 seconds too.
This is the Powershell code:
This is the result... started with "powershell -file E:\Aldo\testps.ps1 >>E:\Aldo\testps.log" command.
First session with an account logged on (speedy), second session with an account not logged on (speedy).
This is the VBScript code:
This is the result... started with "cscript E:\Aldo\testvbs.vbs >>E:\Aldo\testvbs.log" command.
First session with an account logged on (speedy), second session with an account not logged on (20 seconds).
Do you have ideas on how to avoid these 20 seconds wait in COM using?
I tried with WinSCP 5.9.4, 5.11.3 and the last 5.13. Always the same result.
Grazie. Ciao,
Aldo
I use WinSCPnet.dll with a program written with AutoIT script language. It acts as a COM.
It works fine but when I start the program from a scheduled task (under Windows Server 2012 R2) using an user account that is not logged on, it takes 20 seconds for the WinSCP.SessionOptions create object. If I run the scheduled task with a user already logged on, it create the object immediately.
So, I tried with two simple scripts, one with Powershell and one with VBScript.
With Powershell there is no wait time and with VBScript it takes 20 seconds too.
This is the Powershell code:
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Create object WinSCP.SessionOptions`r"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "***.**.***.**"
UserName = "AldoProva"
Password = "***"
SshHostKeyFingerprint = "ssh-rsa 2048 ***"
}
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Object created`r"
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Create object WinSCP.Session`r"
$session = New-Object WinSCP.Session
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Object created`r"
try
{
# Connect
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Open Session`r"
$session.Open($sessionOptions)
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Session opened`r"
# Upload files
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Create object WinSCP.TransferOptions`r"
$transferOptions = New-Object WinSCP.TransferOptions
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Object created`r"
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult =
$session.PutFiles("E:\test.txt", "/", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host $(Get-Date -format "dd/MM/yyyy HH:mm:ss") " Upload of $($transfer.FileName) succeeded`r"
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
Write-Host "`r"
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}First session with an account logged on (speedy), second session with an account not logged on (speedy).
21/02/2018 17:01:05 Create object WinSCP.SessionOptions 21/02/2018 17:01:05 Object created 21/02/2018 17:01:05 Create object WinSCP.Session 21/02/2018 17:01:05 Object created 21/02/2018 17:01:05 Open Session 21/02/2018 17:01:07 Session opened 21/02/2018 17:01:07 Create object WinSCP.TransferOptions 21/02/2018 17:01:07 Object created 21/02/2018 17:01:07 Upload of E:\test.txt succeeded 21/02/2018 17:01:32 Create object WinSCP.SessionOptions 21/02/2018 17:01:32 Object created 21/02/2018 17:01:32 Create object WinSCP.Session 21/02/2018 17:01:33 Object created 21/02/2018 17:01:33 Open Session 21/02/2018 17:01:35 Session opened 21/02/2018 17:01:35 Create object WinSCP.TransferOptions 21/02/2018 17:01:35 Object created 21/02/2018 17:01:35 Upload of E:\test.txt succeeded
This is the VBScript code:
Option Explicit
' Setup session options
Dim sessionOptions
WScript.Echo Date & " " & Time & " Create object WinSCP.SessionOptions"
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
WScript.Echo Date & " " & Time & " Object created"
With sessionOptions
.Protocol = 0
.HostName = "***.**.***.**"
.UserName = "AldoProva"
.Password = "***"
.SshHostKeyFingerprint = "ssh-rsa 2048 ***"
End With
Dim session
WScript.Echo Date & " " & Time & " Create object WinSCP.Session"
Set session = WScript.CreateObject("WinSCP.Session")
WScript.Echo Date & " " & Time & " Object created"
' Connect
WScript.Echo Date & " " & Time & " Open session"
session.Open sessionOptions
WScript.Echo Date & " " & Time & " Session opened"
' Upload files
Dim transferOptions
WScript.Echo Date & " " & Time & " Create object WinSCP.TransferOptions"
Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
WScript.Echo Date & " " & Time & " Object created"
transferOptions.TransferMode = 0
Dim transferResult
Set transferResult = session.PutFiles("E:\test.txt", "/", False, transferOptions)
' Throw on any error
transferResult.Check
' Print results
Dim transfer
For Each transfer In transferResult.Transfers
WScript.Echo Date & " " & Time & " Upload of " & transfer.FileName & " succeeded"
Next
' Disconnect, clean up
session.Dispose
WScript.Echo ""First session with an account logged on (speedy), second session with an account not logged on (20 seconds).
Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. 21/02/2018 17:01:07 Create object WinSCP.SessionOptions 21/02/2018 17:01:08 Object created 21/02/2018 17:01:09 Create object WinSCP.Session 21/02/2018 17:01:09 Object created 21/02/2018 17:01:09 Open session 21/02/2018 17:01:11 Session opened 21/02/2018 17:01:11 Create object WinSCP.TransferOptions 21/02/2018 17:01:11 Object created 21/02/2018 17:01:11 Upload of E:\test.txt succeeded Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. 21/02/2018 17:01:35 Create object WinSCP.SessionOptions 21/02/2018 17:01:55 Object created 21/02/2018 17:01:55 Create object WinSCP.Session 21/02/2018 17:01:55 Object created 21/02/2018 17:01:55 Open session 21/02/2018 17:01:57 Session opened 21/02/2018 17:01:57 Create object WinSCP.TransferOptions 21/02/2018 17:01:57 Object created 21/02/2018 17:01:57 Upload of E:\test.txt succeeded
Do you have ideas on how to avoid these 20 seconds wait in COM using?
I tried with WinSCP 5.9.4, 5.11.3 and the last 5.13. Always the same result.
Grazie. Ciao,
Aldo