I have a powershell script which looks like this:
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)
I tried to convert it to an executable with PS2EXE which worked fine.
If I try to run the .exe with name.exe -fullpath "\\\\192.168.1.120\\share" -username "administrator" -password "test123"
I get the error message Networkname not found
If I compile the following code to an executable
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)
...and run the .exe - it works and I get the network drive shown in the Explorer....
Any ideas why this doesn't work?
Regards Markus
I found a solution, now I'm justing using this script
param(
[string]$driveletter,
[string]$fullpath,
[string]$username,
[string]$password)
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive($driveletter, $fullpath, $false, $username, $password)
which I convert into the .exe This works fine. The .exe uses the following "parameters"
run.exe "P:" "\\192.168.1.120\share" "administrator" "test123"
There is some problem with converting of the boolean. However, it works now the way I want to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.