Bis*_*iyo 7 c# c++ powershell windows-10 windows-subsystem-for-linux
我正在制作一个PowerShell脚本来从压缩的tarball(.tar.gz)安装任何Linux用户空间.但它总会返回这样的数字2147943746.我正在使用WslRegisterDistribution函数wslapi.dll.C++中的语法如下:
HRESULT WINAPI WslRegisterDistribution(
_In_ PCWSTR distroName,
_In_ PCWSTR tarGzFilename
);
Run Code Online (Sandbox Code Playgroud)
我的PowerShell脚本如下:
$X=Read-Host "Enter Distro Name"
$Y=Read-Host "Enter .tar.gz file path"
Write-Host "Distro name '$X' and file path '$Y'"
pause
$MethodDefinition=@'
[DllImport("wslapi.dll", CharSet = CharSet.Unicode)]
public static extern uint WslRegisterDistribution(string distributionName, string tarGzFilename);
'@
$WslApi=Add-Type -MemberDefinition $MethodDefinition -Name 'Wslapi' -PassThru
$WslApi::WslRegisterDistribution("$X", "$Y");
Run Code Online (Sandbox Code Playgroud)
我可以使用C++/C#调用该方法,但我无法在PowerShell中执行此操作.在C#中我导入函数并在其参数中传递两个命令参数,如下所示:
[DllImport("wslapi.dll", CharSet = CharSet.Unicode)]
public static extern uint WslRegisterDistribution(string distributionName, string tarGzFilename);
Run Code Online (Sandbox Code Playgroud)
可以在PowerShell中导入吗?我该如何更正脚本来做到这一点?请参阅我的替代GitHub项目https://github.com/Biswa96/WSLInstall.
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |