Required to "Run As Administrator" to open session

Advertisement

Zachbray
Joined:
Posts:
2

Required to "Run As Administrator" to open session

I am attempting to develop a Windows 10 Pro version 21H2 PowerShell script using the WinSCPnet.dll. I have WinSCP version 5.21 installed. I have used the code generator option to gather the SessionOptions and used the basic examples to develop a simple PowerShell script, see below. Attached is my debug log.

When I run the script from a PowerShell ISE as a user it crashes my PowerShell session. When I run the script from a Run As Administrator PowerShell ISE it runs as expected and does not crash my PowerShell session.

I am wanting to be able to run WinSCP in a script as a standard user. How can I make that happen?
Clear-Content "C:\SVEC\Surveys\debug.log"
$assemblyPath = if ($env:WINSCP_PATH) { $env:WINSCP_PATH } else { $PSScriptRoot }
Add-Type -Path (Join-Path $assemblyPath "WinSCPnet.dll")
 
$SessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "Data.inside-info.com"
    UserName = "xxxx"
    Password = "xxxx"
    SshHostKeyFingerprint = "ssh-ed25519 255 xxxxx"
    }
 
$session = New-Object WinSCP.Session
$session.DebugLogPath = "C:\SVEC\Surveys\debug.log"
$session.ExecutablePath = "C:\SVEC\Surveys\WinSCP.exe"
 
try{
    # Connect
    $session.Open($sessionOptions)
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
}
finally
{
    # Disconnect & Clean up
    $session.Dispose()
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,506
Location:
Prague, Czechia

Re: Required to "Run As Administrator" to open session

How exactly does the "crash" look like?
Do I understand right, that it crashes in your interactive Windows user session (no Task Scheduler or anything similar)?
Please post also a session log file (Session.SessionLogPath).

Reply with quote

Zachbray
Joined:
Posts:
2

Re: Required to "Run As Administrator" to open session

The "crash" is my PowerShell window simply closes and when I reopen it I am told that my last PowerShell session did not close normally, see attachment. Also attached is my session log.

I was able to find another way to make this work. I use Import-Module winscp instead of Add-Type -Path (Join-Path $assemblyPath "WinSCPnet.dll"). In doing so I discover that the version of WinSCP that the Import-Module references is 5.17.10.0 and this causes conflicts with the version I am currently on of 5.21. Once I copy the version 5.21 WinSCP.exe to C:\Program Files\WindowsPowerShell\Modules\WinSCP\5.17.10.0\bin and WinSCPnet.dll to C:\Program Files\WindowsPowerShell\Modules\WinSCP\5.17.10.0\lib\net40 then I am able to run my commands as a standard user.

You may wish to update Installer to correct this.

Powershell-WinSCP.PNG

Reply with quote

Advertisement

You can post new topics in this forum