开发者

Running a command in power shell profile script has different behaviour than command line

开发者 https://www.devze.com 2023-01-26 20:18 出处:网络
then I run cmd /c net use h: /d from the powershell command line it all succeeds but when I run t开发者_JAVA技巧he same command in the powershell $profile script it asks for a manual confirmation.

then I run cmd /c net use h: /d from the powershell command line it all succeeds

but when I run t开发者_JAVA技巧he same command in the powershell $profile script it asks for a manual confirmation.

Running a command in power shell profile script has different behaviour than command line

Anyone know how to prevent the confirmation please?


I cannot find a way to force the net program to force the drive deletion, however I can use the following powershell script to control the Windows Script Host to

map a drive:

(New-Object -ComObject WScript.Network).MapNetworkDrive("H:", '\\SVNAS301\blah')

remove a mapping

(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:")

Or remove a mapping with force

(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:", 1)


(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:", 1, 1)

The second 1 at the end I believe is for bUpdateProfile. The drive would not disappear from the Explorer window unless that value was there.

0

精彩评论

暂无评论...
验证码 换一张
取 消