Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 使用参数将Powershell转换为exe_Windows_Powershell_Networking_Exe - Fatal编程技术网

Windows 使用参数将Powershell转换为exe

Windows 使用参数将Powershell转换为exe,windows,powershell,networking,exe,Windows,Powershell,Networking,Exe,我有一个powershell脚本,如下所示: param( [string]$fullpath, [string]$username, [string]$password, [string]$driveletter = "P:", [bool]$storedrive = $False) $net = new-object -ComObject WScript.Network $net.MapNetworkDrive($driveletter, $fullpath, $storedrive,

我有一个powershell脚本,如下所示:

param(
[string]$fullpath,
[string]$username,
[string]$password,
[string]$driveletter = "P:",
[bool]$storedrive = $False)

$net = new-object -ComObject WScript.Network

$net.MapNetworkDrive($driveletter, $fullpath, $storedrive, $username, $password)
我试着把它转换成一个可执行文件,它可以很好地工作

如果我尝试使用
name.exe-fullpath“\\192.168.1.120\share”-用户名“administrator”-密码“test123”
运行.exe,我会收到错误消息
Networkname not found

如果我将以下代码编译成可执行文件

param(
[string]$fullpath = "\\192.168.1.120\share",
[string]$username = "administrator",
[string]$password ="test123",
[string]$driveletter = "P:",
[bool]$storedrive = $False)

$net = new-object -ComObject WScript.Network

$net.MapNetworkDrive($driveletter, $fullpath, $storedrive, $username, $password)
…并运行.exe-它可以工作,我得到浏览器中显示的网络驱动器

你知道为什么这样不行吗

问候
Markus

我找到了一个解决方案,现在我正在使用这个脚本进行调整

param(
[string]$driveletter,
[string]$fullpath,
[string]$username,
[string]$password)

$net = new-object -ComObject WScript.Network

$net.MapNetworkDrive($driveletter, $fullpath, $false, $username, $password)
我将其转换为.exe 这个很好用。 .exe使用以下“参数”


布尔值的转换存在一些问题。但是,它现在按我希望的方式工作。

看起来参数有问题。尝试将
write host
添加到非工作版本,以显示传递给
MapNetworkDrive
的参数集。输出看起来合理吗?当我尝试添加“写入主机”$net.MapNetworkDrive($driveletter、$fullpath、$storedrive、$username、$password)”,并将其编译为exe时,它不会显示任何内容。。。当我在powershell中运行它时,它工作正常,并且我得到了打印的输出,而不是
Write Host“$net.MapNetworkDrive(…)”
,请尝试更简单的
Write Host“fullpath=$fullpath;username=$username;password=$password;driveletter=$driveletter;storedrive=$storedrive”
-您希望确保在EXE中正确分配您要传递的参数。
run.exe "P:" "\\192.168.1.120\share" "administrator" "test123"